dev@glassfish.java.net

Re: Habitat.getComponent default

From: Bill Shannon <bill.shannon_at_sun.com>
Date: Sun, 16 Aug 2009 23:04:08 -0700

Sahoo wrote on 8/16/09 8:55 PM:
> Bill,
>
> No, Habitat.getComponent(Class clazz) is not broken. The implementation
> is like this:
>
> public <T> T getComponent(Class<T> clazz) throws ComponentException {
> if(isContract(clazz))
> return getByContract(clazz);
> else
> return getByType(clazz);
> }
>
> If clazz is a contract, then the javadocs of getByContract says it
> returns an arbitrary matching instance.
>
> If you want the a service with "null" name, then please call
> Habitat.getComponent(Class clazz, String name) with a null value for
> name. It is guaranteed to return unnamed instance only.

To be clear, *I* didn't write the code that calls getComponent.
Someone else did. Whoever did seemed to be assuming it was going
to return the unnamed component. Clearly it doesn't. And I guess
shouldn't.

I guess I now have two choices - name the component and get it by
name, or call getComponent with an explicit null.

Still waiting for someone (Jerome?) with some history on the code
to explain why it is the way it is.