ROOT_LOGGER.debugf("Starting: %s in mode %s", controller.getName(), controller.getMode());
try {
ServiceContainer serviceContainer = context.getController().getServiceContainer();
// Setup the OSGi {@link Framework} properties
SubsystemState subsystemState = injectedSubsystemState.getValue();
Map<String, Object> props = new HashMap<String, Object>(subsystemState.getProperties());
setupIntegrationProperties(context, props);
// Register the URLStreamHandlerFactory
Module coreFrameworkModule = ((ModuleClassLoader) FrameworkBuilder.class.getClassLoader()).getModule();
Module.registerURLStreamHandlerFactoryModule(coreFrameworkModule);
Module.registerContentHandlerFactoryModule(coreFrameworkModule);
ServiceTarget target = context.getChildTarget();
AutoInstallIntegration.addService(target);
FrameworkModuleIntegration.addService(target, props);
JAXPServiceProvider.addService(target);
ModuleLoaderIntegration.addService(target);
ModuleIdentityArtifactProvider.addService(target);
RepositoryProvider.addService(target);
SystemServicesIntegration.addService(target);
// Configure the {@link Framework} builder
FrameworkBuilder builder = new FrameworkBuilder(props);
builder.setServiceContainer(serviceContainer);
builder.setServiceTarget(target);
builder.addProvidedService(Services.AUTOINSTALL_PROVIDER);
builder.addProvidedService(Services.BUNDLE_INSTALL_PROVIDER);
builder.addProvidedService(Services.FRAMEWORK_MODULE_PROVIDER);
builder.addProvidedService(Services.MODULE_LOADER_PROVIDER);
builder.addProvidedService(Services.SYSTEM_SERVICES_PROVIDER);
// Create the {@link Framework} services
Activation activation = subsystemState.getActivationPolicy();
Mode initialMode = (activation == Activation.EAGER ? Mode.ACTIVE : Mode.ON_DEMAND);
builder.createFrameworkServices(initialMode, true);
} catch (Throwable t) {
throw new StartException(MESSAGES.failedToCreateFrameworkServices(), t);