Search in sources :

Example 1 with XmlElements

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

Example 2 with XmlElements

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

the class SpringAnnotationProcessor method processElements.

private void processElements(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, TypeElement classElement, XmlElements elements, VariableElement fieldElement, Set<EipOption> eipOptions, String prefix) {
    Elements elementUtils = processingEnv.getElementUtils();
    String fieldName;
    fieldName = fieldElement.getSimpleName().toString();
    if (elements != null) {
        String kind = "element";
        String name = fieldName;
        name = prefix + name;
        TypeMirror fieldType = fieldElement.asType();
        String fieldTypeName = fieldType.toString();
        String defaultValue = findDefaultValue(fieldElement, fieldTypeName);
        String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, classElement, true);
        if (isNullOrEmpty(docComment)) {
            Metadata metadata = fieldElement.getAnnotation(Metadata.class);
            docComment = metadata != null ? metadata.description() : null;
        }
        boolean required = false;
        required = findRequired(fieldElement, required);
        // gather oneOf of the elements
        Set<String> oneOfTypes = new TreeSet<String>();
        for (XmlElement element : elements.value()) {
            String child = element.name();
            oneOfTypes.add(child);
        }
        String displayName = null;
        Metadata metadata = fieldElement.getAnnotation(Metadata.class);
        if (metadata != null) {
            displayName = metadata.displayName();
        }
        EipOption ep = new EipOption(name, kind, displayName, fieldTypeName, required, defaultValue, docComment, false, false, null, true, oneOfTypes, false);
        eipOptions.add(ep);
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TreeSet(java.util.TreeSet) Metadata(org.apache.camel.spi.Metadata) XmlElement(javax.xml.bind.annotation.XmlElement) Elements(javax.lang.model.util.Elements) XmlElements(javax.xml.bind.annotation.XmlElements)

Example 3 with XmlElements

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

the class CoreEipAnnotationProcessor 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;
                }
            }
            XmlValue value = fieldElement.getAnnotation(XmlValue.class);
            if (value != null) {
                processValue(processingEnv, roundEnv, originalClassType, classElement, fieldElement, fieldName, value, eipOptions, prefix, modelName);
            }
            XmlElements elements = fieldElement.getAnnotation(XmlElements.class);
            if (elements != null) {
                processElements(processingEnv, roundEnv, classElement, elements, fieldElement, eipOptions, prefix);
            }
            XmlElement element = fieldElement.getAnnotation(XmlElement.class);
            if (element != null) {
                processElement(processingEnv, roundEnv, classElement, element, fieldElement, eipOptions, prefix);
            }
            // special for eips which has outputs or requires an expressions
            XmlElementRef elementRef = fieldElement.getAnnotation(XmlElementRef.class);
            if (elementRef != null) {
                // special for routes
                processRoutes(roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for outputs
                processOutputs(processingEnv, roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for when clauses (choice eip)
                processRefWhenClauses(processingEnv, roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for rests (rest-dsl)
                processRests(roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for verbs (rest-dsl)
                processVerbs(processingEnv, roundEnv, originalClassType, elementRef, fieldElement, fieldName, eipOptions, prefix);
                // special for expression
                processRefExpression(processingEnv, roundEnv, originalClassType, classElement, elementRef, fieldElement, fieldName, eipOptions, prefix);
            }
        }
        // special when we process these nodes as they do not use JAXB annotations on fields, but on methods
        if ("OptionalIdentifiedDefinition".equals(classElement.getSimpleName().toString())) {
            processIdentified(processingEnv, roundEnv, originalClassType, classElement, eipOptions, prefix);
        } else if ("RouteDefinition".equals(classElement.getSimpleName().toString())) {
            processRoute(processingEnv, roundEnv, originalClassType, classElement, 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) XmlValue(javax.xml.bind.annotation.XmlValue) XmlElement(javax.xml.bind.annotation.XmlElement) VariableElement(javax.lang.model.element.VariableElement)

Example 4 with XmlElements

use of javax.xml.bind.annotation.XmlElements 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 5 with XmlElements

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

the class CoreEipAnnotationProcessor method processElements.

private void processElements(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, TypeElement classElement, XmlElements elements, VariableElement fieldElement, Set<EipOption> eipOptions, String prefix) {
    Elements elementUtils = processingEnv.getElementUtils();
    String fieldName;
    fieldName = fieldElement.getSimpleName().toString();
    if (elements != null) {
        String kind = "element";
        String name = fieldName;
        name = prefix + name;
        TypeMirror fieldType = fieldElement.asType();
        String fieldTypeName = fieldType.toString();
        String defaultValue = findDefaultValue(fieldElement, fieldTypeName);
        String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, classElement, true);
        boolean required = true;
        required = findRequired(fieldElement, required);
        // gather oneOf of the elements
        Set<String> oneOfTypes = new TreeSet<String>();
        for (XmlElement element : elements.value()) {
            String child = element.name();
            oneOfTypes.add(child);
        }
        String displayName = null;
        Metadata metadata = fieldElement.getAnnotation(Metadata.class);
        if (metadata != null) {
            displayName = metadata.displayName();
        }
        EipOption ep = new EipOption(name, displayName, kind, fieldTypeName, required, defaultValue, docComment, false, false, null, true, oneOfTypes, false);
        eipOptions.add(ep);
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TreeSet(java.util.TreeSet) Metadata(org.apache.camel.spi.Metadata) XmlElement(javax.xml.bind.annotation.XmlElement) Elements(javax.lang.model.util.Elements) XmlElements(javax.xml.bind.annotation.XmlElements)

Aggregations

XmlElement (javax.xml.bind.annotation.XmlElement)6 XmlElements (javax.xml.bind.annotation.XmlElements)6 TypeMirror (javax.lang.model.type.TypeMirror)4 XmlElementRef (javax.xml.bind.annotation.XmlElementRef)4 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)3 TreeSet (java.util.TreeSet)2 TypeElement (javax.lang.model.element.TypeElement)2 VariableElement (javax.lang.model.element.VariableElement)2 Elements (javax.lang.model.util.Elements)2 XmlElementRefs (javax.xml.bind.annotation.XmlElementRefs)2 XmlValue (javax.xml.bind.annotation.XmlValue)2 Metadata (org.apache.camel.spi.Metadata)2 AnnotationProcessorHelper.findTypeElement (org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement)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