Search in sources :

Example 31 with XmlType

use of javax.xml.bind.annotation.XmlType in project zm-mailbox by Zimbra.

the class JaxbInfo method gatherInfo.

private void gatherInfo() {
    XmlAccessorType accessorType;
    rootElementName = null;
    XmlAccessType accessType = null;
    XmlRootElement rootE = jaxbClass.getAnnotation(XmlRootElement.class);
    if (rootE != null) {
        rootElementName = rootE.name();
    }
    xmlType = jaxbClass.getAnnotation(XmlType.class);
    accessorType = jaxbClass.getAnnotation(XmlAccessorType.class);
    if (accessorType == null) {
        Package pkg = jaxbClass.getPackage();
        accessorType = pkg.getAnnotation(XmlAccessorType.class);
    }
    if (accessorType != null) {
        accessType = accessorType.value();
    }
    if (accessType == null) {
        // Default value for JAXB
        accessType = XmlAccessType.PUBLIC_MEMBER;
    }
    Field[] fields = jaxbClass.getDeclaredFields();
    for (Field field : fields) {
        XmlTransient xmlTransient = field.getAnnotation(XmlTransient.class);
        if (xmlTransient != null) {
            continue;
        }
        Annotation[] fAnnots = field.getAnnotations();
        if ((fAnnots == null) || (fAnnots.length == 0)) {
            boolean autoFields = (accessType.equals(XmlAccessType.PUBLIC_MEMBER) || accessType.equals(XmlAccessType.FIELD));
            if (!autoFields) {
                continue;
            }
        }
        processFieldRelatedAnnotations(fAnnots, field.getName(), field.getGenericType());
    }
    Method[] methods = jaxbClass.getDeclaredMethods();
    for (Method method : methods) {
        XmlTransient xmlTransient = method.getAnnotation(XmlTransient.class);
        if (xmlTransient != null) {
            continue;
        }
        if (!isGetterOrSetter(method)) {
            continue;
        }
        Annotation[] mAnnots = method.getAnnotations();
        if ((mAnnots == null) || (mAnnots.length == 0)) {
            boolean autoGettersSetters = (accessType.equals(XmlAccessType.PUBLIC_MEMBER) || accessType.equals(XmlAccessType.PROPERTY));
            if (!autoGettersSetters) {
                continue;
            }
        }
        processFieldRelatedAnnotations(mAnnots, guessFieldNameFromGetterOrSetter(method.getName()), method.getGenericReturnType());
    }
}
Also used : XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Method(java.lang.reflect.Method) XmlTransient(javax.xml.bind.annotation.XmlTransient) Annotation(java.lang.annotation.Annotation) XmlType(javax.xml.bind.annotation.XmlType) Field(java.lang.reflect.Field) XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType)

Aggregations

XmlType (javax.xml.bind.annotation.XmlType)31 QName (javax.xml.namespace.QName)11 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)10 Method (java.lang.reflect.Method)9 Field (java.lang.reflect.Field)7 XmlSchema (javax.xml.bind.annotation.XmlSchema)7 ArrayList (java.util.ArrayList)6 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)5 XmlAccessorOrder (javax.xml.bind.annotation.XmlAccessorOrder)4 ParameterizedType (java.lang.reflect.ParameterizedType)3 Type (java.lang.reflect.Type)3 JAXBException (javax.xml.bind.JAXBException)3 XmlElement (javax.xml.bind.annotation.XmlElement)3 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)3 PrintWriter (java.io.PrintWriter)2 Annotation (java.lang.annotation.Annotation)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 JAXBContext (javax.xml.bind.JAXBContext)2