Hi there,
The composition tutorial shows an example of how to attain a simple service,
i.e. LocationService.
* @avalon.dependency key="locator"
type="tutorial.location.LocationService"
...
*/
public void service( ServiceManager manager ) throws ServiceException
{
getLogger().info( "servicing application" );
LocationService locator = null;
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?
Daniel
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]