From: Berin Loritsch <[EMAIL PROTECTED]>service in fortress
Reply-To: "Avalon framework users" <[EMAIL PROTECTED]>
To: Avalon framework users <[EMAIL PROTECTED]>
Subject: Re: where can I find a sample code demonstrating how to lookup a
Date: Mon, 12 Jan 2004 09:26:27 -0500about
Mu Mike wrote:
>
> when you said " looked up via a Selector", did you mean that the
> ServiceManager does it automatically? that is, I dont need to care
> if it is a manager or a selector is looking up a service 'component'?what
Pretty much.
<snip/>
> <my-system>
> <AnotherRunner id="Another"/>
> <DefaultRunner id="Default"/>
> </my-system>
>
> now I need a Runner implementaion, I did this
>
> myServiceManager.lookup(Runner.ROLE);(Runner.ROLE="Runner"):
>
> it returns me an AnotherRunner, but what if I need a DefaultRunner?
> shall I do then?"default"
You can override the default implementation of Runner by adding a
attribute to the config. for example:Fortress
<my-system> <AnotherRunner id="Another"/> <DefaultRunner id="Default" default="true"/> </my-system>
The decision process for figuring out the default implementation in
is to use the first component found in the configuration file(AnotherRunner),
unless the "default" attribute is set for another implementation (in thiscase,
DefaultRunner).look up
Also, if you still need to get at a particular Runner you can directly
which one using this construct:cases.
myServiceManager.lookup(Runner.ROLE + "/Another"); // get AnotherRunner myServiceManager.lookup(Runner.ROLE + "/Default"); // get DefaultRunner
That means that the ServiceSelector really isn't needed at all in most
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
> you know in ECM ,we wrote the roles file this way:
>
>
> <role
> name="Runner"
> shorthand="runner"
>
>
that was> > > <hint shorthand="anotherRunner" class="AnotherRunner"/> > <hint shorthand="defaultRunner" class="DefaultRunner"/> > </role>
Right. In ECM that "default-class" was used to initialize a component
"Selector);needed, but not part of the configuration file. By default, there is no equivalent in Fortress.
> when I did this: > mySelector=(ExcaliburComponentSelector)myECM.lookup(Runner.ROLE); it > returned me an ExcaliburComponentSelector,and I can then get,for > example, an AnotherRunner instance like this: > AnotherRunner runner=(AnotherRunner)mySelector.select("anotherRunner"); > > can you tell me how to achieve this in fortress?
You don't need to worry about this too much. All you have to do is this:
mySelector=(ServiceSelector)myServiceManager.lookup(Runner.ROLE +
the
Please note that you are using a dangerous construct above by casting to
actual *implementation* of the component instead of the *interface* of theis
component. Containers are free to use dynamic proxies to hide methods and
add other features for you. By casting to the expected implementation you
increase the likelihood that your application will fail with
ClassCastExceptions. Esp. if you change the implementation later on. It
best to code to the expressed contract, which is the interface.files,
> And, where can I find complete roles file and xconf file examples? I > guess they are of great use for a beginner like me
The examples directory has some available--but they do not use the Roles
they use meta-info. I have found the meta-info to be much more useful andless
fragile than roles files.
--
"They that give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." - Benjamin Franklin
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger: http://messenger.msn.com/cn
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
