Search in sources :

Example 1 with XmlElement

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

the class PrismBeanInspector method findFieldElementQNameUncached.

private QName findFieldElementQNameUncached(String fieldName, Class beanClass, String defaultNamespace) {
    Field field;
    try {
        field = beanClass.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
        // TODO implement this if needed (lookup the getter method instead of the field)
        return new QName(defaultNamespace, fieldName);
    }
    String realLocalName = fieldName;
    String realNamespace = defaultNamespace;
    XmlElement xmlElement = field.getAnnotation(XmlElement.class);
    if (xmlElement != null) {
        String name = xmlElement.name();
        if (name != null && !BeanMarshaller.DEFAULT_PLACEHOLDER.equals(name)) {
            realLocalName = name;
        }
        String namespace = xmlElement.namespace();
        if (namespace != null && !BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
            realNamespace = namespace;
        }
    }
    return new QName(realNamespace, realLocalName);
}
Also used : QName(javax.xml.namespace.QName) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 2 with XmlElement

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

the class PrismBeanInspector method findPropertyFieldExactUncached.

private <T> Field findPropertyFieldExactUncached(Class<T> classType, String propName) {
    for (Field field : classType.getDeclaredFields()) {
        XmlElement xmlElement = field.getAnnotation(XmlElement.class);
        if (xmlElement != null && xmlElement.name() != null && xmlElement.name().equals(propName)) {
            return field;
        }
        XmlAttribute xmlAttribute = field.getAnnotation(XmlAttribute.class);
        if (xmlAttribute != null && xmlAttribute.name() != null && xmlAttribute.name().equals(propName)) {
            return field;
        }
    }
    try {
        return classType.getDeclaredField(propName);
    } catch (NoSuchFieldException e) {
    // nothing found
    }
    Class<? super T> superclass = classType.getSuperclass();
    if (superclass == null || Object.class.equals(superclass)) {
        return null;
    }
    return findPropertyField(superclass, propName);
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 3 with XmlElement

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

the class JaxbToJsonTest method kvpForCreateDLResp_bug74371.

/*
# zmsoap -z -t account -m user1 GetDistributionListRequest/dl=grendl@coco.local @by=name
<GetDistributionListResponse xmlns="urn:zimbraAccount">
  <dl id="7a3e8ec5-4892-4b17-9225-cf17e8b3acc9" dynamic="1" name="grendl@coco.local" isOwner="1" isMember="1">
    <a n="mail">grendl@coco.local</a>
    <a n="zimbraMailStatus">enabled</a>
    <a n="zimbraMailAlias">grendl@coco.local</a>
    <a n="description">Wonder at that</a>
    <a n="displayName">Gren DLfun</a>
    <a n="zimbraDistributionListSubscriptionPolicy">ACCEPT</a>
    <a n="zimbraDistributionListUnsubscriptionPolicy">ACCEPT</a>
  </dl>
</GetDistributionListResponse>
# zmsoap --json -z -t account -m user1 GetDistributionListRequest/dl=grendl@coco.local @by=name
{
  "dl": [{
      "name": "grendl@coco.local",
      "id": "7a3e8ec5-4892-4b17-9225-cf17e8b3acc9",
      "dynamic": true,
      "isMember": true,
      "isOwner": true,
      "_attrs": {
        "mail": "grendl@coco.local",
        "zimbraMailStatus": "enabled",
        "zimbraMailAlias": "grendl@coco.local",
        "description": "Wonder at that",
        "displayName": "Gren DLfun",
        "zimbraDistributionListSubscriptionPolicy": "ACCEPT",
        "zimbraDistributionListUnsubscriptionPolicy": "ACCEPT"
      }
    }],
  "_jsns": "urn:zimbraAccount"
}

Extract from mailbox.log for creation of this DL by ZWC - demonstrating the different handling of attrs - See Bug 74371

      "CreateDistributionListResponse": [{
          "dl": [{
              "name": "grendl@coco.local",
              "id": "7a3e8ec5-4892-4b17-9225-cf17e8b3acc9",
              "dynamic": true,
              "a": [
                {
                  "n": "memberURL",
                  "_content": "ldap:///??sub?(|(zimbraMemberOf=7a3e8ec5-4892-4b17-9225-cf17e8b3acc9)(zimbraId=de47828e-94dd-45c3-9770-4dbd255564ca))"
                },
                {
                  "n": "mail",
                  "_content": "grendl@coco.local"
                },
                ...
     */
/**
     * Desired JSON
     */
// Re-enable when Bug 74371 is fixed? @Test
public void kvpForCreateDLResp_bug74371() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get(AccountConstants.E_CREATE_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
    populateCreateDlResp(jsonElem);
    Element xmlElem = XMLElement.mFactory.createElement(QName.get(AccountConstants.E_CREATE_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
    populateCreateDlResp(xmlElem);
    logDebug("XmlElement (for comparison) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    List<KeyValuePair> attrs = Lists.newArrayList();
    attrs.add(new KeyValuePair("key1", "value1"));
    attrs.add(new KeyValuePair("key2", "value2"));
    DLInfo dl = new DLInfo("myId", "myRef", "my name", null, null, null, null, null);
    CreateDistributionListResponse jaxb = new CreateDistributionListResponse(dl);
    Element xmlJaxbElem = JaxbUtil.jaxbToElement(jaxb, XMLElement.mFactory);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    DLInfo roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, DLInfo.class);
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    logDebug("XMLElement from JAXB ---> prettyPrint\n%1$s", xmlJaxbElem.prettyPrint());
    Element eDL = jsonJaxbElem.getElement(AdminConstants.E_DL);
    List<? extends KeyValuePair> kvps = roundtripped.getAttrList();
    Assert.assertEquals("roundtripped kvps num", 2, kvps.size());
    List<com.zimbra.common.soap.Element.KeyValuePair> elemKVPs = eDL.getElement("a").listKeyValuePairs();
    Assert.assertEquals("elemKVP num", 2, elemKVPs.size());
    Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
}
Also used : KeyValuePair(com.zimbra.soap.type.KeyValuePair) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) CreateDistributionListResponse(com.zimbra.soap.account.message.CreateDistributionListResponse) DLInfo(com.zimbra.soap.account.type.DLInfo)

Example 4 with XmlElement

use of javax.xml.bind.annotation.XmlElement in project swagger-core by swagger-api.

the class SwaggerAnnotationIntrospector method hasRequiredMarker.

@Override
public Boolean hasRequiredMarker(AnnotatedMember m) {
    ApiModelProperty ann = m.getAnnotation(ApiModelProperty.class);
    if (ann != null) {
        return ann.required();
    }
    XmlElement elem = m.getAnnotation(XmlElement.class);
    if (elem != null) {
        if (elem.required()) {
            return true;
        }
    }
    return null;
}
Also used : ApiModelProperty(io.swagger.annotations.ApiModelProperty) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 5 with XmlElement

use of javax.xml.bind.annotation.XmlElement in project camel by apache.

the class SpringAnnotationProcessor method findClassProperties.

protected void findClassProperties(ProcessingEnvironment processingEnv, PrintWriter writer, RoundEnvironment roundEnv, Set<EipOption> eipOptions, TypeElement originalClassType, TypeElement classElement, String prefix, String modelName) {
    while (true) {
        List<VariableElement> fieldElements = ElementFilter.fieldsIn(classElement.getEnclosedElements());
        for (VariableElement fieldElement : fieldElements) {
            String fieldName = fieldElement.getSimpleName().toString();
            XmlAttribute attribute = fieldElement.getAnnotation(XmlAttribute.class);
            if (attribute != null) {
                boolean skip = processAttribute(processingEnv, roundEnv, originalClassType, classElement, fieldElement, fieldName, attribute, eipOptions, prefix, modelName);
                if (skip) {
                    continue;
                }
            }
            XmlElements elements = fieldElement.getAnnotation(XmlElements.class);
            if (elements != null) {
                processElements(processingEnv, roundEnv, classElement, elements, fieldElement, eipOptions, prefix);
            }
            XmlElementRef elementRef = fieldElement.getAnnotation(XmlElementRef.class);
            if (elementRef != null) {
                processElement(processingEnv, roundEnv, classElement, null, elementRef, fieldElement, eipOptions, prefix);
            }
            XmlElement element = fieldElement.getAnnotation(XmlElement.class);
            if (element != null) {
                if ("rests".equals(fieldName)) {
                    processRests(roundEnv, classElement, element, fieldElement, fieldName, eipOptions, prefix);
                } else if ("routes".equals(fieldName)) {
                    processRoutes(roundEnv, classElement, element, fieldElement, fieldName, eipOptions, prefix);
                } else {
                    processElement(processingEnv, roundEnv, classElement, element, null, fieldElement, eipOptions, prefix);
                }
            }
        }
        // check super classes which may also have fields
        TypeElement baseTypeElement = null;
        TypeMirror superclass = classElement.getSuperclass();
        if (superclass != null) {
            String superClassName = canonicalClassName(superclass.toString());
            baseTypeElement = findTypeElement(processingEnv, roundEnv, superClassName);
        }
        if (baseTypeElement != null) {
            classElement = baseTypeElement;
        } else {
            break;
        }
    }
}
Also used : XmlElementRef(javax.xml.bind.annotation.XmlElementRef) XmlElements(javax.xml.bind.annotation.XmlElements) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) AnnotationProcessorHelper.findTypeElement(org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement) XmlElement(javax.xml.bind.annotation.XmlElement) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

XmlElement (javax.xml.bind.annotation.XmlElement)84 Test (org.junit.Test)31 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)29 Element (com.zimbra.common.soap.Element)28 JSONElement (com.zimbra.common.soap.Element.JSONElement)28 XMLElement (com.zimbra.common.soap.Element.XMLElement)28 FilterTest (com.zimbra.soap.mail.type.FilterTest)26 Field (java.lang.reflect.Field)17 Method (java.lang.reflect.Method)13 ArrayList (java.util.ArrayList)13 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)13 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)12 XmlElements (javax.xml.bind.annotation.XmlElements)10 XmlElementRef (javax.xml.bind.annotation.XmlElementRef)8 KeyValuePair (com.zimbra.soap.type.KeyValuePair)7 Annotation (java.lang.annotation.Annotation)6 Type (java.lang.reflect.Type)6 ParameterizedType (java.lang.reflect.ParameterizedType)4 List (java.util.List)4 XmlList (javax.xml.bind.annotation.XmlList)4