예제 #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;
  }
예제 #2
0
  @Override
  public ValidationResult validateRootElement(RootElementDeclaration rootElementDeclaration) {
    ValidationResult result = super.validateRootElement(rootElementDeclaration);
    String namespace = rootElementDeclaration.getNamespace();
    if (namespace == null) {
      namespace = "";
    }

    if (namespace.isEmpty()) {
      result.addError(rootElementDeclaration, "Root element should not be in the empty namespace.");
    }

    if (rootElementDeclaration.getName().toLowerCase().startsWith("web")) {
      result.addWarning(
          rootElementDeclaration,
          "You probably don't want a root element that starts with the name 'web'. Consider renaming using the @XmlRootElement annotation.");
    }

    JsonElementWrapper elementWrapper =
        rootElementDeclaration.getAnnotation(JsonElementWrapper.class);
    if (namespace.startsWith(CommonModels.GEDCOMX_DOMAIN) && elementWrapper == null) {
      result.addWarning(
          rootElementDeclaration,
          "Root elements in the '"
              + CommonModels.GEDCOMX_DOMAIN
              + "' namespace should probably be annotated with @"
              + JsonElementWrapper.class.getSimpleName()
              + ".");
    }

    if (elementWrapper != null) {
      String jsonName = elementWrapper.namespace() + elementWrapper.name();
      Declaration previous = this.jsonNameDeclarations.put(jsonName, rootElementDeclaration);
      if (previous != null) {
        result.addError(
            rootElementDeclaration,
            "JSON name conflict with " + String.valueOf(previous.getPosition()));
      }
    }

    return result;
  }