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());
  }
예제 #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);
     }
   }
 }
 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;
 }
 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;
 }
 @SuppressWarnings("rawtypes")
 static XmlAdapter getXmlAdapter(XmlJavaTypeAdapter adapterAnnotation)
     throws InstantiationException, IllegalAccessException {
   return adapterAnnotation != null ? adapterAnnotation.value().newInstance() : null;
 }