avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <blorit...@apache.org>
Subject Re: [Fortress] Single Role, Multiple Components
Date Tue, 04 Mar 2003 19:29:47 GMT
J Aaron Farr wrote:
> Hello again.
> Having trouble with FortressServiceManager/Selector again.
> Okay, in my roles file I have this:
> <role name="com.company.component.RoleInterface">
>  <component shorthand="componentOne"
>             class="com.company.component.ImplOne"
>     handler="org.apache.avalon.fortress.impl.handler.FactoryComponentHandler"/>
>  <component shorthand="componentTwo"
>             class="com.company.component.ImplTwo"
> handler="org.apache.avalon.fortress.impl.handler.FactoryComponentHandler"/>
> </role>
> First off, is this valid?  It sure appears to be.


>  So now we turn to the
> container's configuration file:
>   <componentOne id="one">
>      <config>stuff</config>
>   </componentOne>
>   <componentTwo id="two">
>      <config>stuff</config>
>   </componentTwo>
> Now, if I use the service manager to lookup the role
> "com.company.component.RoleInterface" or RoleInterface.ROLE, I should get a
> ServiceSelector, correct?  In other words:
>   Object o = m_serviceManager.lookup(RoleInterface.ROLE);

No.  That gets you the default implementation.

> the object 'o' should be a ServiceSelector since I have two different
> components of the same role.  Instead, I'm getting 'o' as a proxy for the
> "ImplOne" object.  So in order for me to get an "ImplTwo" object, I have to do
> something like this:
>    Object o = m_serviceManager.lookup(RoleInterface.ROLE+"/componentTwo");

Right.  And if you want the selector, you need to do this:

Object o = m_serviceManager.lookup(RoleInterface.ROLE+"Selector");

(See the Developing with Avalon whitepaper for the documented

This is done to allow easier migration from ECM based projects where you
had to simply *know* which roles were accessible via selector or not.
This way your components are more portable.

> Is this the way it's supposed to work?  I'm fairly certain that the first
> example should return a ServiceSelector since I have two components defined for
> the same Role.  Perhaps I misunderstand the "contracts" of the ServiceManager,
> so if anyone has some insight, I'd appriciate it.

You just forgot to specify the selector with the +"Selector" idiom.

To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org

View raw message