Search in sources :

Example 1 with XmlElementRefs

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

the class NameInfo method setWrappedInfo.

private void setWrappedInfo(AnnotationIntrospector ai, AnnotatedMember prop, String defaultWrappedName) {
    ZimbraUniqueElement uniqueElemAnnot = prop.getAnnotation(ZimbraUniqueElement.class);
    if (uniqueElemAnnot != null) {
        treatAsUniqueElement = uniqueElemAnnot.value();
    }
    ZimbraJsonArrayForWrapper arrayForWrapperAnnot = prop.getAnnotation(ZimbraJsonArrayForWrapper.class);
    if (arrayForWrapperAnnot != null) {
        wrapperIsArray = arrayForWrapperAnnot.value();
    }
    ZimbraKeyValuePairs kvpAnnot = prop.getAnnotation(ZimbraKeyValuePairs.class);
    if (kvpAnnot != null) {
        keyValuePairs = kvpAnnot.value();
        return;
    }
    ZimbraJsonAttribute jsonAttributeAnnot = prop.getAnnotation(ZimbraJsonAttribute.class);
    if (jsonAttributeAnnot != null) {
        treatAsAttribute = jsonAttributeAnnot.value();
    }
    mixedAllowed = (prop.getAnnotation(XmlMixed.class) != null);
    anyElementAllowed = (prop.getAnnotation(XmlAnyElement.class) != null);
    anyAttributeAllowed = (prop.getAnnotation(XmlAnyAttribute.class) != null);
    XmlElement elemAnnot = prop.getAnnotation(XmlElement.class);
    if (elemAnnot != null) {
        wrappedName = getQName(prop.getName(), elemAnnot.namespace(), elemAnnot.name());
        return;
    }
    XmlElementRef elemRefAnnot = prop.getAnnotation(XmlElementRef.class);
    wrappedName = getElementRefName(elemRefAnnot);
    if (wrappedName != null) {
        return;
    }
    XmlElements elemsAnnot = prop.getAnnotation(XmlElements.class);
    if (elemsAnnot != null) {
        XmlElement[] elems = elemsAnnot.value();
        wrappedNameMap = Maps.newHashMapWithExpectedSize(elems.length);
        for (XmlElement elem : elems) {
            QName qn = getQName(prop.getName(), elem.namespace(), elem.name());
            Class<?> kls = elem.type();
            getWrappedNameMap().put(kls, qn);
        }
        return;
    }
    XmlElementRefs elemRefsAnnot = prop.getAnnotation(XmlElementRefs.class);
    if (elemRefsAnnot != null) {
        XmlElementRef[] elems = elemRefsAnnot.value();
        wrappedNameMap = Maps.newHashMapWithExpectedSize(elems.length);
        for (XmlElementRef elem : elems) {
            QName qn = getElementRefName(elem);
            Class<?> kls = elem.type();
            getWrappedNameMap().put(kls, qn);
        }
        return;
    }
    if (wrapperName != null) {
        // We have a wrapper but nothing to tell us what the wrapped name should be, so use default
        wrappedName = new QName("", defaultWrappedName);
    }
}
Also used : XmlElementRef(javax.xml.bind.annotation.XmlElementRef) ZimbraKeyValuePairs(com.zimbra.soap.json.jackson.annotate.ZimbraKeyValuePairs) ZimbraJsonAttribute(com.zimbra.soap.json.jackson.annotate.ZimbraJsonAttribute) QName(javax.xml.namespace.QName) ZimbraJsonArrayForWrapper(com.zimbra.soap.json.jackson.annotate.ZimbraJsonArrayForWrapper) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) XmlElementRefs(javax.xml.bind.annotation.XmlElementRefs) XmlMixed(javax.xml.bind.annotation.XmlMixed) XmlElements(javax.xml.bind.annotation.XmlElements) ZimbraUniqueElement(com.zimbra.soap.json.jackson.annotate.ZimbraUniqueElement) XmlAnyAttribute(javax.xml.bind.annotation.XmlAnyAttribute) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 2 with XmlElementRefs

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

the class JaxbInfo method processFieldRelatedAnnotations.

private void processFieldRelatedAnnotations(Annotation[] annots, String fieldName, Type defaultGenericType) {
    WrappedElementInfo wrappedInfo = null;
    for (Annotation annot : annots) {
        if (annot instanceof XmlElementWrapper) {
            XmlElementWrapper wrapper = (XmlElementWrapper) annot;
            wrappedInfo = new WrappedElementInfo(wrapper, fieldName);
            jaxbElemNodeInfo.add(wrappedInfo);
            break;
        }
    }
    for (Annotation annot : annots) {
        if (annot instanceof XmlValue) {
            elementValue = new JaxbValueInfo((XmlValue) annot, fieldName, defaultGenericType);
        } else if (annot instanceof XmlAttribute) {
            XmlAttribute attr = (XmlAttribute) annot;
            String attrName = attr.name();
            if ((attrName == null) || DEFAULT_MARKER.equals(attrName)) {
                attrName = fieldName;
            }
            this.setXmlAttributeInfo(attr, fieldName, defaultGenericType);
            this.attributeNames.add(attrName);
        } else if (annot instanceof XmlElement) {
            XmlElement xmlElem = (XmlElement) annot;
            if (wrappedInfo == null) {
                setXmlElementInfo(xmlElem, fieldName, defaultGenericType);
            } else {
                wrappedInfo.add(xmlElem, fieldName, defaultGenericType);
            }
        } else if (annot instanceof XmlElementRef) {
            XmlElementRef xmlElemR = (XmlElementRef) annot;
            if (wrappedInfo == null) {
                setXmlElementInfo(xmlElemR, null, null);
            } else {
                wrappedInfo.add(xmlElemR, null, null);
            }
        } else if (annot instanceof XmlElements) {
            JaxbPseudoNodeChoiceInfo choiceNode = new JaxbPseudoNodeChoiceInfo(fieldName, defaultGenericType);
            if (wrappedInfo == null) {
                jaxbElemNodeInfo.add(choiceNode);
            } else {
                wrappedInfo.add(choiceNode);
            }
            XmlElements xmlElemsAnnot = (XmlElements) annot;
            for (XmlElement xmlE : xmlElemsAnnot.value()) {
                choiceNode.add(xmlE);
            }
        } else if (annot instanceof XmlElementRefs) {
            JaxbPseudoNodeChoiceInfo choiceNode = new JaxbPseudoNodeChoiceInfo(fieldName, defaultGenericType);
            if (wrappedInfo == null) {
                jaxbElemNodeInfo.add(choiceNode);
            } else {
                wrappedInfo.add(choiceNode);
            }
            XmlElementRefs elemRefs = (XmlElementRefs) annot;
            for (XmlElementRef xmlE : elemRefs.value()) {
                choiceNode.add(xmlE);
            }
        }
    }
}
Also used : XmlElementRef(javax.xml.bind.annotation.XmlElementRef) XmlElements(javax.xml.bind.annotation.XmlElements) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) XmlValue(javax.xml.bind.annotation.XmlValue) XmlElement(javax.xml.bind.annotation.XmlElement) XmlElementRefs(javax.xml.bind.annotation.XmlElementRefs) Annotation(java.lang.annotation.Annotation) XmlElementWrapper(javax.xml.bind.annotation.XmlElementWrapper)

Aggregations

XmlElement (javax.xml.bind.annotation.XmlElement)2 XmlElementRef (javax.xml.bind.annotation.XmlElementRef)2 XmlElementRefs (javax.xml.bind.annotation.XmlElementRefs)2 XmlElements (javax.xml.bind.annotation.XmlElements)2 ZimbraJsonArrayForWrapper (com.zimbra.soap.json.jackson.annotate.ZimbraJsonArrayForWrapper)1 ZimbraJsonAttribute (com.zimbra.soap.json.jackson.annotate.ZimbraJsonAttribute)1 ZimbraKeyValuePairs (com.zimbra.soap.json.jackson.annotate.ZimbraKeyValuePairs)1 ZimbraUniqueElement (com.zimbra.soap.json.jackson.annotate.ZimbraUniqueElement)1 Annotation (java.lang.annotation.Annotation)1 XmlAnyAttribute (javax.xml.bind.annotation.XmlAnyAttribute)1 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)1 XmlMixed (javax.xml.bind.annotation.XmlMixed)1 XmlValue (javax.xml.bind.annotation.XmlValue)1 QName (javax.xml.namespace.QName)1