Search in sources :

Example 1 with XmlList

use of javax.xml.bind.annotation.XmlList in project cxf by apache.

the class CodeGenTest method testGenerateXmlListAnno.

@Test
public void testGenerateXmlListAnno() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/cxf-1354/string_array_test.wsdl"));
    processor.setContext(env);
    processor.execute();
    Class<?> sei = classLoader.loadClass("org.apache.stringarray.StringListTest");
    Method method = sei.getMethods()[0];
    assertNotNull("@XmlList is not generated for method", method.getAnnotation(XmlList.class));
    boolean xmlListGenerated = false;
    for (Annotation ann : method.getParameterAnnotations()[0]) {
        if (ann instanceof XmlList) {
            xmlListGenerated = true;
        }
    }
    assertTrue("@XmlList is not generated for paramter", xmlListGenerated);
}
Also used : Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) Annotation(java.lang.annotation.Annotation) XmlList(javax.xml.bind.annotation.XmlList) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 2 with XmlList

use of javax.xml.bind.annotation.XmlList in project cxf by apache.

the class WrapperBeanFieldAnnotator method annotate.

public void annotate(final JavaAnnotatable field) {
    JavaField jField = null;
    if (field instanceof JavaField) {
        jField = (JavaField) field;
    } else {
        throw new RuntimeException("WrapperBeanFiledAnnotator expect JavaField as input");
    }
    String rawName = jField.getRawName();
    boolean hasEl = false;
    for (Annotation ann : jField.getJaxbAnnotaions()) {
        if (ann instanceof XmlMimeType) {
            JAnnotation mimeAnno = new JAnnotation(XmlMimeType.class);
            mimeAnno.addElement(new JAnnotationElement("value", ((XmlMimeType) ann).value()));
            jField.addAnnotation(mimeAnno);
        } else if (ann instanceof XmlJavaTypeAdapter) {
            JAnnotation jaxbAnn = new JAnnotation(XmlJavaTypeAdapter.class);
            jaxbAnn.addElement(new JAnnotationElement("value", ((XmlJavaTypeAdapter) ann).value()));
            jaxbAnn.addElement(new JAnnotationElement("type", ((XmlJavaTypeAdapter) ann).type()));
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlAttachmentRef) {
            JAnnotation jaxbAnn = new JAnnotation(XmlAttachmentRef.class);
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlList) {
            JAnnotation jaxbAnn = new JAnnotation(XmlList.class);
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlElement) {
            hasEl = true;
            XmlElement el = (XmlElement) ann;
            JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
            xmlElementAnnotation.addElement(new JAnnotationElement("name", el.name()));
            if (!StringUtils.isEmpty(el.namespace())) {
                xmlElementAnnotation.addElement(new JAnnotationElement("namespace", el.namespace()));
            }
            if (el.nillable()) {
                xmlElementAnnotation.addElement(new JAnnotationElement("nillable", el.nillable(), true));
            }
            if (el.required()) {
                xmlElementAnnotation.addElement(new JAnnotationElement("required", el.required(), true));
            }
            if (!StringUtils.isEmpty(el.defaultValue())) {
                xmlElementAnnotation.addElement(new JAnnotationElement("defaultValue", el.defaultValue()));
            }
            jField.addAnnotation(xmlElementAnnotation);
        }
    }
    if (!hasEl) {
        JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
        xmlElementAnnotation.addElement(new JAnnotationElement("name", rawName));
        if (!StringUtils.isEmpty(jField.getTargetNamespace())) {
            xmlElementAnnotation.addElement(new JAnnotationElement("namespace", jField.getTargetNamespace()));
        }
        jField.addAnnotation(xmlElementAnnotation);
    }
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) XmlMimeType(javax.xml.bind.annotation.XmlMimeType) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) XmlAttachmentRef(javax.xml.bind.annotation.XmlAttachmentRef) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) XmlElement(javax.xml.bind.annotation.XmlElement) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) Annotation(java.lang.annotation.Annotation) XmlList(javax.xml.bind.annotation.XmlList)

Example 3 with XmlList

use of javax.xml.bind.annotation.XmlList in project cxf by apache.

the class XmlListAnotator method annotate.

public void annotate(JavaAnnotatable jn) {
    JAnnotation jaxbAnnotation = new JAnnotation(XmlList.class);
    if (jn instanceof JavaParameter) {
        JavaParameter jp = (JavaParameter) jn;
        jp.addAnnotation("XmlList", jaxbAnnotation);
    } else if (jn instanceof JavaMethod) {
        JavaMethod jm = (JavaMethod) jn;
        jm.addAnnotation("XmlList", jaxbAnnotation);
    } else {
        throw new RuntimeException("XmlList can only annotate to JavaParameter or JavaMethod");
    }
    jf.addImport(XmlList.class.getName());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) XmlList(javax.xml.bind.annotation.XmlList)

Example 4 with XmlList

use of javax.xml.bind.annotation.XmlList in project cxf by apache.

the class WrapperClassGenerator method addJAXBAnnotations.

private boolean addJAXBAnnotations(FieldVisitor fv, List<Annotation> jaxbAnnos, String name) {
    AnnotationVisitor av0;
    boolean addedEl = false;
    for (Annotation ann : jaxbAnnos) {
        if (ann instanceof XmlMimeType) {
            av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlMimeType;", true);
            av0.visit("value", ((XmlMimeType) ann).value());
            av0.visitEnd();
        } else if (ann instanceof XmlJavaTypeAdapter) {
            av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapter;", true);
            generateXmlJavaTypeAdapter(av0, (XmlJavaTypeAdapter) ann);
            av0.visitEnd();
        } else if (ann instanceof XmlAttachmentRef) {
            av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlAttachmentRef;", true);
            av0.visitEnd();
        } else if (ann instanceof XmlList) {
            av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlList;", true);
            av0.visitEnd();
        } else if (ann instanceof XmlElement) {
            addedEl = true;
            XmlElement el = (XmlElement) ann;
            av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true);
            if ("##default".equals(el.name())) {
                av0.visit("name", name);
            } else {
                av0.visit("name", el.name());
            }
            av0.visit("nillable", el.nillable());
            av0.visit("required", el.required());
            av0.visit("namespace", el.namespace());
            av0.visit("defaultValue", el.defaultValue());
            if (el.type() != XmlElement.DEFAULT.class) {
                av0.visit("type", el.type());
            }
            av0.visitEnd();
        } else if (ann instanceof XmlElementWrapper) {
            XmlElementWrapper el = (XmlElementWrapper) ann;
            av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElementWrapper;", true);
            av0.visit("name", el.name());
            av0.visit("nillable", el.nillable());
            av0.visit("required", el.required());
            av0.visit("namespace", el.namespace());
            av0.visitEnd();
        }
    }
    return addedEl;
}
Also used : XmlMimeType(javax.xml.bind.annotation.XmlMimeType) XmlAttachmentRef(javax.xml.bind.annotation.XmlAttachmentRef) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) XmlElement(javax.xml.bind.annotation.XmlElement) Annotation(java.lang.annotation.Annotation) XmlElementWrapper(javax.xml.bind.annotation.XmlElementWrapper) XmlList(javax.xml.bind.annotation.XmlList)

Example 5 with XmlList

use of javax.xml.bind.annotation.XmlList in project cxf by apache.

the class ReflectionServiceFactoryBean method getJaxbAnnoMap.

private Map<Class<?>, Boolean> getJaxbAnnoMap(MessagePartInfo mpi) {
    Map<Class<?>, Boolean> map = new ConcurrentHashMap<Class<?>, Boolean>(4, 0.75f, 1);
    Annotation[] anns = getMethodParameterAnnotations(mpi);
    if (anns != null) {
        for (Annotation anno : anns) {
            if (anno instanceof XmlList) {
                map.put(XmlList.class, true);
            }
            if (anno instanceof XmlAttachmentRef) {
                map.put(XmlAttachmentRef.class, true);
            }
            if (anno instanceof XmlJavaTypeAdapter) {
                map.put(XmlJavaTypeAdapter.class, true);
            }
            if (anno instanceof XmlElementWrapper) {
                map.put(XmlElementWrapper.class, true);
            }
        }
    }
    return map;
}
Also used : XmlAttachmentRef(javax.xml.bind.annotation.XmlAttachmentRef) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Annotation(java.lang.annotation.Annotation) XmlElementWrapper(javax.xml.bind.annotation.XmlElementWrapper) XmlList(javax.xml.bind.annotation.XmlList)

Aggregations

XmlList (javax.xml.bind.annotation.XmlList)6 Annotation (java.lang.annotation.Annotation)5 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)4 XmlAttachmentRef (javax.xml.bind.annotation.XmlAttachmentRef)3 XmlElement (javax.xml.bind.annotation.XmlElement)2 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)2 XmlMimeType (javax.xml.bind.annotation.XmlMimeType)2 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)2 Method (java.lang.reflect.Method)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 WebMethod (javax.jws.WebMethod)1 QName (javax.xml.namespace.QName)1 JAXBBeanInfo (org.apache.cxf.common.jaxb.JAXBBeanInfo)1 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)1 JavaField (org.apache.cxf.tools.common.model.JavaField)1 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)1 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)1 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)1