Esempio n. 1
0
  /**
   * The qname for the referenced element, if this element is a reference to a global element, or
   * null if this element is not a reference element.
   *
   * @return The qname for the referenced element, if exists.
   */
  public QName getRef() {
    QName ref = null;

    boolean qualified = getForm() == XmlNsForm.QUALIFIED;
    String typeNamespace = getTypeDefinition().getNamespace();
    typeNamespace = typeNamespace == null ? "" : typeNamespace;
    String elementNamespace = isWrapped() ? getWrapperNamespace() : getNamespace();
    elementNamespace = elementNamespace == null ? "" : elementNamespace;
    if ((!elementNamespace.equals(typeNamespace)) && (qualified || !"".equals(elementNamespace))) {
      // the namespace is different; must be a ref...
      return new QName(elementNamespace, isWrapped() ? getWrapperName() : getName());
    } else {
      // check to see if this is an implied ref as per the jaxb spec, section 8.9.1.2
      com.webcohesion.enunciate.modules.jaxb.model.types.XmlType baseType = getBaseType();
      if ((baseType.isAnonymous()) && (baseType instanceof XmlClassType)) {
        TypeDefinition baseTypeDef = ((XmlClassType) baseType).getTypeDefinition();
        if (baseTypeDef.getAnnotation(XmlRootElement.class) != null) {
          RootElementDeclaration rootElement =
              new RootElementDeclaration(baseTypeDef.getDelegate(), baseTypeDef, this.context);
          ref = new QName(rootElement.getNamespace(), rootElement.getName());
        }
      }
    }

    return ref;
  }
Esempio n. 2
0
  public Element(
      javax.lang.model.element.Element delegate,
      TypeDefinition typedef,
      EnunciateJaxbContext context) {
    super(delegate, typedef, context);

    XmlElement xmlElement = getAnnotation(XmlElement.class);
    XmlElements xmlElements = getAnnotation(XmlElements.class);
    if (xmlElements != null) {
      XmlElement[] elementChoices = xmlElements.value();
      if (elementChoices.length == 0) {
        xmlElements = null;
      } else if ((xmlElement == null) && (elementChoices.length == 1)) {
        xmlElement = elementChoices[0];
        xmlElements = null;
      }
    }

    this.xmlElement = xmlElement;
    this.choices = new ArrayList<Element>();
    if (xmlElements != null) {
      for (final XmlElement element : xmlElements.value()) {
        DecoratedTypeMirror typeMirror =
            Annotations.mirrorOf(
                new Callable<Class<?>>() {
                  @Override
                  public Class<?> call() throws Exception {
                    return element.type();
                  }
                },
                this.env,
                XmlElement.DEFAULT.class);

        if ((typeMirror instanceof ArrayType
                && ((ArrayType) typeMirror).getComponentType().getKind() != TypeKind.BYTE)
            || (typeMirror.isCollection())) {
          throw new EnunciateException(
              "Member "
                  + getName()
                  + " of "
                  + typedef.getQualifiedName()
                  + ": an element choice must not be a collection or an array.");
        }

        this.choices.add(new Element(getDelegate(), getTypeDefinition(), element, context));
      }
    } else {
      this.choices.add(this);
    }
  }