Example #1
0
  protected boolean isExplicitTypeDefinition(Element declaration) {
    if (declaration.getKind() != ElementKind.CLASS) {
      debug("%s isn't a potential JAXB type because it's not a class.", declaration);
      return false;
    }

    PackageElement pckg =
        this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration);
    if ((pckg != null) && (pckg.getAnnotation(Ignore.class) != null)) {
      debug(
          "%s isn't a potential JAXB type because its package is annotated as to be ignored.",
          declaration);
      return false;
    }

    if (isThrowable(declaration)) {
      debug(
          "%s isn't a potential JAXB type because it's an instance of java.lang.Throwable.",
          declaration);
      return false;
    }

    List<? extends AnnotationMirror> annotationMirrors = declaration.getAnnotationMirrors();
    boolean explicitXMLTypeOrElement = false;
    for (AnnotationMirror mirror : annotationMirrors) {
      Element annotationDeclaration = mirror.getAnnotationType().asElement();
      if (annotationDeclaration != null) {
        String fqn =
            annotationDeclaration instanceof TypeElement
                ? ((TypeElement) annotationDeclaration).getQualifiedName().toString()
                : "";
        // exclude all XmlTransient types and all jaxws types.
        if (XmlTransient.class.getName().equals(fqn)
            || fqn.startsWith("javax.xml.ws")
            || fqn.startsWith("javax.ws.rs")
            || fqn.startsWith("javax.jws")) {
          debug("%s isn't a potential JAXB type because of annotation %s.", declaration, fqn);
          return false;
        } else {
          explicitXMLTypeOrElement =
              (XmlType.class.getName().equals(fqn)) || (XmlRootElement.class.getName().equals(fqn));
        }
      }

      if (explicitXMLTypeOrElement) {
        break;
      }
    }

    return explicitXMLTypeOrElement;
  }
Example #2
0
  public void addPotentialJaxbElement(Element declaration, LinkedList<Element> contextStack) {
    if (declaration instanceof TypeElement) {
      boolean addSyntax = false;
      XmlRegistry registryMetadata = declaration.getAnnotation(XmlRegistry.class);
      if (registryMetadata != null) {
        addSyntax = this.jaxbContext.isEmpty();
        Registry registry = new Registry((TypeElement) declaration, jaxbContext);
        this.jaxbContext.add(registry);
      } else if (!this.jaxbContext.isKnownTypeDefinition((TypeElement) declaration)
          && isExplicitTypeDefinition(declaration)) {
        addSyntax = this.jaxbContext.isEmpty();
        this.jaxbContext.add(
            this.jaxbContext.createTypeDefinition((TypeElement) declaration), contextStack);
      }

      if (addSyntax) {
        // if this is the first xml element, add the xml syntax to the registry.
        this.apiRegistry.getSyntaxes().add(this.jaxbContext);
      }
    }
  }
Example #3
0
 /**
  * Whether the specified declaration is throwable.
  *
  * @param declaration The declaration to determine whether it is throwable.
  * @return Whether the specified declaration is throwable.
  */
 protected boolean isThrowable(Element declaration) {
   return declaration.getKind() == ElementKind.CLASS
       && ((DecoratedTypeMirror) declaration.asType()).isInstanceOf(Throwable.class);
 }