## org.eclipse.xsd.util
Class XSDSchemaQueryTools

    java.lang.Object
      org.eclipse.xsd.util.XSDSchemaQueryTools

    public abstract class XSDSchemaQueryTools

extends java.lang.Object

XSDSchemaQueryTools is a collection of worker methods for performing simple queries or searches of schemas.

These are suitable to show examples of how to build convenience methods to more easily find components in a schema. They also serve as useful examples of usage of the library's functions.

Note that these methods are somewhat simplistic, especially in terms of support for namespaces. To simplify the calling signatures, and to account for the 80% case where you don't have multiple namespaces, most method simply take a localName that's assumed to be correct in the current context. However it should be simple to copy & paste these methods and add namespaceURI's to each method if desired.

Constructor Summary
`XSDSchemaQueryTools()`

Method Summary
`static java.util.List<XSDElementDeclaration>` `findElementsUsingType(XSDSchema schema, java.lang.String namespace, java.lang.String localName)` Find elementDeclarations that use any types derived from a named type.
`static java.util.List<XSDTypeDefinition>` `findTypesDerivedFrom(XSDSchema schema, java.lang.String namespace, java.lang.String localName)` Find typeDefinitions that derive from a named type.
`static java.util.HashMap<java.lang.String,java.lang.String>` `hasImpInclRedef(XSDSchema schema)` Find any included, imported, or redefined schemas that this one references.
`static java.util.HashMap<java.lang.String,java.lang.String>` `hasImpInclRedef2(XSDSchema schema)` Find any included, imported, or redefined schemas that this one references.
`static boolean` `isTypeDerivedFrom(XSDTypeDefinition typedef, java.lang.String namespace, java.lang.String localName)` Deprecated. Use `XSDConstants.isOrIsDerivedFrom(XSDTypeDefinition, String, String)` instead.
`protected static void` `mapImpInclRedef(XSDSchema schema, java.util.HashMap<java.lang.String,java.lang.String> hash, int level)` Recursive worker method implementing `hasImpInclRedef(XSDSchema)` and `hasImpInclRedef2(XSDSchema)`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### XSDSchemaQueryTools

    public XSDSchemaQueryTools()

Method Detail

### findTypesDerivedFrom

    public static java.util.List<XSDTypeDefinition> findTypesDerivedFrom(XSDSchema schema,
                                                                         java.lang.String namespace,
                                                                         java.lang.String localName)

  Find typeDefinitions that derive from a named type.

  This shows one way to query the schema for typeDefinitions and then how to find specific kinds of typeDefinitions.

  Parameters:
    `schema` - to search for typeDefs
    `namespace` - for the type derived from
    `localName` - for the type derived from
  Returns:
    List of any XSDTypeDefinitions found

### isTypeDerivedFrom

    @Deprecated
    public static boolean isTypeDerivedFrom(XSDTypeDefinition typedef,
                                                       java.lang.String namespace,
                                                       java.lang.String localName)

  Deprecated. Use `XSDConstants.isOrIsDerivedFrom(XSDTypeDefinition, String, String)` instead.

  Recursive worker method to find typeDefinitions that derive from a named type.

  This is not a terribly time-efficient algorithm, but it does show usage of library methods. This works for simpleTypes; complexType support needs to be added.

  Parameters:
    `typedef` - to see if it's derived from
    `namespace` - for the type derived from
    `localName` - for the type derived from
  Returns:
    true if it is; false otherwise
  See Also:
    `findTypesDerivedFrom(XSDSchema, String, String)`

### findElementsUsingType

    public static java.util.List<XSDElementDeclaration> findElementsUsingType(XSDSchema schema,
                                                                              java.lang.String namespace,
                                                                              java.lang.String localName)

  Find elementDeclarations that use any types derived from a named type.

  This shows one way to query the schema for elementDeclarations and then how to find specific kinds of typeDefinitions.

  Parameters:
    `schema` - to search for elemDecls
    `namespace` - for the type used
    `localName` - for the type used
  Returns:
    List of any XSDElementDeclarations found

### hasImpInclRedef

    public static java.util.HashMap<java.lang.String,java.lang.String> hasImpInclRedef(XSDSchema schema)

  Find any included, imported, or redefined schemas that this one references.

  This method uses solely the Schema model API to look for XSDSchemaDirective objects. Each directive is the result of an include, import, or redefine in our schema. We then walk the tree of directives, finding their resolved schemas (if available), and produce a simple HashMap of them all.

  See also `hasImpInclRedef2(XSDSchema)` which uses the underlying ResourceSet model to query the external resources that were loaded with this schema: it has the same effect, but using different code.

  Parameters:
    `schema` - object to search for imports/includes/redefines
  Returns:
    HashMap where keys are the URI's of any other schemas found, and values are one of 'import', 'include', 'redefine'; null if none found or an error occurred
  See Also:
    `hasImpInclRedef2(XSDSchema)`

### hasImpInclRedef2

    public static java.util.HashMap<java.lang.String,java.lang.String> hasImpInclRedef2(XSDSchema schema)

  Find any included, imported, or redefined schemas that this one references.

  This method uses the underlying ResourceSet model to query the external resources that were loaded with this schema. Note that the ResourceSet implementation is subject to change.

  Parameters:
    `schema` - object to search for imports/includes/redefines
  Returns:
    HashMap where keys are the URI's of any other schemas found, and values are one of 'import', 'include', 'redefine'; null if none found or an error occurred
  See Also:
    `hasImpInclRedef(XSDSchema)`

### mapImpInclRedef

    protected static void mapImpInclRedef(XSDSchema schema,
                                          java.util.HashMap<java.lang.String,java.lang.String> hash,
                                          int level)

  Recursive worker method implementing `hasImpInclRedef(XSDSchema)` and `hasImpInclRedef2(XSDSchema)`.

  This uses only the schema model library API's to look for XSDSchemaDirective objects in it's content. It then checks which specific subclass of directive each is to report and then recurses to any other schemas found.

  Parameters:
    `schema` - object to search for imports/includes/redefines
    `hash` - where keys are the URI's of any other schemas found, and values are one of 'import', 'include', 'redefine'; this object is mutated by this method
    `level` - of iteration we're on

Copyright 2001-2006 IBM Corporation and others. All Rights Reserved.