in jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java [120:203]
public void start(BundleContext context) {
instance = this;
BundleContext trackerBundleContext;
/* Use system context to allow trackers full bundle/service visibility. */
if ( !Boolean.getBoolean("org.apache.aries.jndi.trackersUseLocalContext") ){
trackerBundleContext = context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
if (trackerBundleContext==null) {
throw new IllegalStateException("Bundle could not aquire system bundle context.");
}
}
else {
trackerBundleContext = context;
}
bundleServiceCaches =
new BundleTracker<ServiceCache>(trackerBundleContext, Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING , null) {
@Override
public ServiceCache addingBundle(Bundle bundle, BundleEvent event) {
return new ServiceCache(bundle.getBundleContext());
}
@Override
public void modifiedBundle(Bundle bundle, BundleEvent event, ServiceCache object) {
}
};
bundleServiceCaches.open();
initialContextFactories = new CachingServiceTracker<>(trackerBundleContext, InitialContextFactory.class, Activator::getInitialContextFactoryInterfaces);
objectFactories = new CachingServiceTracker<>(trackerBundleContext, ObjectFactory.class, Activator::getObjectFactorySchemes);
icfBuilders = new CachingServiceTracker<>(trackerBundleContext, InitialContextFactoryBuilder.class);
urlObjectFactoryFinders = new CachingServiceTracker<>(trackerBundleContext, URLObjectFactoryFinder.class);
if (!isPropertyEnabled(context, DISABLE_BUILDER)) {
try {
OSGiInitialContextFactoryBuilder builder = new OSGiInitialContextFactoryBuilder();
try {
NamingManager.setInitialContextFactoryBuilder(builder);
} catch (IllegalStateException e) {
// use reflection to force the builder to be used
if (isPropertyEnabled(context, FORCE_BUILDER)) {
originalICFBuilder = swapStaticField(InitialContextFactoryBuilder.class, builder);
}
}
icfBuilder = builder;
} catch (NamingException e) {
LOGGER.debug("A failure occurred when attempting to register an InitialContextFactoryBuilder with the NamingManager. " +
"Support for calling new InitialContext() will not be enabled.", e);
} catch (IllegalStateException e) {
// Log the problem at info level, but only log the exception at debug level, as in many cases this is not a real issue and people
// don't want to see stack traces at info level when everything it working as expected.
String msg = "It was not possible to register an InitialContextFactoryBuilder with the NamingManager because " +
"another builder called " + getClassName(InitialContextFactoryBuilder.class) + " was already registered. Support for calling new InitialContext() will not be enabled.";
LOGGER.info(msg);
LOGGER.debug(msg, e);
}
try {
OSGiObjectFactoryBuilder builder = new OSGiObjectFactoryBuilder(context);
try {
NamingManager.setObjectFactoryBuilder(builder);
} catch (IllegalStateException e) {
// use reflection to force the builder to be used
if (isPropertyEnabled(context, FORCE_BUILDER)) {
originalOFBuilder = swapStaticField(ObjectFactoryBuilder.class, builder);
}
}
ofBuilder = builder;
} catch (NamingException e) {
LOGGER.info("A failure occurred when attempting to register an ObjectFactoryBuilder with the NamingManager. " +
"Looking up certain objects may not work correctly.", e);
} catch (IllegalStateException e) {
// Log the problem at info level, but only log the exception at debug level, as in many cases this is not a real issue and people
// don't want to see stack traces at info level when everything it working as expected.
String msg = "It was not possible to register an ObjectFactoryBuilder with the NamingManager because " +
"another builder called " + getClassName(ObjectFactoryBuilder.class) + " was already registered. Looking up certain objects may not work correctly.";
LOGGER.info(msg);
LOGGER.debug(msg, e);
}
}
context.registerService(JNDIProviderAdmin.class.getName(), new ProviderAdminServiceFactory(context), null);
context.registerService(InitialContextFactoryBuilder.class.getName(), new JREInitialContextFactoryBuilder(), null);
context.registerService(JNDIContextManager.class.getName(), new ContextManagerServiceFactory(), null);
context.registerService(AugmenterInvoker.class.getName(), augmenterInvoker = new AugmenterInvokerImpl(context), null);
}