A Builder implementation that's backed by a container itself. In essence,
we're using a container to help build a container. The documentation for the
builder API may be a bit complex, but the usage is actually quite easy.
Just take a look at the following example:
PicoContainer picoContainer = getPicoContainer();
Container fortressContainer = getFortressContainer();
ResourceLocator dnaContainer = getDnaContainer();
Resolver parentContainerResolver = getParentResolver();
Resolver resolver =
JicarillaBuilder.newInstance()
.addComponent( HomerImpl.class )
.addComponent( YoungHomer.class )
.addComponent( new HomerImpl() )
.addComponent( new BartImpl() )
.addComponent(
new ClassSelector( Marge.class ),
new SingletonAdapter(
new ManualFactory(
new MargeImpl()
)
)
)
.addComponent(
new ClassSelector( Lisa.class ),
new SingletonAdapter(
new DnaFactory(
DnaLisa.class
)
)
)
.addComponent(
new ClassSelector( Maggie.class ),
new SingletonAdapter(
new Type1Factory(
AvalonMaggie.class
)
)
)
.addComponent( parentContainerResolver )
.addComponent( picoContainer )
.addComponent( fortressContainer )
.addComponent( dnaContainer )
.create();
Note a Builder instance is single-use, and you should create a new
instance (using
JicarillaBuilder.newInstance() every time you call
JicarillaBuilder.create() .
author: Leo Simons version: $Id: JicarillaBuilder.java,v 1.5 2004/04/03 12:59:48 lsimons Exp $ |