Search in sources :

Example 1 with XmlAttachmentRef

use of javax.xml.bind.annotation.XmlAttachmentRef 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 2 with XmlAttachmentRef

use of javax.xml.bind.annotation.XmlAttachmentRef 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 3 with XmlAttachmentRef

use of javax.xml.bind.annotation.XmlAttachmentRef 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

Annotation (java.lang.annotation.Annotation)3 XmlAttachmentRef (javax.xml.bind.annotation.XmlAttachmentRef)3 XmlList (javax.xml.bind.annotation.XmlList)3 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)3 XmlElement (javax.xml.bind.annotation.XmlElement)2 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)2 XmlMimeType (javax.xml.bind.annotation.XmlMimeType)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)1 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)1 JavaField (org.apache.cxf.tools.common.model.JavaField)1