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 Class<?> getTypeFromXmlAdapter(XmlJavaTypeAdapter xjta) {
   if (xjta != null) {
     Class<?> c2 = xjta.value();
     Type sp = c2.getGenericSuperclass();
     while (!XmlAdapter.class.equals(c2) && c2 != null) {
       sp = c2.getGenericSuperclass();
       c2 = c2.getSuperclass();
     }
     if (sp instanceof ParameterizedType) {
       return (Class<?>) ((ParameterizedType) sp).getActualTypeArguments()[0];
     }
   }
   return null;
 }
Ejemplo n.º 3
0
 private void checkForJAXBAnnotations(
     MessagePartInfo mpi, SchemaCollection schemaCollection, String ns) {
   Annotation[] anns = (Annotation[]) mpi.getProperty("parameter.annotations");
   JAXBContextProxy ctx = JAXBUtils.createJAXBContextProxy(context, schemaCollection, ns);
   XmlJavaTypeAdapter jta =
       JAXBSchemaInitializer.findFromTypeAdapter(ctx, mpi.getTypeClass(), anns);
   if (jta != null) {
     JAXBBeanInfo jtaBeanInfo = JAXBSchemaInitializer.findFromTypeAdapter(ctx, jta.value());
     JAXBBeanInfo beanInfo = JAXBSchemaInitializer.getBeanInfo(ctx, mpi.getTypeClass());
     if (jtaBeanInfo != beanInfo) {
       mpi.setProperty("parameter.annotations", anns);
       mpi.setProperty("honor.jaxb.annotations", Boolean.TRUE);
     }
   }
 }
 @SuppressWarnings("rawtypes")
 static XmlAdapter getXmlAdapter(XmlJavaTypeAdapter adapterAnnotation)
     throws InstantiationException, IllegalAccessException {
   return adapterAnnotation != null ? adapterAnnotation.value().newInstance() : null;
 }