On Sunday 14 March 2004 19:44, Daniel Frey wrote:

>         Object object = manager.lookup( "locator" );
>         if( object instanceof LocationService )
>         {
>             locator = (LocationService) object;
>         }
>         else
>         {
>             final String error =
>               "Object " + object.getClass().getName()
>               + " does not implement the LocatorService class.";
>             throw new ServiceException( "locator", error );
>         }
>     ...
>
> Certainly, an "instanceof" check is necessary when we cannot be sure of
> what type an object is. However, in this case we declare the type of
> "locator" in the @avalon.dependency tag to be "LocatorService". Is it still
> possible to get another service, mean, do we really need the instanceof
> check?

I guess I am the guilty one here. I copied the code from another tutorial (so 
if you search, you'll probably find it elsewhere as well).

The story goes roughly like this;
Avalon Framework doesn't specify that the correct type is guaranteed to be 
returned. And for all containers, except Merlin, this is true. It is possible 
to configure the application so that the wrong type is returned.

In Merlin, it should not be possible, so you are kind of right. It can't 
happen in Merlin, because Merlin will not deploy if it is misconfigured. (or 
so I believe, Stephen?)

Cheers
Niclas
-- 
+---------//-------------------+
|   http://www.bali.ac         |
|  http://niclas.hedhman.org   |
+------//----------------------+

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to