Ejemplo n.º 1
0
 private JAXBContext newJAXBContext(final Class<?>... pClasses) throws JAXBException {
   Class<?>[] classList;
   final Class<?> clazz = getDeclaringClass();
   final XmlSeeAlso seeAlso = clazz.getAnnotation(XmlSeeAlso.class);
   if ((seeAlso != null) && (seeAlso.value().length > 0)) {
     final Class<?>[] seeAlsoClasses = seeAlso.value();
     classList = new Class<?>[seeAlsoClasses.length + pClasses.length];
     System.arraycopy(seeAlsoClasses, 0, classList, 0, seeAlsoClasses.length);
     System.arraycopy(pClasses, 0, classList, seeAlsoClasses.length, pClasses.length);
   } else {
     classList = pClasses;
   }
   return JAXBContext.newInstance(classList);
 }
Ejemplo n.º 2
0
  static AnnotationDesc create(Class cls) {
    AnnotationDescImpl aDesc = new AnnotationDescImpl();

    // XMLSeeAlso is part of JAXB 2.1.2.
    // The assumption is that this is a prereq for JAXWS 2.1; thus
    // we can safely reference this class
    XmlSeeAlso xmlSeeAlso = (XmlSeeAlso) getAnnotation(cls, XmlSeeAlso.class);

    if (xmlSeeAlso != null) {
      aDesc._XmlSeeAlsoClasses = xmlSeeAlso.value();
    }

    QName qName = XMLRootElementUtil.getXmlRootElementQName(cls);
    if (qName != null) {
      aDesc._hasXmlRootElement = true;
      aDesc._XmlRootElementName = qName.getLocalPart();
      aDesc._XmlRootElementNamespace = qName.getNamespaceURI();
    }

    qName = XMLRootElementUtil.getXmlTypeQName(cls);
    if (qName != null) {
      aDesc._hasXmlType = true;
      aDesc._XmlTypeName = qName.getLocalPart();
      aDesc._XmlTypeNamespace = qName.getNamespaceURI();
    }
    return aDesc;
  }
  /**
   * @param ar abstract resource
   * @param path resources path
   * @return resource
   * @see
   *     org.glassfish.jersey.server.wadl.WadlGenerator#createResource(org.glassfish.jersey.server.model.Resource,
   *     String)
   */
  public Resource createResource(org.glassfish.jersey.server.model.Resource ar, String path) {
    for (Class<?> resClass : ar.getHandlerClasses()) {
      XmlSeeAlso seeAlso = (XmlSeeAlso) resClass.getAnnotation(XmlSeeAlso.class);
      if (seeAlso != null) {
        Collections.addAll(seeAlsoClasses, seeAlso.value());
      }
    }

    return wadlGeneratorDelegate.createResource(ar, path);
  }
  private void addClass(Class<?> cls) {
    if (Throwable.class.isAssignableFrom(cls)) {
      if (!Throwable.class.equals(cls) && !Exception.class.equals(cls)) {
        walkReferences(cls);
      }
      addClass(String.class);
    } else {
      cls = JAXBUtils.getValidClass(cls);
      if (null != cls) {
        if (classes.contains(cls)) {
          return;
        }

        if (!cls.isInterface()) {
          classes.add(cls);
        }

        XmlSeeAlso xsa = cls.getAnnotation(XmlSeeAlso.class);
        if (xsa != null) {
          for (Class<?> c : xsa.value()) {
            addClass(c);
          }
        }
        XmlJavaTypeAdapter xjta = cls.getAnnotation(XmlJavaTypeAdapter.class);
        if (xjta != null) {
          // has an adapter.   We need to inspect the adapter and then
          // return as the adapter will handle the superclass
          // and interfaces and such
          Type t = getTypeFromXmlAdapter(xjta);
          if (t != null) {
            addType(t);
          }
          return;
        }

        if (cls.getSuperclass() != null) {
          // JAXB should do this, but it doesn't always.
          // in particular, older versions of jaxb don't
          addClass(cls.getSuperclass());
        }

        if (!cls.isInterface()) {
          walkReferences(cls);
        }
      }
    }
  }
Ejemplo n.º 5
0
  void addClass(Class<?> claz) {
    if (Throwable.class.isAssignableFrom(claz)) {
      if (!Throwable.class.equals(claz) && !Exception.class.equals(claz)) {
        walkReferences(claz);
      }
      addClass(String.class);
    } else if (claz.getName().startsWith("java.") || claz.getName().startsWith("javax.")) {
      return;
    } else {
      Class<?> cls = JAXBUtils.getValidClass(claz);
      if (cls == null
          && ReflectionUtil.getDeclaredConstructors(claz).length > 0
          && !Modifier.isAbstract(claz.getModifiers())) {
        if (LOG.isLoggable(Level.INFO)) {
          LOG.info(
              "Class "
                  + claz.getName()
                  + " does not have a default constructor which JAXB requires.");
        }
        // there is no init(), but other constructors
        Object factory = createFactory(claz, ReflectionUtil.getDeclaredConstructors(claz)[0]);
        unmarshallerProperties.put("com.sun.xml.bind.ObjectFactory", factory);
        cls = claz;
      }
      if (null != cls) {
        if (classes.contains(cls)) {
          return;
        }

        if (!cls.isInterface()) {
          classes.add(cls);
        }

        XmlSeeAlso xsa = cls.getAnnotation(XmlSeeAlso.class);
        if (xsa != null) {
          for (Class<?> c : xsa.value()) {
            addClass(c);
          }
        }
        XmlJavaTypeAdapter xjta = cls.getAnnotation(XmlJavaTypeAdapter.class);
        if (xjta != null) {
          // has an adapter.   We need to inspect the adapter and then
          // return as the adapter will handle the superclass
          // and interfaces and such
          Type t = Utils.getTypeFromXmlAdapter(xjta);
          if (t != null) {
            addType(t);
          }
          return;
        }

        if (cls.getSuperclass() != null) {
          // JAXB should do this, but it doesn't always.
          // in particular, older versions of jaxb don't
          addClass(cls.getSuperclass());
        }

        if (!cls.isInterface()) {
          walkReferences(cls);
        }
      }
    }
  }