Thanks, that really helped me much.

From: Berin Loritsch <[EMAIL PROTECTED]>
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
service in fortress
Date: Mon, 12 Jan 2004 09:26:27 -0500

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
about
> if it is a manager or a selector is looking up a service 'component'?

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?
what
> shall I do then?

You can override the default implementation of Runner by adding a
"default"
attribute to the config. for example:

<my-system>
  <AnotherRunner id="Another"/>
  <DefaultRunner id="Default" default="true"/>
</my-system>

The decision process for figuring out the default implementation in
Fortress
is to use the first component found in the configuration file
(AnotherRunner),
unless the "default" attribute is set for another implementation (in this
case,
DefaultRunner).

Also, if you still need to get at a particular Runner you can directly
look up
which one using this construct:

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
cases.


> you know in ECM ,we wrote the roles file this way:
>
>
> <role
> name="Runner"
> shorthand="runner"
>
>
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">

>
>
>    <hint shorthand="anotherRunner" class="AnotherRunner"/>
>    <hint shorthand="defaultRunner" class="DefaultRunner"/>
>  </role>

Right. In ECM that "default-class" was used to initialize a component
that was
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 +
"Selector);

Please note that you are using a dangerous construct above by casting to
the
actual *implementation* of the component instead of the *interface* of the
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
is
best to code to the expressed contract, which is the interface.


> 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
files,
they use meta-info. I have found the meta-info to be much more useful and
less
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]



Reply via email to