private final void validateOneAnnotation(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 == 1); Annotation a = annotations[0]; 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()); }
private XmlJavaTypeAdapter getApplicableAdapter(T type) { XmlJavaTypeAdapter jta = seed.readAnnotation(XmlJavaTypeAdapter.class); if(jta!=null && isApplicable(jta,type)) return jta; // check the applicable adapters on the package XmlJavaTypeAdapters jtas = reader().getPackageAnnotation(XmlJavaTypeAdapters.class, parent.clazz, seed ); if(jtas!=null) { for (XmlJavaTypeAdapter xjta : jtas.value()) { if(isApplicable(xjta,type)) return xjta; } } jta = reader().getPackageAnnotation(XmlJavaTypeAdapter.class, parent.clazz, seed ); if(isApplicable(jta,type)) return jta; // then on the target class C refType = nav().asDecl(type); if(refType!=null) { jta = reader().getClassAnnotation(XmlJavaTypeAdapter.class, refType, seed ); if(jta!=null && isApplicable(jta,type)) // the one on the type always apply. return jta; } return null; }
private XmlJavaTypeAdapter getApplicableAdapter(T type) { XmlJavaTypeAdapter jta = seed.readAnnotation(XmlJavaTypeAdapter.class); if (jta != null && isApplicable(jta, type)) return jta; // check the applicable adapters on the package XmlJavaTypeAdapters jtas = reader().getPackageAnnotation(XmlJavaTypeAdapters.class, parent.clazz, seed); if (jtas != null) { for (XmlJavaTypeAdapter xjta : jtas.value()) { if (isApplicable(xjta, type)) return xjta; } } jta = reader().getPackageAnnotation(XmlJavaTypeAdapter.class, parent.clazz, seed); if (isApplicable(jta, type)) return jta; if (type instanceof Type) { jta = JefAdapters.get((Type)type); if (jta != null && isApplicable(jta, type)) { return jta; } } // then on the target class C refType = nav().asDecl(type); if (refType != null) { jta = reader().getClassAnnotation(XmlJavaTypeAdapter.class, refType, seed); if (jta != null && isApplicable(jta, type)) // the one on the type // always apply. return jta; } return null; }
private void generatePackageInfo(String className, String ns, Class clz) { ClassWriter cw = createClassWriter(); String classFileName = periodToSlashes(className); cw.visit(Opcodes.V1_5, Opcodes.ACC_ABSTRACT + Opcodes.ACC_INTERFACE, classFileName, null, "java/lang/Object", null); boolean q = qualified; SchemaInfo si = interfaceInfo.getService().getSchema(ns); if (si != null) { q = si.isElementFormQualified(); } AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlSchema;", true); av0.visit("namespace", ns); av0.visitEnum("elementFormDefault", getClassCode(XmlNsForm.class), q ? "QUALIFIED" : "UNQUALIFIED"); av0.visitEnd(); if (clz.getPackage() != null && clz.getPackage().getAnnotations() != null) { for (Annotation ann : clz.getPackage().getAnnotations()) { if (ann instanceof XmlJavaTypeAdapters) { av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapters;", true); generateXmlJavaTypeAdapters(av0, (XmlJavaTypeAdapters)ann); av0.visitEnd(); } else if (ann instanceof XmlJavaTypeAdapter) { av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapter;", true); generateXmlJavaTypeAdapter(av0, (XmlJavaTypeAdapter)ann); av0.visitEnd(); } } } cw.visitEnd(); loadClass(className, clz, cw.toByteArray()); }
private void generateXmlJavaTypeAdapters(AnnotationVisitor av, XmlJavaTypeAdapters adapters) { AnnotationVisitor av1 = av.visitArray("value"); for (XmlJavaTypeAdapter adapter : adapters.value()) { AnnotationVisitor av2 = av1.visitAnnotation(null, "Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapter;"); generateXmlJavaTypeAdapter(av2, adapter); av2.visitEnd(); } av1.visitEnd(); }
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()); }