org.apache.xerces.impl.xs
Class XMLSchemaLoader

java.lang.Object
  extended by org.apache.xerces.impl.xs.XMLSchemaLoader
All Implemented Interfaces:
XMLGrammarLoader, XMLComponent, XSLoader, DOMConfiguration

public class XMLSchemaLoader
extends java.lang.Object
implements XMLGrammarLoader, XMLComponent, XSLoader, DOMConfiguration

This class implements xni.grammars.XMLGrammarLoader. It also serves as implementation of xs.XSLoader interface and DOMConfiguration interface. This class is designed to interact either with a proxy for a user application which wants to preparse schemas, or with our own Schema validator. It is hoped that none of these "external" classes will therefore need to communicate directly with XSDHandler in future.

This class only knows how to make XSDHandler do its thing. The caller must ensure that all its properties (schemaLocation, JAXPSchemaSource etc.) have been properly set.

Version:
$Id: XMLSchemaLoader.java 521495 2007-03-22 22:12:05Z mrglavas $
Author:
Neil Graham, IBM

Field Summary
static java.lang.String ENTITY_RESOLVER
          Property identifier: entity resolver.
static java.lang.String ERROR_REPORTER
          Property identifier: error reporter.
static java.lang.String SYMBOL_TABLE
          Property identifier: symbol table.
static java.lang.String XMLGRAMMAR_POOL
          Property identifier: grammar pool.
 
Constructor Summary
XMLSchemaLoader()
           
XMLSchemaLoader(SymbolTable symbolTable)
           
 
Method Summary
 boolean canSetParameter(java.lang.String name, java.lang.Object value)
          Check if setting a parameter to a specific value is supported.
 DOMConfiguration getConfig()
          The configuration of a document.
 XMLEntityResolver getEntityResolver()
          Returns the registered entity resolver.
 XMLErrorHandler getErrorHandler()
          Returns the registered error handler.
 boolean getFeature(java.lang.String featureId)
          Returns the state of a feature.
 java.lang.Boolean getFeatureDefault(java.lang.String featureId)
          Returns the default state for a feature, or null if this component does not want to report a default value for this feature.
 java.util.Locale getLocale()
          Return the Locale the XMLGrammarLoader is using.
 java.lang.Object getParameter(java.lang.String name)
          Return the value of a parameter if known.
 DOMStringList getParameterNames()
          The list of the parameters supported by this DOMConfiguration object and for which at least one value can be set by the application.
 java.lang.Object getProperty(java.lang.String propertyId)
          Returns the state of a property.
 java.lang.Object getPropertyDefault(java.lang.String propertyId)
          Returns the default state for a property, or null if this component does not want to report a default value for this property.
 java.lang.String[] getRecognizedFeatures()
          Returns a list of feature identifiers that are recognized by this XMLGrammarLoader.
 java.lang.String[] getRecognizedProperties()
          Returns a list of property identifiers that are recognized by this XMLGrammarLoader.
 XSModel load(LSInput is)
          Parse an XML Schema document from a resource identified by a LSInput .
 Grammar loadGrammar(XMLInputSource source)
          Returns a Grammar object by parsing the contents of the entity pointed to by source.
 void loadGrammar(XMLInputSource[] source)
          Returns a Grammar object by parsing the contents of the entities pointed to by sources.
 XSModel loadInputList(LSInputList is)
          Parses the content of XML Schema documents specified as a list of LSInputs.
 XSModel loadURI(java.lang.String uri)
          Parse an XML Schema document from a location identified by a URI reference.
 XSModel loadURIList(StringList uriList)
          Parses the content of XML Schema documents specified as the list of URI references.
static void processExternalHints(java.lang.String sl, java.lang.String nsl, java.util.Hashtable locations, XMLErrorReporter er)
           
 void reset(XMLComponentManager componentManager)
          Resets the component.
static XMLInputSource resolveDocument(XSDDescription desc, java.util.Hashtable locationPairs, XMLEntityResolver entityResolver)
          This method tries to resolve location of the given schema.
 void setEntityResolver(XMLEntityResolver entityResolver)
          Sets the entity resolver.
 void setErrorHandler(XMLErrorHandler errorHandler)
          Sets the error handler.
 void setFeature(java.lang.String featureId, boolean state)
          Sets the state of a feature.
 void setLocale(java.util.Locale locale)
          Set the locale to use for messages.
 void setParameter(java.lang.String name, java.lang.Object value)
          Set the value of a parameter.
 void setProperty(java.lang.String propertyId, java.lang.Object state)
          Sets the state of a property.
static boolean tokenizeSchemaLocationStr(java.lang.String schemaStr, java.util.Hashtable locations)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYMBOL_TABLE

public static final java.lang.String SYMBOL_TABLE
Property identifier: symbol table.

See Also:
Constant Field Values

ERROR_REPORTER

public static final java.lang.String ERROR_REPORTER
Property identifier: error reporter.

See Also:
Constant Field Values

ENTITY_RESOLVER

public static final java.lang.String ENTITY_RESOLVER
Property identifier: entity resolver.

See Also:
Constant Field Values

XMLGRAMMAR_POOL

public static final java.lang.String XMLGRAMMAR_POOL
Property identifier: grammar pool.

See Also:
Constant Field Values
Constructor Detail

XMLSchemaLoader

public XMLSchemaLoader()

XMLSchemaLoader

public XMLSchemaLoader(SymbolTable symbolTable)
Method Detail

getRecognizedFeatures

public java.lang.String[] getRecognizedFeatures()
Returns a list of feature identifiers that are recognized by this XMLGrammarLoader. This method may return null if no features are recognized.

Specified by:
getRecognizedFeatures in interface XMLGrammarLoader
Specified by:
getRecognizedFeatures in interface XMLComponent

getFeature

public boolean getFeature(java.lang.String featureId)
                   throws XMLConfigurationException
Returns the state of a feature.

Specified by:
getFeature in interface XMLGrammarLoader
Parameters:
featureId - The feature identifier.
Throws:
XMLConfigurationException - Thrown on configuration error.

setFeature

public void setFeature(java.lang.String featureId,
                       boolean state)
                throws XMLConfigurationException
Sets the state of a feature.

Specified by:
setFeature in interface XMLGrammarLoader
Specified by:
setFeature in interface XMLComponent
Parameters:
featureId - The feature identifier.
state - The state of the feature.
Throws:
XMLConfigurationException - Thrown when a feature is not recognized or cannot be set.

getRecognizedProperties

public java.lang.String[] getRecognizedProperties()
Returns a list of property identifiers that are recognized by this XMLGrammarLoader. This method may return null if no properties are recognized.

Specified by:
getRecognizedProperties in interface XMLGrammarLoader
Specified by:
getRecognizedProperties in interface XMLComponent

getProperty

public java.lang.Object getProperty(java.lang.String propertyId)
                             throws XMLConfigurationException
Returns the state of a property.

Specified by:
getProperty in interface XMLGrammarLoader
Parameters:
propertyId - The property identifier.
Throws:
XMLConfigurationException - Thrown on configuration error.

setProperty

public void setProperty(java.lang.String propertyId,
                        java.lang.Object state)
                 throws XMLConfigurationException
Sets the state of a property.

Specified by:
setProperty in interface XMLGrammarLoader
Specified by:
setProperty in interface XMLComponent
Parameters:
propertyId - The property identifier.
state - The state of the property.
Throws:
XMLConfigurationException - Thrown when a property is not recognized or cannot be set.

setLocale

public void setLocale(java.util.Locale locale)
Set the locale to use for messages.

Specified by:
setLocale in interface XMLGrammarLoader
Parameters:
locale - The locale object to use for localization of messages.
Throws:
XNIException - Thrown if the parser does not support the specified locale.

getLocale

public java.util.Locale getLocale()
Return the Locale the XMLGrammarLoader is using.

Specified by:
getLocale in interface XMLGrammarLoader

setErrorHandler

public void setErrorHandler(XMLErrorHandler errorHandler)
Sets the error handler.

Specified by:
setErrorHandler in interface XMLGrammarLoader
Parameters:
errorHandler - The error handler.

getErrorHandler

public XMLErrorHandler getErrorHandler()
Returns the registered error handler.

Specified by:
getErrorHandler in interface XMLGrammarLoader

setEntityResolver

public void setEntityResolver(XMLEntityResolver entityResolver)
Sets the entity resolver.

Specified by:
setEntityResolver in interface XMLGrammarLoader
Parameters:
entityResolver - The new entity resolver.

getEntityResolver

public XMLEntityResolver getEntityResolver()
Returns the registered entity resolver.

Specified by:
getEntityResolver in interface XMLGrammarLoader

loadGrammar

public void loadGrammar(XMLInputSource[] source)
                 throws java.io.IOException,
                        XNIException
Returns a Grammar object by parsing the contents of the entities pointed to by sources.

Parameters:
source - the locations of the entity which forms the staring point of the grammars to be constructed
Throws:
java.io.IOException - when a problem is encounted reading the entity
XNIException - when a condition arises (such as a FatalError) that requires parsing of the entity be terminated

loadGrammar

public Grammar loadGrammar(XMLInputSource source)
                    throws java.io.IOException,
                           XNIException
Returns a Grammar object by parsing the contents of the entity pointed to by source.

Specified by:
loadGrammar in interface XMLGrammarLoader
Parameters:
source - the location of the entity which forms the starting point of the grammar to be constructed.
Throws:
java.io.IOException - When a problem is encountered reading the entity XNIException When a condition arises (such as a FatalError) that requires parsing of the entity be terminated.
XNIException

resolveDocument

public static XMLInputSource resolveDocument(XSDDescription desc,
                                             java.util.Hashtable locationPairs,
                                             XMLEntityResolver entityResolver)
                                      throws java.io.IOException
This method tries to resolve location of the given schema. The loader stores the namespace/location pairs in a hashtable (use "" as the namespace of absent namespace). When resolving an entity, loader first tries to find in the hashtable whether there is a value for that namespace, if so, pass that location value to the user-defined entity resolver.

Parameters:
desc -
locationPairs -
entityResolver -
Returns:
the XMLInputSource
Throws:
java.io.IOException

processExternalHints

public static void processExternalHints(java.lang.String sl,
                                        java.lang.String nsl,
                                        java.util.Hashtable locations,
                                        XMLErrorReporter er)

tokenizeSchemaLocationStr

public static boolean tokenizeSchemaLocationStr(java.lang.String schemaStr,
                                                java.util.Hashtable locations)

getFeatureDefault

public java.lang.Boolean getFeatureDefault(java.lang.String featureId)
Description copied from interface: XMLComponent
Returns the default state for a feature, or null if this component does not want to report a default value for this feature.

Specified by:
getFeatureDefault in interface XMLComponent
Parameters:
featureId - The feature identifier.

getPropertyDefault

public java.lang.Object getPropertyDefault(java.lang.String propertyId)
Description copied from interface: XMLComponent
Returns the default state for a property, or null if this component does not want to report a default value for this property.

Specified by:
getPropertyDefault in interface XMLComponent
Parameters:
propertyId - The property identifier.

reset

public void reset(XMLComponentManager componentManager)
           throws XMLConfigurationException
Description copied from interface: XMLComponent
Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.

Specified by:
reset in interface XMLComponent
Parameters:
componentManager - The component manager.
Throws:
XMLConfigurationException

getConfig

public DOMConfiguration getConfig()
Description copied from interface: XSLoader
The configuration of a document. It maintains a table of recognized parameters. Using the configuration, it is possible to change the behavior of the load methods. The configuration may support the setting of and the retrieval of the following non-boolean parameters defined on the DOMConfiguration interface: error-handler (DOMErrorHandler) and resource-resolver (LSResourceResolver).
The following list of boolean parameters is defined:
"validate"
true
[required] (default) Validate an XML Schema during loading. If validation errors are found, the error handler is notified.
false
[optional] Do not report errors during the loading of an XML Schema document.

Specified by:
getConfig in interface XSLoader

load

public XSModel load(LSInput is)
Description copied from interface: XSLoader
Parse an XML Schema document from a resource identified by a LSInput .

Specified by:
load in interface XSLoader
Parameters:
is - The LSInput from which the source document is to be read.
Returns:
An XSModel representing this schema.

loadInputList

public XSModel loadInputList(LSInputList is)
Description copied from interface: XSLoader
Parses the content of XML Schema documents specified as a list of LSInputs.

Specified by:
loadInputList in interface XSLoader
Parameters:
is - The list of LSInputs from which the XML Schema documents are to be read.
Returns:
An XSModel representing the schema documents.

loadURI

public XSModel loadURI(java.lang.String uri)
Description copied from interface: XSLoader
Parse an XML Schema document from a location identified by a URI reference. If the URI contains a fragment identifier, the behavior is not defined by this specification.

Specified by:
loadURI in interface XSLoader
Parameters:
uri - The location of the XML Schema document to be read.
Returns:
An XSModel representing this schema.

loadURIList

public XSModel loadURIList(StringList uriList)
Description copied from interface: XSLoader
Parses the content of XML Schema documents specified as the list of URI references. If the URI contains a fragment identifier, the behavior is not defined by this specification.

Specified by:
loadURIList in interface XSLoader
Parameters:
uriList - The list of URI locations.
Returns:
An XSModel representing the schema documents.

canSetParameter

public boolean canSetParameter(java.lang.String name,
                               java.lang.Object value)
Description copied from interface: DOMConfiguration
Check if setting a parameter to a specific value is supported.

Specified by:
canSetParameter in interface DOMConfiguration
Parameters:
name - The name of the parameter to check.
value - An object. if null, the returned value is true.
Returns:
true if the parameter could be successfully set to the specified value, or false if the parameter is not recognized or the requested value is not supported. This does not change the current value of the parameter itself.

getParameter

public java.lang.Object getParameter(java.lang.String name)
                              throws DOMException
Description copied from interface: DOMConfiguration
Return the value of a parameter if known.

Specified by:
getParameter in interface DOMConfiguration
Parameters:
name - The name of the parameter.
Returns:
The current object associated with the specified parameter or null if no object has been associated or if the parameter is not supported.
Throws:
DOMException - NOT_FOUND_ERR: Raised when the parameter name is not recognized.

getParameterNames

public DOMStringList getParameterNames()
Description copied from interface: DOMConfiguration
The list of the parameters supported by this DOMConfiguration object and for which at least one value can be set by the application. Note that this list can also contain parameter names defined outside this specification.

Specified by:
getParameterNames in interface DOMConfiguration

setParameter

public void setParameter(java.lang.String name,
                         java.lang.Object value)
                  throws DOMException
Description copied from interface: DOMConfiguration
Set the value of a parameter.

Specified by:
setParameter in interface DOMConfiguration
Parameters:
name - The name of the parameter to set.
value - The new value or null if the user wishes to unset the parameter. While the type of the value parameter is defined as DOMUserData, the object type must match the type defined by the definition of the parameter. For example, if the parameter is "error-handler", the value must be of type DOMErrorHandler.
Throws:
DOMException - NOT_FOUND_ERR: Raised when the parameter name is not recognized.
NOT_SUPPORTED_ERR: Raised when the parameter name is recognized but the requested value cannot be set.
TYPE_MISMATCH_ERR: Raised if the value type for this parameter name is incompatible with the expected value type.