Search in sources :

Example 1 with ZimbraKeyValuePairs

use of com.zimbra.soap.json.jackson.annotate.ZimbraKeyValuePairs 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 ZimbraKeyValuePairs

use of com.zimbra.soap.json.jackson.annotate.ZimbraKeyValuePairs in project zm-mailbox by Zimbra.

the class JaxbInfo method getKeyValuePairElementInfo.

/**
     * If this object has keyvaluepairs for children, this returns information about them, otherwise returns null.
     * Note implicit assumption that there can only be one set of keyvaluepairs - this is because the JSON
     * representation would be unable to differentiate between them.
     */
public KeyValuePairXmlRepresentationInfo getKeyValuePairElementInfo() {
    if (haveKvpXmlInfo) {
        return kvpXmlInfo;
    }
    String elemName = null;
    String attrName = null;
    Field[] fields = jaxbClass.getDeclaredFields();
    for (Field field : fields) {
        ZimbraKeyValuePairs annot = field.getAnnotation(ZimbraKeyValuePairs.class);
        if (annot == null) {
            continue;
        }
        XmlElement xmlElemAnnot = field.getAnnotation(XmlElement.class);
        if (xmlElemAnnot != null) {
            elemName = xmlElemAnnot.name();
        } else {
            elemName = field.getName();
        }
    }
    if (elemName != null) {
        Method[] methods = jaxbClass.getDeclaredMethods();
        for (Method method : methods) {
            ZimbraKeyValuePairs annot = method.getAnnotation(ZimbraKeyValuePairs.class);
            if (annot == null) {
                continue;
            }
            XmlElement xmlElemAnnot = method.getAnnotation(XmlElement.class);
            if (xmlElemAnnot != null) {
                elemName = xmlElemAnnot.name();
            } else {
                elemName = method.getName();
            }
        }
    }
    if (elemName != null) {
        Class<?> kvpElemClass = this.getClassForElement(elemName);
        if (kvpElemClass != null) {
            JaxbInfo kvpJaxbInfo = JaxbInfo.getFromCache(kvpElemClass);
            if (kvpJaxbInfo != null) {
                Iterable<String> attribNames = kvpJaxbInfo.getAttributeNames();
                if (attribNames != null) {
                    for (String attribName : attribNames) {
                        // Should only be one...
                        attrName = attribName;
                        break;
                    }
                }
            }
        }
    }
    if ((elemName != null) && (attrName != null)) {
        kvpXmlInfo = new KeyValuePairXmlRepresentationInfo(elemName, attrName);
    } else {
        kvpXmlInfo = null;
    }
    haveKvpXmlInfo = true;
    return kvpXmlInfo;
}
Also used : Field(java.lang.reflect.Field) ZimbraKeyValuePairs(com.zimbra.soap.json.jackson.annotate.ZimbraKeyValuePairs) XmlElement(javax.xml.bind.annotation.XmlElement) Method(java.lang.reflect.Method)

Aggregations

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