org.geotools.xml
Class Schemas

java.lang.Object
  extended by org.geotools.xml.Schemas

public class Schemas
extends java.lang.Object

Utility class for performing various opreations.

Author:
Justin Deoliveira, The Open Planning Project

Constructor Summary
Schemas()
           
 
Method Summary
static java.util.List findSchemaLocationResolvers(Configuration configuration)
          Finds all XSDSchemaLocationResolver's used by the configuration.
static SchemaIndex findSchemas(Configuration configuration)
          Finds all the XSDSchemas used by the configuration by looking at the configuration's schema locator and its dependencies.
static java.util.List getAnyElementParticles(org.eclipse.xsd.XSDTypeDefinition type)
          Returns a list of all xs:any element particles that correspond to element declarations of the specified type.
static org.eclipse.xsd.XSDAttributeDeclaration getAttributeDeclaration(org.eclipse.xsd.XSDElementDeclaration element, javax.xml.namespace.QName qName)
          Returns an attribute declaration that is contained in the type of another element declaration.
static java.util.List getAttributeDeclarations(org.eclipse.xsd.XSDElementDeclaration element)
          Returns a list of all attribute declarations declared in the type (or any base type) of the specified element.
static java.util.List getAttributeDeclarations(org.eclipse.xsd.XSDTypeDefinition type)
          Returns a list of all attribute declarations declared in the type (or any base type) of the specified element.
static java.util.List getAttributeDeclarations(org.eclipse.xsd.XSDTypeDefinition type, boolean includeParents)
          Returns a list of all attribute declarations declared in the type (and optionally any base type) of the specified element.
static org.eclipse.xsd.XSDTypeDefinition getBaseTypeDefinition(org.eclipse.xsd.XSDTypeDefinition type, javax.xml.namespace.QName parentTypeName)
          Returns the base type defintion of type named parentTypeName.
static org.eclipse.xsd.XSDElementDeclaration getChildElementDeclaration(org.eclipse.xsd.XSDElementDeclaration parent, javax.xml.namespace.QName qName)
          Returns an element declaration that is contained in the type of another element declaration.
static java.util.List getChildElementDeclarations(org.eclipse.xsd.XSDElementDeclaration element)
          Deprecated. use getChildElementDeclarations(XSDTypeDefinition)
static java.util.List getChildElementDeclarations(org.eclipse.xsd.XSDElementDeclaration element, boolean includeParents)
          Deprecated. use getChildElementDeclarations(XSDTypeDefinition, boolean)
static java.util.List getChildElementDeclarations(org.eclipse.xsd.XSDTypeDefinition type)
          Returns a list of all child element declarations of the specified type, no order is guaranteed.
static java.util.List getChildElementDeclarations(org.eclipse.xsd.XSDTypeDefinition type, boolean includeParents)
          Returns a list of all child element declarations of the specified type, no order is guaranteed.
static org.eclipse.xsd.XSDParticle getChildElementParticle(org.eclipse.xsd.XSDTypeDefinition type, java.lang.String name, boolean includeParents)
          Returns the particle for an element declaration that is part of a type.
static java.util.List getChildElementParticles(org.eclipse.xsd.XSDTypeDefinition type, boolean includeParents)
          Returns a list of all child element particles that corresponde to element declarations of the specified type, no order is guaranteed.
static java.util.List getComponentInstancesOfType(org.picocontainer.PicoContainer container, java.lang.Class clazz)
          Obtains all instances of a particular class from a container by navigating up the container hierachy.
static java.util.List getDerivedElementDeclarations(org.eclipse.xsd.XSDElementDeclaration element)
          Returns a list of all top level elements that are of a type derived from the type of the specified element.
static org.eclipse.xsd.XSDElementDeclaration getElementDeclaration(org.eclipse.xsd.XSDSchema schema, javax.xml.namespace.QName name)
          Searches schema for an element which matches name.
static java.util.List getImports(org.eclipse.xsd.XSDSchema schema)
          Returns a flat list of imports from the specified schema.
static java.util.List getIncludes(org.eclipse.xsd.XSDSchema schema)
          Returns a flat list of includes from the specified schema.
static int getMaxOccurs(org.eclipse.xsd.XSDComplexTypeDefinition type, org.eclipse.xsd.XSDElementDeclaration element)
          Returns the minimum number of occurences of an element within a complex type.
static int getMinOccurs(org.eclipse.xsd.XSDComplexTypeDefinition type, org.eclipse.xsd.XSDElementDeclaration element)
          Returns the minimum number of occurences of an element within a complex type.
static javax.xml.namespace.QName getParticleName(org.eclipse.xsd.XSDParticle particle)
          Returns the name of the element represented by the particle as a QName.
static java.lang.String getTargetPrefix(org.eclipse.xsd.XSDSchema schema)
          Returns the namespace prefix mapped to the targetNamespace of the schema.
static void importSchema(org.eclipse.xsd.XSDSchema schema, org.eclipse.xsd.XSDSchema importee)
          Imports one schema into another.
static boolean isBaseType(org.eclipse.xsd.XSDElementDeclaration e1, org.eclipse.xsd.XSDElementDeclaration e2)
          Determines if the type of an element is a sub-type of another element.
static boolean nameMatches(org.eclipse.xsd.XSDNamedComponent component, javax.xml.namespace.QName qName)
          Method for comparing the name of a schema component to a qualified name.
static org.eclipse.xsd.XSDSchema parse(java.lang.String location)
          Parses a schema at the specified location.
static org.eclipse.xsd.XSDSchema parse(java.lang.String location, java.util.List locators, java.util.List resolvers)
           
static org.eclipse.xsd.XSDSchema parse(java.lang.String location, org.eclipse.xsd.util.XSDSchemaLocator[] locators, org.eclipse.xsd.util.XSDSchemaLocationResolver[] resolvers)
          Parses a schema at the specified location.
static void unregisterComponent(org.picocontainer.PicoContainer container, java.lang.Object key)
          Unregisters a component in the container and all parent containers.
static java.util.List validateImportsIncludes(java.lang.String location)
           
static java.util.List validateImportsIncludes(java.lang.String location, java.util.List locators, java.util.List resolvers)
           
static java.util.List validateImportsIncludes(java.lang.String location, org.eclipse.xsd.util.XSDSchemaLocator[] locators, org.eclipse.xsd.util.XSDSchemaLocationResolver[] resolvers)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Schemas

public Schemas()
Method Detail

findSchemas

public static final SchemaIndex findSchemas(Configuration configuration)
Finds all the XSDSchemas used by the configuration by looking at the configuration's schema locator and its dependencies.

Parameters:
configuration - the Configuration for which to find all its related schemas
Returns:
a SchemaIndex holding the schemas related to configuration

findSchemaLocationResolvers

public static java.util.List findSchemaLocationResolvers(Configuration configuration)
Finds all XSDSchemaLocationResolver's used by the configuration.

Parameters:
configuration - The parser configuration.
Returns:
A list of location resolvers, empty if none found.

parse

public static final org.eclipse.xsd.XSDSchema parse(java.lang.String location)
                                             throws java.io.IOException
Parses a schema at the specified location.

Parameters:
location - A uri pointing to the location of the schema.
Returns:
The parsed schema, or null if the schema could not be parsed.
Throws:
java.io.IOException - In the event of a schema parsing error.

parse

public static final org.eclipse.xsd.XSDSchema parse(java.lang.String location,
                                                    org.eclipse.xsd.util.XSDSchemaLocator[] locators,
                                                    org.eclipse.xsd.util.XSDSchemaLocationResolver[] resolvers)
                                             throws java.io.IOException
Parses a schema at the specified location.

Parameters:
location - A uri pointing to the location of the schema.
locators - An array of schema locator objects to be used when parsing imports/includes of the main schema.
resolvers - An array of schema location resolvers used to override schema locations encountered in an instance document or an imported schema.
Returns:
The parsed schema, or null if the schema could not be parsed.
Throws:
java.io.IOException - In the event of a schema parsing error.

parse

public static final org.eclipse.xsd.XSDSchema parse(java.lang.String location,
                                                    java.util.List locators,
                                                    java.util.List resolvers)
                                             throws java.io.IOException
Throws:
java.io.IOException

importSchema

public static final void importSchema(org.eclipse.xsd.XSDSchema schema,
                                      org.eclipse.xsd.XSDSchema importee)
                               throws java.io.IOException
Imports one schema into another.

Parameters:
schema - The schema being imported into.
importee - The schema being imported.
Throws:
java.io.IOException

validateImportsIncludes

public static final java.util.List validateImportsIncludes(java.lang.String location)
                                                    throws java.io.IOException
Throws:
java.io.IOException

validateImportsIncludes

public static final java.util.List validateImportsIncludes(java.lang.String location,
                                                           org.eclipse.xsd.util.XSDSchemaLocator[] locators,
                                                           org.eclipse.xsd.util.XSDSchemaLocationResolver[] resolvers)
                                                    throws java.io.IOException
Throws:
java.io.IOException

validateImportsIncludes

public static final java.util.List validateImportsIncludes(java.lang.String location,
                                                           java.util.List locators,
                                                           java.util.List resolvers)
                                                    throws java.io.IOException
Throws:
java.io.IOException

getChildElementDeclarations

public static final java.util.List getChildElementDeclarations(org.eclipse.xsd.XSDElementDeclaration element)
Deprecated. use getChildElementDeclarations(XSDTypeDefinition)

Returns a list of all child element declarations of the specified element, no order is guaranteed.

Parameters:
element - The parent element.
Returns:
A list of @link XSDElementDeclaration objects, one for each child element.

getChildElementDeclarations

public static final java.util.List getChildElementDeclarations(org.eclipse.xsd.XSDTypeDefinition type)
Returns a list of all child element declarations of the specified type, no order is guaranteed.

Parameters:
type - The type.
Returns:
A list of @link XSDElementDeclaration objects, one for each child element.

getChildElementDeclarations

public static final java.util.List getChildElementDeclarations(org.eclipse.xsd.XSDElementDeclaration element,
                                                               boolean includeParents)
Deprecated. use getChildElementDeclarations(XSDTypeDefinition, boolean)

Returns a list of all child element declarations of the specified element.

The includeParents flag controls if this method should returns those elements defined on parent types.

Parameters:
element - The parent element.
includeParents - Flag indicating if parent types should be processed.
Returns:
A list of @link XSDElementDeclaration objects, one for each child element.

getChildElementParticle

public static final org.eclipse.xsd.XSDParticle getChildElementParticle(org.eclipse.xsd.XSDTypeDefinition type,
                                                                        java.lang.String name,
                                                                        boolean includeParents)
Returns the particle for an element declaration that is part of a type.

Parameters:
type - The type definition.
name - The naem of the child element declaration.
includeParents - Flag to control wether parent types are included.
Returns:
The particle representing the element declaration, or null if it could not be found.

getChildElementParticles

public static final java.util.List getChildElementParticles(org.eclipse.xsd.XSDTypeDefinition type,
                                                            boolean includeParents)
Returns a list of all child element particles that corresponde to element declarations of the specified type, no order is guaranteed.

The includeParents flag controls if this method should returns those elements defined on parent types.

Parameters:
type - THe type.
includeParents - flag indicating if parent types should be processed
Returns:
A list of XSDParticle.

getAnyElementParticles

public static final java.util.List getAnyElementParticles(org.eclipse.xsd.XSDTypeDefinition type)
Returns a list of all xs:any element particles that correspond to element declarations of the specified type.

Parameters:
type - The type.
Returns:
A list of XSDParticle.

getChildElementDeclarations

public static final java.util.List getChildElementDeclarations(org.eclipse.xsd.XSDTypeDefinition type,
                                                               boolean includeParents)
Returns a list of all child element declarations of the specified type, no order is guaranteed.

The includeParents flag controls if this method should returns those elements defined on parent types.

Parameters:
type - The type
includeParents - flag indicating if parent types should be processed
Returns:
A list of @link XSDElementDeclaration objects, one for each child element.

getBaseTypeDefinition

public static final org.eclipse.xsd.XSDTypeDefinition getBaseTypeDefinition(org.eclipse.xsd.XSDTypeDefinition type,
                                                                            javax.xml.namespace.QName parentTypeName)
Returns the base type defintion of type named parentTypeName.

This method will handle the case in which the parentTypeName == type.getTypeName(). If no such parent type is found this method will return null.

Parameters:
type - The type.
parentTypeName - The name of the base type to return.
Returns:
The base type, or null if it could not be found.

isBaseType

public static final boolean isBaseType(org.eclipse.xsd.XSDElementDeclaration e1,
                                       org.eclipse.xsd.XSDElementDeclaration e2)
Determines if the type of an element is a sub-type of another element.

Parameters:
e1 - The element.
e2 - The element to be tested as a base type.
Since:
2.5

getMinOccurs

public static final int getMinOccurs(org.eclipse.xsd.XSDComplexTypeDefinition type,
                                     org.eclipse.xsd.XSDElementDeclaration element)
Returns the minimum number of occurences of an element within a complex type.

Parameters:
type - The type definition containg the declaration element
element - The declaration of the element.
Returns:
The minimum number of occurences.
Throws:
java.lang.IllegalArgumentException - If the element declaration cannot be locaated withing the type definition.

getMaxOccurs

public static final int getMaxOccurs(org.eclipse.xsd.XSDComplexTypeDefinition type,
                                     org.eclipse.xsd.XSDElementDeclaration element)
Returns the minimum number of occurences of an element within a complex type.

Parameters:
type - The type definition containg the declaration element
element - The declaration of the element.
Returns:
The minimum number of occurences.
Throws:
java.lang.IllegalArgumentException - If the element declaration cannot be locaated withing the type definition.

getChildElementDeclaration

public static final org.eclipse.xsd.XSDElementDeclaration getChildElementDeclaration(org.eclipse.xsd.XSDElementDeclaration parent,
                                                                                     javax.xml.namespace.QName qName)
Returns an element declaration that is contained in the type of another element declaration. The following strategy is used to locate the child element declaration.
  1. The immediate children of the specified element are examined, if a match is found, it is returned.
  2. If 1. does not match, global elements that derive from the immediate children are examined.

Parameters:
parent - the containing element declaration
qName - the qualified name of the contained element
Returns:
The contained element declaration, or false if containment is not satisfied.

getDerivedElementDeclarations

public static final java.util.List getDerivedElementDeclarations(org.eclipse.xsd.XSDElementDeclaration element)
Returns a list of all top level elements that are of a type derived from the type of the specified element.

Parameters:
element - The element.
Returns:
All elements which are of a type derived from the type of the specified element.

getAttributeDeclarations

public static final java.util.List getAttributeDeclarations(org.eclipse.xsd.XSDElementDeclaration element)
Returns a list of all attribute declarations declared in the type (or any base type) of the specified element.

This method is just a shortcut for getAttributeDeclarations(element.getType()

Parameters:
element - The element.
Returns:
A list of @link XSDAttributeDeclaration objects, one for each attribute of the element.

getAttributeDeclarations

public static final java.util.List getAttributeDeclarations(org.eclipse.xsd.XSDTypeDefinition type)
Returns a list of all attribute declarations declared in the type (or any base type) of the specified element.

Parameters:
element - The element.
Returns:
A list of @link XSDAttributeDeclaration objects, one for each attribute of the element.

getAttributeDeclarations

public static final java.util.List getAttributeDeclarations(org.eclipse.xsd.XSDTypeDefinition type,
                                                            boolean includeParents)
Returns a list of all attribute declarations declared in the type (and optionally any base type) of the specified element.

Parameters:
element - The element.
includeParents - Wether to include parent types.
Returns:
A list of @link XSDAttributeDeclaration objects, one for each attribute of the element.

getAttributeDeclaration

public static final org.eclipse.xsd.XSDAttributeDeclaration getAttributeDeclaration(org.eclipse.xsd.XSDElementDeclaration element,
                                                                                    javax.xml.namespace.QName qName)
Returns an attribute declaration that is contained in the type of another element declaration.

Parameters:
element - The containing element declaration.
qName - The qualified name of the contained attribute
Returns:
The contained attribute declaration, or false if containment is not satisfied.

getImports

public static final java.util.List getImports(org.eclipse.xsd.XSDSchema schema)
Returns a flat list of imports from the specified schema.

The method recurses into imported schemas. The list returned is filtered so that duplicate includes are removed. Two includes are considered equal if they have the same target namespace.

Parameters:
schema - The top-level schema.
Returns:
A list containing objects of type XSDImport.

getIncludes

public static final java.util.List getIncludes(org.eclipse.xsd.XSDSchema schema)
Returns a flat list of includes from the specified schema.

The method recurses into included schemas. The list returned is filtered so that duplicate includes are removed. Two includes are considered equal if they have the same uri location

Parameters:
schema - The top-level schema.
Returns:
A list containing objects of type XSDInclude.

getElementDeclaration

public static org.eclipse.xsd.XSDElementDeclaration getElementDeclaration(org.eclipse.xsd.XSDSchema schema,
                                                                          javax.xml.namespace.QName name)
Searches schema for an element which matches name.

Parameters:
schema - The schema
name - The element to search for
Returns:
The element declaration, or null if it could not be found.

nameMatches

public static final boolean nameMatches(org.eclipse.xsd.XSDNamedComponent component,
                                        javax.xml.namespace.QName qName)
Method for comparing the name of a schema component to a qualified name. The component name and the qualified name match if both the namespaces match, and the local parts match. Prefixes are ignored. Two strings will match if one of the following conditions hold.
  • Both strings are null.
  • Both strings are the empty string.
  • One string is null, and the other is the empty string.
  • Both strings are non-null and non-empty and equals() return true.

Parameters:
component - The component in question.
qName - The qualifined name.

getTargetPrefix

public static java.lang.String getTargetPrefix(org.eclipse.xsd.XSDSchema schema)
Returns the namespace prefix mapped to the targetNamespace of the schema.

Parameters:
schema - The schema in question.
Returns:
The namesapce prefix, or null if not found.

getComponentInstancesOfType

public static java.util.List getComponentInstancesOfType(org.picocontainer.PicoContainer container,
                                                         java.lang.Class clazz)
Obtains all instances of a particular class from a container by navigating up the container hierachy.

Parameters:
container - The container.
clazz - The class.
Returns:
A list of all instances of clazz, or the empty list if none found.

unregisterComponent

public static void unregisterComponent(org.picocontainer.PicoContainer container,
                                       java.lang.Object key)
Unregisters a component in the container and all parent containers.

Parameters:
container - The container.
key - The key of the component.

getParticleName

public static javax.xml.namespace.QName getParticleName(org.eclipse.xsd.XSDParticle particle)
Returns the name of the element represented by the particle as a QName.



Copyright © 1996-2010 Geotools. All Rights Reserved.