| Resonsible for loading bindings into a container.
Strategy objects live inside a pico container. This provides the strategy
with the following:
- Life cycle
- Dependency management
Life Cycle
Strategy components that require notification of life cycle events must
implement the
org.picocontainer.Startable , and
org.picocontainer.Disposable interfaces.
Dependencies
Pico Container uses a design pattern known as Inversion of Control (IoC).This
pattern is very useful when the implementation of a particular dependency can
vary. For a detailed description, see
Inversion of Control pattern.
To achieve IoC, Pico Container uses a mechanism known as Contstructor
Injection. In this scheme, a particular component specifies all of its
dependencies in its constructor. The container will ensure that the
dependencies are satisfied when the component is instantiated. For an more
detailed explanation, see
Constructor Injection.
So how does the container know which implementation to supply to the
component when it is instantiated? An implementation of the dependency must
be registered with the container before the component is instantiated. This
is usually done at parser configuration time. See
org.geotools.xml.Configurationfor more details . Consider the following strategy.
class MyBinding extends SimpleBinding {
List list;
public MyBinding(List list) {
this.list = list;
}
public Object parse(InstanceComponent instance, Object value)
throws Exception {
list.add(value);
return list;
}
}
In the above example, our component depends on an object of type List. Since
List itself is abstract, at some point an actual concrete implementation of
List must be passed into the constructor of MyStrategy. Consider the
following strategy configuration.
class MyBindingConfiguration implements BindingConfiguration {
public void configure(MutablePicoContainer container) {
//first register a concrete implemtnation of list
container.registerComponentImplementation(LinkedList.class);
//register the actual component
QName qName = new QName("http://geotools/org/", "my");
container.registerComponentImplementation(qName,MyStrategy.class);
}
}
With the above container configuration, the concrete type of List will be
LinkedList.
author: Justin Deoliveira,Refractions Research Inc.,jdeolive@refractions.net |