dev@glassfish.java.net

Re: How to load a class using HK2 mechanisms

From: Kedar Mhaswade <Kedar.Mhaswade_at_Sun.COM>
Date: Mon, 14 Jul 2008 11:10:35 -0700

Thanks for these instructions. I will try them out.

If you have two "Service"s implementing the same "Contract", can
a Service be looked up by "name"?

Where does the "name" of a Service reflect in domain.xml? (What
attribute)?

Thanks,
Kedar

Sahoo wrote:
> Kumar,
>
> This is a good question. I am copying dev@ for others' benefit.
> Something like this should work:
>
> 1. Realm is a contract, which means.
> @Contract intercace Realm {...}
> 2. Let's say user provides FooRealm. They write:
> @Service class FooRealm implements Realm {...}
> They can choose to implement the same using OSGi service mechanism as
> well. We do the mapping from OSGi to HK2 service transparently.
>
> 3. Assuming you have the class name from domain.xml, in your code, you
> can use Habitat API to get hold of the service as shown below:
> @Inject Habitat habitat;
> Realm customRealm = habitat.getInhabitantsByType("FooRealm").get();
>
> Hope this helps,
>
> Thanks,
> Sahoo
> V B Kumar Jayanti wrote:
>> Hi Sahoo,
>>
>> I wanted to put in code for loading a Custom Realm defined as a
>> HK2/OSGI Module. Can you tell me how i can do that.
>>
>> regards,
>> kumar
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>