Search in sources :

Example 11 with XmlAccessType

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

Field (java.lang.reflect.Field)11 Method (java.lang.reflect.Method)11 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)11 XmlType (javax.xml.bind.annotation.XmlType)9 QName (javax.xml.namespace.QName)8 GenericArrayType (java.lang.reflect.GenericArrayType)6 ParameterizedType (java.lang.reflect.ParameterizedType)6 Type (java.lang.reflect.Type)6 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)6 PrivilegedActionException (java.security.PrivilegedActionException)4 JAXBException (javax.xml.bind.JAXBException)4 XmlAccessorOrder (javax.xml.bind.annotation.XmlAccessorOrder)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 Message (org.apache.cxf.common.i18n.Message)4 JAXBBeanInfo (org.apache.cxf.common.jaxb.JAXBBeanInfo)4 Fault (org.apache.cxf.interceptor.Fault)4 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)4 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)4 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)4 Constructor (java.lang.reflect.Constructor)2