Search in sources :

Example 46 with XmlElement

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

Example 47 with XmlElement

use of javax.xml.bind.annotation.XmlElement in project midpoint by Evolveum.

the class PrismBeanInspector method findPropertyGetterUncached.

private <T> Method findPropertyGetterUncached(Class<T> classType, String propName) {
    if (propName.startsWith("_")) {
        propName = propName.substring(1);
    }
    for (Method method : classType.getDeclaredMethods()) {
        XmlElement xmlElement = method.getAnnotation(XmlElement.class);
        if (xmlElement != null && xmlElement.name().equals(propName)) {
            return method;
        }
        XmlAttribute xmlAttribute = method.getAnnotation(XmlAttribute.class);
        if (xmlAttribute != null && xmlAttribute.name().equals(propName)) {
            return method;
        }
    }
    String getterName = "get" + StringUtils.capitalize(propName);
    try {
        return classType.getDeclaredMethod(getterName);
    } catch (NoSuchMethodException e) {
    // nothing found
    }
    getterName = "is" + StringUtils.capitalize(propName);
    try {
        return classType.getDeclaredMethod(getterName);
    } catch (NoSuchMethodException e) {
    // nothing found
    }
    Class<? super T> superclass = classType.getSuperclass();
    if (superclass == null || superclass.equals(Object.class)) {
        return null;
    }
    return findPropertyGetter(superclass, propName);
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 48 with XmlElement

use of javax.xml.bind.annotation.XmlElement in project ddf by codice.

the class AdaptedSourceResponse method getMetacard.

@XmlElement(namespace = METACARD_URI)
public List<MetacardElement> getMetacard() {
    List<MetacardElement> metacards = new ArrayList<MetacardElement>();
    for (Result r : delegate.getResults()) {
        Metacard metacard = r.getMetacard();
        if (metacard == null) {
            continue;
        }
        MetacardElement element = new MetacardElement();
        element.setId(metacard.getId());
        element.setSource(metacard.getSourceId());
        if (metacard.getMetacardType() != null) {
            String metacardTypeName = BasicTypes.BASIC_METACARD.getName();
            if (isNotBlank(metacard.getMetacardType().getName())) {
                metacardTypeName = metacard.getMetacardType().getName();
            }
            element.setType(metacardTypeName);
            AttributeAdapter attributeAdapter = new AttributeAdapter(metacard.getMetacardType());
            for (AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
                try {
                    element.getAttributes().add(attributeAdapter.marshal(metacard.getAttribute(descriptor.getName())));
                } catch (CatalogTransformerException e) {
                    LOGGER.info("Marshalling error with attribute", e);
                }
            }
        }
        metacards.add(element);
    }
    return metacards;
}
Also used : Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardElement(ddf.catalog.transformer.xml.binding.MetacardElement) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Result(ddf.catalog.data.Result) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 49 with XmlElement

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

Example 50 with XmlElement

use of javax.xml.bind.annotation.XmlElement in project winery by eclipse.

the class FieldValidator method setDeclaredFields.

private void setDeclaredFields(Class base, Class parent) {
    if (!this.declaredFields.containsKey(base)) {
        this.declaredFields.put(base, new HashSet<>());
    }
    if (parent.equals(TArtifactDefinition.class)) {
        this.declaredFields.get(base).add("file");
    }
    if (!parent.equals(Object.class)) {
        this.declaredFields.get(base).addAll(Arrays.stream(parent.getDeclaredFields()).map(field -> {
            XmlAttribute xmlAttribute = field.getAnnotation(XmlAttribute.class);
            XmlElement xmlElement = field.getAnnotation(XmlElement.class);
            if (Objects.nonNull(xmlAttribute) && !xmlAttribute.name().equals("##default")) {
                return xmlAttribute.name();
            } else if (Objects.nonNull(xmlElement) && !xmlElement.name().equals("##default")) {
                return xmlElement.name();
            } else {
                return field.getName();
            }
        }).collect(Collectors.toList()));
        setDeclaredFields(base, parent.getSuperclass());
    }
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) XmlElement(javax.xml.bind.annotation.XmlElement)

Aggregations

XmlElement (javax.xml.bind.annotation.XmlElement)51 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)26 Element (com.zimbra.common.soap.Element)25 JSONElement (com.zimbra.common.soap.Element.JSONElement)25 XMLElement (com.zimbra.common.soap.Element.XMLElement)25 Test (org.junit.Test)25 FilterTest (com.zimbra.soap.mail.type.FilterTest)24 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)8 Field (java.lang.reflect.Field)7 XmlElements (javax.xml.bind.annotation.XmlElements)7 KeyValuePair (com.zimbra.soap.type.KeyValuePair)5 XmlElementRef (javax.xml.bind.annotation.XmlElementRef)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 StringAttribIntValue (com.zimbra.soap.jaxb.StringAttribIntValue)3 Annotation (java.lang.annotation.Annotation)3 TypeMirror (javax.lang.model.type.TypeMirror)3 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)3 QName (javax.xml.namespace.QName)3 GetDistributionListResponse (com.zimbra.soap.account.message.GetDistributionListResponse)2