コード例 #1
0
ファイル: XSDUtils.java プロジェクト: ww102111/tools
  /**
   * Return the base type from which this type inherits - that is, all xsd types are either
   * xsd:anyType or xsd:anySimpleType at the topmost level of inheritance, so return the second
   * topmost level of type's inheritance. The first specific type from which type inherits.
   *
   * @param type
   * @return the root type definition
   */
  public static XSDTypeDefinition getRootType(XSDTypeDefinition type) {
    if (type == null) return null;

    XSDTypeDefinition baseType = type.getBaseType();
    while (baseType != null
        && !XSDConstants.isAnySimpleType(baseType)
        && !XSDConstants.isAnyType(baseType)) {
      // walk one more step up the hierarchy
      type = baseType;
      baseType = type.getBaseType();
    }

    // Since baseType, type's immediate parent, broke the while condition, we know that type is now
    // as high up the tree as we want to be
    return type;
  }
コード例 #2
0
ファイル: XSDUtils.java プロジェクト: ww102111/tools
  /**
   * Return a collection of all types referenced by the attributes (XSDFeatures) of source. This
   * method is non-recursive (i.e. the list only contains direct references, not
   * references-of-references) Will not return null, but may return an empty set. This will not
   * return a BO reference if the file has been deleted (or just doesn't exist).
   *
   * @param source The complex type to examine for references
   * @return a Collection of XSDComplexTypeDefinition instances -- no duplicates
   */
  public static Collection<XSDTypeDefinition> getReferencedTypes(XSDComplexTypeDefinition source) {

    if (source == null) {
      return Collections.emptySet();
    }

    List<XSDTypeDefinition> results = new ArrayList<XSDTypeDefinition>();
    XSDFeature element = null;
    XSDComplexTypeDefinition elementType = null;
    for (Iterator<XSDParticleContent> i = getChildElements(source).iterator(); i.hasNext(); ) {
      element = (XSDFeature) i.next();
      elementType = getResolvedComplexType(element);
      if (elementType != null
          && !results.contains(elementType)
          && !XSDConstants.isSchemaForSchemaNamespace(elementType.getTargetNamespace()))
        results.add(elementType);
    }
    return results;
  }
コード例 #3
0
ファイル: XSDUtils.java プロジェクト: ww102111/tools
  /**
   * Return a collection of all types referenced by the attributes (XSDFeatures) of source. This
   * method is non-recursive (i.e. the list only contains direct references, not
   * references-of-references) Will not return null, but may return an empty set. This will return a
   * BO reference if the file has been deleted (or just doesn't exist).
   *
   * @param source The complex type to examine for references
   * @param includeAnonymous if true, the returned list will include anonymous inlined types as
   *     well. These are not technically "referenced", however it allows this method to be used as a
   *     way to get all non-primitive types used in any way by source
   * @return a Collection of XSDTypeDefinition (could be complex or simple type) instances -- no
   *     duplicates
   */
  public static Collection<XSDTypeDefinition> getAllReferencedTypes(
      XSDComplexTypeDefinition source, boolean includeAnonymous) {
    if (source == null) {
      return Collections.emptySet();
    }

    List<XSDTypeDefinition> results = new ArrayList<XSDTypeDefinition>();
    XSDTypeDefinition elementType = null;
    for (Iterator<XSDParticleContent> i = getChildElements(source).iterator(); i.hasNext(); ) {
      XSDFeature next = (XSDFeature) i.next();
      elementType = getResolvedType(next);

      // Only add non-null, non-duplicate, non-primitive types.  If includeAnonymous is false,
      // anonymous types should be filtered out as well
      if (elementType != null
          && !results.contains(elementType)
          && !XSDConstants.isSchemaForSchemaNamespace(elementType.getTargetNamespace())
          && (includeAnonymous || elementType.eContainer() != next)) {
        results.add(elementType);
      }
    }
    return results;
  }