Search in sources :

Example 31 with XmlJavaTypeAdapter

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

the class JAXBUtils method getAdapter.

public static XmlJavaTypeAdapter getAdapter(Class<?> objectClass, Annotation[] anns) {
    XmlJavaTypeAdapter typeAdapter = AnnotationUtils.getAnnotation(anns, XmlJavaTypeAdapter.class);
    if (typeAdapter == null) {
        typeAdapter = objectClass.getAnnotation(XmlJavaTypeAdapter.class);
        if (typeAdapter == null) {
            // lets just try the 1st interface for now
            Class<?>[] interfaces = objectClass.getInterfaces();
            typeAdapter = interfaces.length > 0 ? interfaces[0].getAnnotation(XmlJavaTypeAdapter.class) : null;
        }
    }
    return typeAdapter;
}
Also used : XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)

Example 32 with XmlJavaTypeAdapter

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

the class JAXBUtils method getTypeFromAdapter.

public static Class<?> getTypeFromAdapter(XmlJavaTypeAdapter adapter, Class<?> theType, boolean boundType) {
    if (adapter != null) {
        if (adapter.type() != XmlJavaTypeAdapter.DEFAULT.class) {
            theType = adapter.type();
        } else {
            Type topAdapterType = adapter.value().getGenericSuperclass();
            Class<?> superClass = adapter.value().getSuperclass();
            while (superClass != null) {
                Class<?> nextSuperClass = superClass.getSuperclass();
                if (nextSuperClass != null && !Object.class.equals(nextSuperClass)) {
                    topAdapterType = superClass.getGenericSuperclass();
                }
                superClass = nextSuperClass;
            }
            Type[] types = InjectionUtils.getActualTypes(topAdapterType);
            if (types != null && types.length == 2) {
                int index = boundType ? 1 : 0;
                theType = InjectionUtils.getActualType(types[index]);
            }
        }
    }
    return theType;
}
Also used : Type(java.lang.reflect.Type) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)

Example 33 with XmlJavaTypeAdapter

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

the class ReflectionServiceFactoryBean method getJaxbAnnoMap.

private Map<Class<?>, Boolean> getJaxbAnnoMap(MessagePartInfo mpi) {
    Map<Class<?>, Boolean> map = new ConcurrentHashMap<>(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)

Example 34 with XmlJavaTypeAdapter

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

the class XmlJavaTypeAdapterAnnotator method annotate.

public void annotate(JavaAnnotatable jn) {
    JAnnotation jaxbAnnotation = new JAnnotation(XmlJavaTypeAdapter.class);
    jaxbAnnotation.addElement(new JAnnotationElement("value", adapter));
    if (jn instanceof JavaParameter) {
        JavaParameter jp = (JavaParameter) jn;
        jp.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
    } else if (jn instanceof JavaMethod) {
        JavaMethod jm = (JavaMethod) jn;
        jm.addAnnotation("XmlJavaTypeAdapter", jaxbAnnotation);
    } else {
        throw new RuntimeException("Annotation of " + jn.getClass() + " not supported.");
    }
    jf.addImport(XmlJavaTypeAdapter.class.getName());
    jf.addImport(adapter.getName());
}
Also used : JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod)

Example 35 with XmlJavaTypeAdapter

use of javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter 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)

Aggregations

XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)40 Annotation (java.lang.annotation.Annotation)10 XmlList (javax.xml.bind.annotation.XmlList)7 QName (javax.xml.namespace.QName)7 EnunciateException (com.webcohesion.enunciate.EnunciateException)5 DecoratedDeclaredType (com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType)5 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)5 DeclaredType (javax.lang.model.type.DeclaredType)5 JAXBElement (javax.xml.bind.JAXBElement)5 XmlElement (javax.xml.bind.annotation.XmlElement)5 XmlAdapter (javax.xml.bind.annotation.adapters.XmlAdapter)5 XmlJavaTypeAdapters (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters)5 ParameterizedType (java.lang.reflect.ParameterizedType)4 Type (java.lang.reflect.Type)4 TypeElement (javax.lang.model.element.TypeElement)4 XmlAttachmentRef (javax.xml.bind.annotation.XmlAttachmentRef)4 JAXBBeanInfo (org.apache.cxf.common.jaxb.JAXBBeanInfo)4 DecoratedProcessingEnvironment (com.webcohesion.enunciate.javac.decorations.DecoratedProcessingEnvironment)3 Method (java.lang.reflect.Method)3 TypeMirror (javax.lang.model.type.TypeMirror)3