You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by J Aaron Farr <ja...@yahoo.com> on 2003/03/04 20:23:34 UTC
[Fortress] Single Role, Multiple Components
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);
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");
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.
Thanks!
jaaron
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
Re: [Fortress] Single Role, Multiple Components
Posted by Berin Loritsch <bl...@apache.org>.
J Aaron Farr wrote:
> --- Berin Loritsch <bl...@apache.org> wrote:
>
>>J Aaron Farr wrote:
>>
>>>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.
>>
>
>
> Is the default always the first one or is there a way to manually set that (in
> the config file for example)?
You can override the default by specifying the default="true" attribute.
NOTE: if there are two components, both specifying default="true", then
the last one wins.
For example:
<componentOne id="one">
<config>stuff</config>
</componentOne>
<componentTwo id="two" default="true">
<config>stuff</config>
</componentTwo>
Now the second component will be the default one.
And to prove the point of the NOTE:
<componentOne id="one" default="true">
<config>stuff</config>
</componentOne>
<componentTwo id="two" default="true">
<config>stuff</config>
</componentTwo>
the second is still the default implementation.
I can't remember if I have the container log that occurance or not.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
Re: [Fortress] Single Role, Multiple Components
Posted by J Aaron Farr <ja...@yahoo.com>.
--- Berin Loritsch <bl...@apache.org> wrote:
> J Aaron Farr wrote:
> > 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.
>
Is the default always the first one or is there a way to manually set that (in
the config file for example)?
jaaron
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
Re: [Fortress] Single Role, Multiple Components
Posted by Berin Loritsch <bl...@apache.org>.
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.
Yes.
> 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
convention).
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