use of javax.naming.NoInitialContextException in project aries by apache.
the class OSGiInitialContextFactoryBuilder method getInitialContext.
public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
Activator.getAugmenterInvoker().augmentEnvironment(environment);
BundleContext context = Utils.getBundleContext(environment, InitialContext.class);
if (context == null) {
throw new NoInitialContextException("The calling code's BundleContext could not be determined.");
}
Activator.getAugmenterInvoker().unaugmentEnvironment(environment);
return ContextHelper.getInitialContext(context, environment);
}
use of javax.naming.NoInitialContextException in project aries by apache.
the class ContextHelper method getInitialContext.
public static Context getInitialContext(BundleContext context, Hashtable<?, ?> environment) throws NamingException {
final Bundle jndiBundle = FrameworkUtil.getBundle(ContextHelper.class);
// if we are outside OSGi (like in our unittests) then we would get Null back here, so just make sure we don't.
if (jndiBundle != null) {
BundleContext jndiBundleContext = Utils.doPrivileged(jndiBundle::getBundleContext);
if (!jndiBundleContext.getClass().equals(context.getClass())) {
// the context passed in must have come from a child framework
// use the parent context instead
context = jndiBundleContext;
}
}
ContextProvider provider = getContextProvider(context, environment);
if (provider != null) {
return new DelegateContext(context, provider);
} else {
String contextFactoryClass = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
if (contextFactoryClass == null) {
return new DelegateContext(context, environment);
} else {
throw new NoInitialContextException("Unable to find the InitialContextFactory " + contextFactoryClass + ".");
}
}
}
Aggregations