|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectConfiguration
public abstract class Configuration
Responsible for configuring a parser runtime environment.
Implementations have the following responsibilites:
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 addDependency(Configuration)
method.
class MyConfiguration extends Configuration {
public MyConfiguration() {
super();
addDependency( new FooConfiguration() );
addDependency( new BarConfiguration() );
}
...
}
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
org.geotools.xml.BindingConfiguration
in #getBindingConfiguration()
:
BindingConfiguration getBindingConfiguration() {
return new MyBindingConfiguration();
}
Instances of type org.geotools.xml.BindingConfiguration
are used to
populate a container with all the bindings from a particular schema.
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);
}
}
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 XSDSchemaLocationResolver
can be
used 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 XSDSchemaLocator
can be used
to 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.
org.geotools.xml.BindingConfiguration
Constructor Summary | |
---|---|
Configuration(XSD xsd)
Creates a new configuration. |
Method Summary | ||
---|---|---|
protected void |
addDependency(Configuration dependency)
Adds a dependent configuration. |
|
List |
allDependencies()
Returns all dependencies in the configuration dependency tree. |
|
protected void |
configureBindings(Map bindings)
Template method allowing subclass to override any bindings. |
|
protected void |
configureBindings(MutablePicoContainer container)
Deprecated. use configureBindings(Map) . |
|
protected void |
configureContext(MutablePicoContainer container)
Configures the root context to be used when parsing elements. |
|
protected void |
configureEncoder(Encoder encoder)
Configures the encoder to be used with this configuration. |
|
protected void |
configureParser(Parser parser)
Configures the parser to be used with this configuration. |
|
boolean |
equals(Object obj)
Equals override, equality is based soley on getNamespaceURI() . |
|
MutablePicoContainer |
getContext()
Returns an internal context which is copied into the runtime context while parsing. |
|
List |
getDependencies()
|
|
|
getDependency(Class<C> clazz)
Returns the first dependency of this configuration of the specified type. |
|
String |
getNamespaceURI()
|
|
Set |
getProperties()
Returns a list of parser properties to set. |
|
String |
getSchemaFileURL()
Deprecated. use XSD.getSchemaLocation() . |
|
XSDSchemaLocationResolver |
getSchemaLocationResolver()
Deprecated. |
|
XSDSchemaLocator |
getSchemaLocator()
Deprecated. |
|
XSD |
getXSD()
The XSD instance representing the schema for which the schema works against. |
|
int |
hashCode()
|
|
boolean |
hasProperty(QName property)
Searches the configuration and all dependent configuration for the speciifed property. |
|
protected void |
registerBindings(Map bindings)
Registers the bindings for the configuration. |
|
protected void |
registerBindings(MutablePicoContainer container)
Deprecated. use registerBindings(Map) . |
|
XSDSchema |
schema()
Deprecated. use getXSD() and XSD.getSchema() . |
|
Map |
setupBindings()
Creates the map of QName to Binding which is used during parsing to attach bindinds to an element,attribute, or type. |
|
MutablePicoContainer |
setupBindings(MutablePicoContainer container)
Deprecated. use setupBindings() . |
|
MutablePicoContainer |
setupContext(MutablePicoContainer container)
Configures the root context to be used when parsing elements. |
|
void |
setupEncoder(Encoder encoder)
Prepares a encoder instance for use with this Configuration instance and all of its dependencies. |
|
void |
setupParser(Parser parser)
Prepares a parser instance for use with this Configuration instance and all of its dependencies. |
Methods inherited from class Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Configuration(XSD xsd)
Any dependent schemas should be added in sublcass constructor. The xml schema dependency does not have to be added.
Method Detail |
---|
public XSD getXSD()
public final List getDependencies()
public final Set getProperties()
To set a parser property:
Configuration configuration = ... configuration.getProperties().add( Parser.Properties.... );
Beware this class is not thread safe so take the needed precautions when using the list returned by this method.
public final boolean hasProperty(QName property)
public final List allDependencies()
The return list contains no duplicates.
public <C extends Configuration> C getDependency(Class<C> clazz)
protected void addDependency(Configuration dependency)
This method should only be called from the constructor.
dependency
- public final String getNamespaceURI()
public final String getSchemaFileURL()
XSD.getSchemaLocation()
.
For schema which are defined by multiple files, this method should return the base schema which includes all other files that define the schema.
public final XSDSchemaLocationResolver getSchemaLocationResolver()
This method should be overridden to return such an instance. The default
implemntation returns null
null
public final XSDSchemaLocator getSchemaLocator()
This method may be overriden to return such an instance. The default
delegates to #createSchemaLocator()
to and caches the restult. This method
may return null
to indicate that no such locator should be used.
null
public XSDSchema schema()
getXSD()
and XSD.getSchema()
.
public final MutablePicoContainer getContext()
This context is provided to allow for placing values in the parsing context without having to sublcass.
public final MutablePicoContainer setupBindings(MutablePicoContainer container)
setupBindings()
.
container
- The container housing the binding objects.public final Map setupBindings()
public final void setupParser(Parser parser)
public final void setupEncoder(Encoder encoder)
protected void registerBindings(MutablePicoContainer container)
registerBindings(Map)
.
This method is intended to provide the default bindings for a configuration
and is intended to be subclassed by client code. Client code should use
configureBindings(MutablePicoContainer)
.
container
- Container containing all bindings, keyed by QName
.protected void registerBindings(Map bindings)
This method is intended to provide the "default" bindings for a configuration
and is not intended to be subclassed by client code. Client code should use
configureBindings(MutablePicoContainer)
to override/remove/add new
bindings on teh fly.
The key of the bindings map is of type QName
. The value
can be class, or an instance. In the case of a class, the binding will be
instantiated by the parser at runtime. In the instance case the binding
will be used as is.
protected void configureBindings(MutablePicoContainer container)
configureBindings(Map)
.
container
- Container containing all bindings, keyed by QName
.protected void configureBindings(Map bindings)
bindings
- Map containing all bindings, keyed by QName
.public final MutablePicoContainer setupContext(MutablePicoContainer container)
container
- The container representing the context.protected void configureContext(MutablePicoContainer container)
The context satisifies any depenencencies needed by a binding. This is often a factory used to create something.
This method should be overriden. The default implementation does nothing.
container
- The container representing the context.protected void configureParser(Parser parser)
This method provides a callback for Configuration instances to configure the parser with whatever options they require.
protected void configureEncoder(Encoder encoder)
This method provides a callback for Configuration instances to configure the encoder with whatever options they require.
public final boolean equals(Object obj)
getNamespaceURI()
.
equals
in class Object
public final int hashCode()
hashCode
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |