use of javax.xml.bind.annotation.XmlElementRef 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;
}
}
}
use of javax.xml.bind.annotation.XmlElementRef 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;
}
}
}
use of javax.xml.bind.annotation.XmlElementRef 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);
}
}
use of javax.xml.bind.annotation.XmlElementRef in project camel by apache.
the class ModelSanityCheckerTest method testSanity.
public void testSanity() throws Exception {
Set<Class<?>> classes = discoverJaxbClasses();
assertNotNull(classes);
assertTrue("There should be > 140 classes, was: " + classes.size(), classes.size() > 140);
// check each class is okay
for (Class<?> clazz : classes) {
// skip ProcessorDefinition as its special
if (clazz == ProcessorDefinition.class) {
continue;
}
// skip RouteDefinition as its special
if (clazz == RouteDefinition.class) {
continue;
}
// check each declared field in the class
for (Field field : clazz.getDeclaredFields()) {
LOG.debug("Class {} has field {}", clazz.getName(), field.getName());
// does the field have a jaxb annotation?
boolean attribute = field.getAnnotation(XmlAttribute.class) != null;
boolean element = field.getAnnotation(XmlElement.class) != null;
boolean elementRef = field.getAnnotation(XmlElementRef.class) != null;
// only one of those 3 is allowed, so check that we don't have 2+ of them
if ((attribute && element) || (attribute && elementRef) || (element && elementRef)) {
fail("Class " + clazz.getName() + " has field " + field.getName() + " which has 2+ annotations that are not allowed together.");
}
// check getter/setter
if (attribute || element || elementRef) {
// check for getter/setter
Method getter = IntrospectionSupport.getPropertyGetter(clazz, field.getName());
Method setter = IntrospectionSupport.getPropertySetter(clazz, field.getName());
assertNotNull("Getter " + field.getName() + " on class " + clazz.getName() + " is missing", getter);
assertNotNull("Setter " + field.getName() + " on class " + clazz.getName() + " is missing", setter);
}
}
// we do not expect any JAXB annotations on methods
for (Method method : clazz.getDeclaredMethods()) {
LOG.debug("Class {} has method {}", clazz.getName(), method.getName());
// special for OptionalIdentifiedDefinition as it has setter, so we should skip it
if (clazz.getCanonicalName().equals(OptionalIdentifiedDefinition.class.getCanonicalName())) {
continue;
}
// does the method have a jaxb annotation?
boolean attribute = method.getAnnotation(XmlAttribute.class) != null;
boolean element = method.getAnnotation(XmlElement.class) != null;
boolean elementRef = method.getAnnotation(XmlElementRef.class) != null;
assertFalse("Class " + clazz.getName() + " has method " + method.getName() + " should not have @XmlAttribute annotation", attribute);
assertFalse("Class " + clazz.getName() + " has method " + method.getName() + " should not have @XmlElement annotation", element);
assertFalse("Class " + clazz.getName() + " has method " + method.getName() + " should not have @XmlElementRef annotation", elementRef);
}
}
}
use of javax.xml.bind.annotation.XmlElementRef in project midpoint by Evolveum.
the class PrismBeanInspector method lookupSubstitutionUncached.
private Field lookupSubstitutionUncached(Class beanClass, Method elementMethodInObjectFactory) {
XmlElementDecl xmlElementDecl = elementMethodInObjectFactory.getAnnotation(XmlElementDecl.class);
if (xmlElementDecl == null) {
return null;
}
final String substitutionHeadName = xmlElementDecl.substitutionHeadName();
return findField(beanClass, field -> {
XmlElementRef xmlElementRef = field.getAnnotation(XmlElementRef.class);
return xmlElementRef != null && xmlElementRef.name().equals(substitutionHeadName);
});
}
Aggregations