org.deegree.commons.xml.schema
Class XMLSchemaInfoSet

java.lang.Object
  extended by org.deegree.commons.xml.schema.XMLSchemaInfoSet
Direct Known Subclasses:
GMLSchemaInfoSet

public class XMLSchemaInfoSet
extends Object

Provides convenient methods to retrieve "relevant" element and type declarations of an XML schema infoset.

This functionality is very handy for extracting higher-level structures defined using XML schema, such as GML feature types.

Version:
$Revision:$, $Date:$
Author:
Markus Schneider , last edited by: $Author:$
See Also:
GMLSchemaInfoSet

Field Summary
protected  org.apache.xerces.xs.XSModel xsModel
          The Xerces schema model.
 
Constructor Summary
XMLSchemaInfoSet(LSInput... inputs)
          Creates a new XMLSchemaInfoSet instance that reads the schema documents from the given inputs.
XMLSchemaInfoSet(String... schemaUrls)
          Creates a new XMLSchemaInfoSet instance that reads the schema documents from the given URLs.
XMLSchemaInfoSet(org.apache.xerces.xs.XSModel xmlSchema)
          Creates a new XSModelAnalyzer for the given (Xerces) XML schema infoset.
 
Method Summary
 List<String> getComponentLocations(String namespace)
          Returns the locations of all schema files that contributed to the given namespace.
 org.apache.xerces.xs.XSElementDeclaration getElementDecl(QName name)
          Returns the global element declaration with the given name.
 org.apache.xerces.xs.XSElementDeclaration getElementDecl(String localName, String namespace)
           
 Map<String,String> getNamespacePrefixes()
          Returns the prefix to namespace bindings used in the original XML schema documents.
 org.apache.xerces.xs.XSNamespaceItemList getNamespaces()
           
 Set<String> getSchemaNamespaces()
          Returns all namespaces that participate in this infoset.
 List<org.apache.xerces.xs.XSElementDeclaration> getSubstitutions(QName elementName, String namespace, boolean transitive, boolean onlyConcrete)
          Returns the declarations of all elements that are substitutable for a given element name.
 List<org.apache.xerces.xs.XSElementDeclaration> getSubstitutions(org.apache.xerces.xs.XSElementDeclaration elementDecl, String namespace, boolean transitive, boolean onlyConcrete)
          Returns the declarations of all elements that are substitutable for a given element declaration.
 List<org.apache.xerces.xs.XSTypeDefinition> getSubtypes(org.apache.xerces.xs.XSTypeDefinition typeDef, String namespace, boolean transitive, boolean onlyConcrete)
          Returns the subtypes for the given type definition.
 org.apache.xerces.xs.XSTypeDefinition getTypeDef(QName name)
           
 org.apache.xerces.xs.XSTypeDefinition getTypeDef(String localName, String namespace)
           
 org.apache.xerces.xs.XSModel getXSModel()
          Returns the XML schema infoset (represented as a Xerces XSModel).
static org.apache.xerces.xs.XSModel loadModel(LSInput... inputs)
          Creates a Xerces XSModel from the given input schemas, using the RedirectingEntityResolver, so OGC schemas URLs are redirected to a local copy.
static org.apache.xerces.xs.XSModel loadModel(String... schemaUrls)
          Creates a Xerces XSModel from the schemas at the given URLs, using the RedirectingEntityResolver, so OGC schemas URLs are redirected to a local copy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xsModel

protected final org.apache.xerces.xs.XSModel xsModel
The Xerces schema model.

Constructor Detail

XMLSchemaInfoSet

public XMLSchemaInfoSet(org.apache.xerces.xs.XSModel xmlSchema)
Creates a new XSModelAnalyzer for the given (Xerces) XML schema infoset.

Parameters:
xmlSchema - schema infoset, must not be null

XMLSchemaInfoSet

public XMLSchemaInfoSet(String... schemaUrls)
                 throws ClassCastException,
                        ClassNotFoundException,
                        InstantiationException,
                        IllegalAccessException
Creates a new XMLSchemaInfoSet instance that reads the schema documents from the given URLs.

Parameters:
schemaUrls - locations of the schema documents, must not be null and contain at least one entry
Throws:
ClassCastException
ClassNotFoundException
InstantiationException
IllegalAccessException

XMLSchemaInfoSet

public XMLSchemaInfoSet(LSInput... inputs)
                 throws ClassCastException,
                        ClassNotFoundException,
                        InstantiationException,
                        IllegalAccessException
Creates a new XMLSchemaInfoSet instance that reads the schema documents from the given inputs.

Parameters:
inputs - schema documents, must not be null and contain at least one entry
Throws:
ClassCastException
ClassNotFoundException
InstantiationException
IllegalAccessException
Method Detail

getElementDecl

public org.apache.xerces.xs.XSElementDeclaration getElementDecl(QName name)
Returns the global element declaration with the given name.

NOTE: Use this method instead of XSModel#getElementDeclaration(...) -- sometimes this convenience method returns null for element declarations that definitely exist (observed for XPlanGML 4.0 schemas with ADE).

Parameters:
name - qualified name, must not be null
Returns:
the global element declaration or null if it does not exist

getElementDecl

public org.apache.xerces.xs.XSElementDeclaration getElementDecl(String localName,
                                                                String namespace)

getTypeDef

public org.apache.xerces.xs.XSTypeDefinition getTypeDef(QName name)

getTypeDef

public org.apache.xerces.xs.XSTypeDefinition getTypeDef(String localName,
                                                        String namespace)

getSchemaNamespaces

public Set<String> getSchemaNamespaces()
Returns all namespaces that participate in this infoset.

Returns:
all namespaces, never null

getNamespacePrefixes

public Map<String,String> getNamespacePrefixes()
Returns the prefix to namespace bindings used in the original XML schema documents.

Returns:
the prefix to namespace bindings, never null (but does not necessarily contain bindings for all namespaces)

getComponentLocations

public List<String> getComponentLocations(String namespace)
Returns the locations of all schema files that contributed to the given namespace.

Parameters:
namespace - namespace, must not be null
Returns:
the locations of the schema files, or null if the namespace does not belong to the schema

getNamespaces

public org.apache.xerces.xs.XSNamespaceItemList getNamespaces()
Returns:

getXSModel

public org.apache.xerces.xs.XSModel getXSModel()
Returns the XML schema infoset (represented as a Xerces XSModel).

Returns:
the XML schema infoset, never null

getSubstitutions

public List<org.apache.xerces.xs.XSElementDeclaration> getSubstitutions(org.apache.xerces.xs.XSElementDeclaration elementDecl,
                                                                        String namespace,
                                                                        boolean transitive,
                                                                        boolean onlyConcrete)
Returns the declarations of all elements that are substitutable for a given element declaration.

Parameters:
elementDecl - element declaration, must not be null
namespace - only element declarations in this namespace are returned, set to null for all namespaces
transitive - if true, also substitutions for substitutions (and so on) are included
onlyConcrete - if true, only concrete (non-abstract) declarations are returned
Returns:
the declarations of all substitution elements in the requested namespace

getSubtypes

public List<org.apache.xerces.xs.XSTypeDefinition> getSubtypes(org.apache.xerces.xs.XSTypeDefinition typeDef,
                                                               String namespace,
                                                               boolean transitive,
                                                               boolean onlyConcrete)
Returns the subtypes for the given type definition.

Parameters:
typeDef - type definition, must not be null
namespace - only type definitions in this namespace are returned, set to null for all namespaces
transitive - if true, also subtypes of subtypes (and so on) are included
onlyConcrete - if true, only concrete (non-abstract) definitions are returned
Returns:
the definition of all sub type definitions in the requested namespace

getSubstitutions

public List<org.apache.xerces.xs.XSElementDeclaration> getSubstitutions(QName elementName,
                                                                        String namespace,
                                                                        boolean transitive,
                                                                        boolean onlyConcrete)
Returns the declarations of all elements that are substitutable for a given element name.

Parameters:
elementName - qualified name of the element, must not be null
namespace - only element declarations in this namespace are returned, set to null for all namespaces
transitive - if true, also substitutions for substitutions (and so one) are included
onlyConcrete - if true, only concrete (non-abstract) declarations are returned
Returns:
the declarations of all substitution elements in the requested namespace

loadModel

public static org.apache.xerces.xs.XSModel loadModel(String... schemaUrls)
                                              throws ClassCastException,
                                                     ClassNotFoundException,
                                                     InstantiationException,
                                                     IllegalAccessException
Creates a Xerces XSModel from the schemas at the given URLs, using the RedirectingEntityResolver, so OGC schemas URLs are redirected to a local copy.

Parameters:
schemaUrls - locations of the schema documents, must not be null and contain at least one entry
Returns:
the XML schema infoset, never null
Throws:
ClassCastException
ClassNotFoundException
InstantiationException
IllegalAccessException

loadModel

public static org.apache.xerces.xs.XSModel loadModel(LSInput... inputs)
                                              throws ClassCastException,
                                                     ClassNotFoundException,
                                                     InstantiationException,
                                                     IllegalAccessException
Creates a Xerces XSModel from the given input schemas, using the RedirectingEntityResolver, so OGC schemas URLs are redirected to a local copy.

Parameters:
inputs - schema document inputs, must not be null and contain at least one entry
Returns:
the XML schema infoset, never null
Throws:
ClassCastException
ClassNotFoundException
InstantiationException
IllegalAccessException


Copyright © 2011. All Rights Reserved.