dev@glassfish.java.net

Re: How to load a class using HK2 mechanisms

From: Sahoo <Sahoo_at_Sun.COM>
Date: Mon, 14 Jul 2008 08:58:47 -0700

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
>