Search in sources :

Example 1 with XmlValue

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

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

XmlAttribute (javax.xml.bind.annotation.XmlAttribute)2 XmlElement (javax.xml.bind.annotation.XmlElement)2 XmlElementRef (javax.xml.bind.annotation.XmlElementRef)2 XmlElements (javax.xml.bind.annotation.XmlElements)2 XmlValue (javax.xml.bind.annotation.XmlValue)2 Annotation (java.lang.annotation.Annotation)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 XmlElementRefs (javax.xml.bind.annotation.XmlElementRefs)1 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)1 AnnotationProcessorHelper.findTypeElement (org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement)1