Ejemplo n.º 1
0
  /**
   * This method gets all relevant facets. It behaves differently from a simple getFacets() call in
   * that enumerations are not congealed.
   */
  public static Set getUsefulFacets(XSDSimpleTypeDefinition type) {
    Set rv = new HashSet();

    Iterator itor = type.getFacets().iterator();
    while (itor.hasNext()) {
      XSDConstrainingFacet facet = (XSDConstrainingFacet) itor.next();
      if (facet instanceof XSDRepeatableFacet && facet.getElement() == null) {
        // this is a fake pattern or enum; get the individual entries:
        if (facet instanceof XSDPatternFacet) {
          XSDPatternFacet pf = (XSDPatternFacet) facet;
          XSDSimpleTypeDefinition realParent = (XSDSimpleTypeDefinition) pf.getContainer();
          // only add patterns if they belong to this type:
          if (realParent == type) {
            rv.addAll(realParent.getPatternFacets());
          } // endif
        } else if (facet instanceof XSDEnumerationFacet) {
          XSDEnumerationFacet ef = (XSDEnumerationFacet) facet;
          XSDSimpleTypeDefinition realParent = (XSDSimpleTypeDefinition) ef.getContainer();
          // only add enums if they belong to this type:
          if (realParent == type) {
            rv.addAll(realParent.getEnumerationFacets());
          } // endif
        } // endif -- which kind of repeatable?
      } else {
        rv.add(facet);
      } // endif -- fake facet
    } // endwhile -- facets

    return rv;
  }
Ejemplo n.º 2
0
  protected void processTypeFacets(
      XSDSimpleTypeDefinition type, Node typeNode, XSDTypeDefinition baseType)
      throws RepositoryException {
    if (baseType == null) {
      baseType = type.getBaseType();
    }
    if (baseType == type) {
      // The base type is the anytype ...
      baseType =
          type.getSchema()
              .getSchemaForSchema()
              .resolveSimpleTypeDefinition("http://www.w3.org/2001/XMLSchema", "anyType");
    }
    if (baseType != null) {
      typeNode.setProperty(XsdLexicon.BASE_TYPE_NAME, baseType.getName());
      typeNode.setProperty(XsdLexicon.BASE_TYPE_NAMESPACE, baseType.getTargetNamespace());
      setReference(
          typeNode,
          XsdLexicon.BASE_TYPE_REFERENCE,
          TYPE_DEFINITIONS,
          baseType.getTargetNamespace(),
          baseType.getName());
    }

    processFacet(
        type.getEffectiveMaxLengthFacet(), typeNode, XsdLexicon.MAX_LENGTH, PropertyType.LONG);
    processFacet(type.getMaxLengthFacet(), typeNode, XsdLexicon.MAX_LENGTH, PropertyType.LONG);
    processFacet(
        type.getEffectiveMinLengthFacet(), typeNode, XsdLexicon.MIN_LENGTH, PropertyType.LONG);
    processFacet(type.getMinLengthFacet(), typeNode, XsdLexicon.MIN_LENGTH, PropertyType.LONG);
    processFacet(
        type.getEffectiveMaxFacet(), typeNode, XsdLexicon.MAX_VALUE_EXCLUSIVE, PropertyType.LONG);
    processFacet(
        type.getMaxExclusiveFacet(), typeNode, XsdLexicon.MAX_VALUE_EXCLUSIVE, PropertyType.LONG);
    processFacet(
        type.getEffectiveMinFacet(), typeNode, XsdLexicon.MIN_VALUE_EXCLUSIVE, PropertyType.LONG);
    processFacet(
        type.getMinExclusiveFacet(), typeNode, XsdLexicon.MIN_VALUE_EXCLUSIVE, PropertyType.LONG);
    processFacet(
        type.getMaxInclusiveFacet(), typeNode, XsdLexicon.MAX_VALUE_INCLUSIVE, PropertyType.LONG);
    processFacet(
        type.getMinInclusiveFacet(), typeNode, XsdLexicon.MIN_VALUE_INCLUSIVE, PropertyType.LONG);
    processFacet(
        type.getEffectiveTotalDigitsFacet(), typeNode, XsdLexicon.TOTAL_DIGITS, PropertyType.LONG);
    processFacet(type.getTotalDigitsFacet(), typeNode, XsdLexicon.TOTAL_DIGITS, PropertyType.LONG);
    processFacet(
        type.getEffectiveFractionDigitsFacet(),
        typeNode,
        XsdLexicon.FRACTION_DIGITS,
        PropertyType.LONG);
    processFacet(
        type.getFractionDigitsFacet(), typeNode, XsdLexicon.FRACTION_DIGITS, PropertyType.LONG);

    processFacet(
        type.getEffectiveWhiteSpaceFacet(), typeNode, XsdLexicon.WHITESPACE, PropertyType.STRING);
    processFacet(type.getWhiteSpaceFacet(), typeNode, XsdLexicon.WHITESPACE, PropertyType.STRING);

    processFacet(
        type.getEffectivePatternFacet(), typeNode, XsdLexicon.PATTERN, PropertyType.STRING);
    @SuppressWarnings("unchecked")
    List<XSDPatternFacet> patternFacets = type.getPatternFacets();
    processFacetsList(patternFacets, typeNode, XsdLexicon.PATTERN);

    processFacet(
        type.getEffectiveEnumerationFacet(),
        typeNode,
        XsdLexicon.ENUMERATED_VALUES,
        PropertyType.STRING);
    @SuppressWarnings("unchecked")
    List<XSDEnumerationFacet> enumFacets = type.getEnumerationFacets();
    processFacetsList(enumFacets, typeNode, XsdLexicon.ENUMERATED_VALUES);

    @SuppressWarnings("unchecked")
    List<XSDSimpleFinal> finalFacets2 = type.getFinal();
    processEnumerators(finalFacets2, typeNode, XsdLexicon.FINAL);

    processAnnotation(type.getAnnotation(), typeNode);
  }