users@glassfish.java.net

Re: injecting com.sun.enterprise.config.serverbeans.Domain to osgi bundle

From: Pavel Bucek <Pavel.Bucek_at_Sun.COM>
Date: Wed, 29 Jul 2009 01:56:24 +0200

Kedar Mhaswade wrote:
> Pavel Bucek wrote:
>>
>> Hello,
>>
>> I have an osgi bundle and I need to determine application name from
>> context root. I can do something like:
>>
>> public static String getAppName(String contextRoot) {
>> if (contextRoot == null)
>> return null;
>> // first check in web modules
>> List<WebModule> lm =
>> domain.getApplications().getModules(WebModule.class);
>> for (WebModule wm : lm) {
>> if (contextRoot.equals(wm.getContextRoot())) {
>> return (wm.getName());
>> }
>> }
>> // then check under applications (introduced in V3 not j2ee app)
>> List<Application> la =
>> domain.getApplications().getModules(Application.class);
>> for (Application sapp : la) {
>> if (contextRoot.equals(sapp.getContextRoot())) {
>> return (sapp.getName());
>> }
>> }
>> return null;
>> }
>>
>>
>> but I dont have a instance of Domain. Can it be injected somehow like
>> in hk2 class with @Service annotation?
>
> I believe
> @Inject
> volatile Domain domain = null;
>
> should work. Have you tried it?
Yes, I did but domain is not injected.. I thought that these injections
works only in @Services and its because the are instanciated in some
special way. This is not my case, its service (declared in
META.INF/services) but not hk2 service.

 (and.. I tried to annotate class with @Service annotation and domain
was still null).

If it helps - I instanciate my "service" via ServiceFinder:
https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/jersey-core/src/main/java/com/sun/jersey/spi/service/ServiceFinder.java?rev=2400&view=markup