users@glassfish.java.net

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

From: Kedar Mhaswade <Kedar.Mhaswade_at_Sun.COM>
Date: Tue, 28 Jul 2009 16:11:41 -0700

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?

Or is there any other way to get
> glassfish configuration / list of deployed applications?

I think the above (what you've done) should be good enough.

Alternatively, you can inject Applications:

@Inject
volatile Applications apps = null;

and then do apps.getApplications() to get a List<Application>.

-Kedar


> Thanks,
> Pavel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>