private void checkForAdapter(Class<?> clazz, Annotation[] anns) { if (anns != null) { for (Annotation a : anns) { if (XmlJavaTypeAdapter.class.isAssignableFrom(a.annotationType())) { Type t = getTypeFromXmlAdapter((XmlJavaTypeAdapter) a); if (t != null) { addType(t); } } } } XmlJavaTypeAdapter xjta = clazz.getAnnotation(XmlJavaTypeAdapter.class); if (xjta != null) { Type t = getTypeFromXmlAdapter(xjta); if (t != null) { addType(t); } } if (clazz.getPackage() != null) { XmlJavaTypeAdapters adapt = clazz.getPackage().getAnnotation(XmlJavaTypeAdapters.class); if (adapt != null) { for (XmlJavaTypeAdapter a : adapt.value()) { globalAdapters.add(a.type()); } for (XmlJavaTypeAdapter a : adapt.value()) { Type t = getTypeFromXmlAdapter(a); if (t != null) { addType(t); } } } } }
private final void validateTwoAnnotations(final PackageInfoModifier.Modification mod) throws Exception { assertNotNull(mod); final byte[] newClass = mod.toByteArray(); assertNotNull(newClass); assertTrue(newClass.length > 0); final Class<?> c = new ClassDefiner().define(mod.getPackageName(), newClass); assertNotNull(c); final Annotation[] annotations = c.getAnnotations(); assertNotNull(annotations); assertTrue(annotations.length == 2); Annotation a = annotations[0]; assertNotNull(a); if (a instanceof Deprecated) { a = annotations[1]; assertNotNull(a); } assertTrue(a instanceof XmlJavaTypeAdapters); final XmlJavaTypeAdapters adaptersAnnotation = (XmlJavaTypeAdapters) a; final XmlJavaTypeAdapter[] adapters = adaptersAnnotation.value(); assertNotNull(adapters); assertEquals(1, adapters.length); final XmlJavaTypeAdapter adapter = adapters[0]; assertNotNull(adapter); assertEquals(Person.class, adapter.type()); assertEquals(AnyTypeAdapter.class, adapter.value()); }
static XmlJavaTypeAdapter getMethodXJTA(final Method m) { XmlJavaTypeAdapter adapter = m.getAnnotation(XmlJavaTypeAdapter.class); if (adapter == null) { adapter = m.getReturnType().getAnnotation(XmlJavaTypeAdapter.class); } if (adapter == null) { XmlJavaTypeAdapters adapters = m.getDeclaringClass().getPackage().getAnnotation(XmlJavaTypeAdapters.class); if (adapters != null) { for (XmlJavaTypeAdapter candidate : adapters.value()) { if (candidate != null && candidate.type().equals(m.getGenericReturnType())) { adapter = candidate; break; } } } } return adapter; }
static XmlJavaTypeAdapter getFieldXJTA(final Field f) { XmlJavaTypeAdapter adapter = f.getAnnotation(XmlJavaTypeAdapter.class); if (adapter == null) { adapter = f.getType().getAnnotation(XmlJavaTypeAdapter.class); } if (adapter == null) { XmlJavaTypeAdapters adapters = f.getDeclaringClass().getPackage().getAnnotation(XmlJavaTypeAdapters.class); if (adapters != null) { for (XmlJavaTypeAdapter candidate : adapters.value()) { if (candidate != null && candidate.type().equals(f.getType())) { adapter = candidate; break; } } } } return adapter; }