Responsible for configuring a parser runtime environment.
Implementations have the following responsibilites:
- Configuration of bindings.
- Configuration of context used by bindings.
- Supplying specialized handlers for looking up schemas.
- Supplying specialized handlers for parsing schemas.
- Declaring dependencies on other configurations
Dependencies
Configurations have dependencies on one another, that result from teh fact that one schema imports another. Configuration dependencies are transitive. Each configuration should declare all dependencies in the constructor using the {@link #addDependency(Configuration)} method. class MyConfiguration extends Configuration { public MyConfiguration() { super(); addDependency( new FooConfiguration() ); addDependency( new BarConfiguration() ); } ... }
Binding Configuration
In able for a particular binding to be found during a parse, the configuration must first populate a container with said binding. This can be done by returning the appropriate instance of {@link org.geotools.xml.BindingConfiguration} in {@link #getBindingConfiguration()}:
BindingConfiguration getBindingConfiguration() { return new MyBindingConfiguration(); }
Instances of type {@link org.geotools.xml.BindingConfiguration} are used topopulate a container with all the bindings from a particular schema.
Context Configuration
Many bindings have dependencies on other types of objects. The pattern used to satisfy these dependencies is known as Constructor Injection. Which means that any dependencies a binding has is passed to it in its constructor. For instance, the following binding has a dependency on java.util.List.
class MyBinding implements SimpleBinding { List list; public MyBinding(List list) { this.list = list; } }
Before a binding can be created, the container in which it is housed in must be able to satisfy all of its dependencies. It is the responsibility of the configuration to statisfy this criteria. This is known as configuring the binding context. The following is a suitable configuration for the above binding.
class MyConfiguration extends Configuration { .... void configureContext(MutablePicoContainer container) { container.registerComponentImplementation(ArrayList.class); } }
Schema Resolution
XML instance documents often contain schema uri references that are invalid with respect to the parser, or non-existant. A configuration can supply specialized look up classes to prevent the parser from following an invalid uri and prevent any errors that may occur as a result.
An instance of {@link org.eclipse.xsd.util.XSDSchemaLocationResolver} can beused to override a schemaLocation referencing another schema. This can be useful when the entity parsing an instance document stores schemas in a location unkown to the entity providing hte instance document.
An instance of {@link org.eclipse.xsd.util.XSDSchemaLocator} can be usedto provide an pre-parsed schema and prevent the parser from parsing a schemaLocation manually. This can be useful when an instance document does not supply a schemaLocation for the targetNamespace of the document.
class MyConfiguration implements Configuration { XSDSchemaLocationResolver getSchemaLocationResolver() { return new MySchemaLocationResolver(); } XSDSchemaLocator getSchemaLocator() { return new MySchemaLocator(); } }
The XSDSchemaLocator and XSDSchemaLocationResolver implementations are used in a couple of scenarios. The first is when the schemaLocation attribute of the root element of the instance document is being parsed. The schemaLocation attribute has the form:
schemaLocation="namespace location namespace location ..."
In which (namespace,location) tuples are listed. For each each namespace encountered when parsing the schemaLocation attribute, an appropriate resolver / locator is looked up. If an override is not aviable, the framework attempts to resolve the location part of the tuple into a schema. The second scenario occurs when the parsing of a schema encounters an
import or an
include element. These elements have the form:
<import namespace="" schemaLocation=""/>
and:
<include schemaLocation="">
respectivley. Similar to above, the schemaLocation (and namespace in the case of an import) are used to find an override. If not found they are resolved directly.
@author Justin Deoliveira,Refractions Research Inc.,jdeolive@refractions.net
@see org.geotools.xml.BindingConfiguration
@source $URL$