Example #1
0
  /**
   * 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;
  }