On Fri, 20 Sep 2002 10:34, Jason van Zyl wrote:
> Or are you saying that for the above scenerio I implement a factory that
> would do essentially what a container is doing:
>
> ContainerUtil.enableLogging(component, log);
> ContainerUtil.contextualize(component, context);
> ContainerUtil.service(component, this);
> ContainerUtil.configure(component, cd.getConfiguration());
> ContainerUtil.initialize(component);
> ContainerUtil.start(component);
>
> Except use a Configuration that I supply?
I think that is what he was implying.
> Would the following signature be useful for this sort of thing
> generally:
>
> ServiceManger.lookup(String role, Configuration configuration)
>
> I imagine that something akin to this must be used all the time, no?
We have debated it and generally came to the conclusion that there is three
"solutions". Say we wanted the component Foo - because Velocity is too long
to type in an example ;).
Solution one:
The component in the SM is a FooFactory that we can pass parameters/config to
to create Foo. Useful if Foo is private to each component.
ie
void service( ServiceManager sm )
{
final FooFactory factory = (FooFactory)sm.lookup( FooFactory.ROLE );
m_foo = factory.createFoo( myParams );
}
Solution two:
The component in the SM is a FooManager. The Foos that FooManager manages are
defined in the configuration of FooManager. Useful if Foo needs to be shared
between multiple components.
ie
void service( ServiceManager sm )
{
final FooManager factory = (FooManager)sm.lookup( FooManager.ROLE );
m_foo = factory.getFoo( "my-foo" );
}
Solution three:
There are several different instances of Foo in the container. ie Foo1, Foo2,
Foo3. Each component that needs a Foo has the assembler map the most
appropriate Foo into their SM namespace.
ie
void service( ServiceManager sm )
{
m_foo = (Foo)sm.lookup( Foo.ROLE );
}
Onlt Solution One provides a "dynamic" solution where the Foo iscreated
according to specified parameters. All the others require that the assembler
configure all the Foo instances in the application and either
* map them to correct component
* place them in a FooManager
That make sense?
--
Cheers,
Peter Donald
*-----------------------------------------------------*
* "Faced with the choice between changing one's mind, *
* and proving that there is no need to do so - almost *
* everyone gets busy on the proof." *
* - John Kenneth Galbraith *
*-----------------------------------------------------*
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>