BundleManagerPlugin(ServiceContainer serviceContainer, FrameworkBuilder frameworkBuilder) {
    super(Services.BUNDLE_MANAGER);
    this.serviceContainer = serviceContainer;
    this.frameworkBuilder = frameworkBuilder;
    this.stoppedEvent = FrameworkEvent.STOPPED;

    // The properties on the BundleManager are mutable as long the framework is not created
    // Plugins may modify these properties in their respective constructor
    properties.putAll(frameworkBuilder.getProperties());

    // Init default framework properties
    if (getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT) == null)
      setProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, OSGi_FRAMEWORK_EXECUTIONENVIRONMENT);
    if (getProperty(Constants.FRAMEWORK_LANGUAGE) == null)
      setProperty(Constants.FRAMEWORK_LANGUAGE, OSGi_FRAMEWORK_LANGUAGE);
    if (getProperty(Constants.FRAMEWORK_OS_NAME) == null)
      setProperty(Constants.FRAMEWORK_OS_NAME, OSGi_FRAMEWORK_OS_NAME);
    if (getProperty(Constants.FRAMEWORK_OS_VERSION) == null)
      setProperty(Constants.FRAMEWORK_OS_VERSION, OSGi_FRAMEWORK_OS_VERSION);
    if (getProperty(Constants.FRAMEWORK_PROCESSOR) == null)
      setProperty(Constants.FRAMEWORK_PROCESSOR, OSGi_FRAMEWORK_PROCESSOR);
    if (getProperty(Constants.FRAMEWORK_VENDOR) == null)
      setProperty(Constants.FRAMEWORK_VENDOR, OSGi_FRAMEWORK_VENDOR);
    if (getProperty(Constants.FRAMEWORK_VERSION) == null)
      setProperty(Constants.FRAMEWORK_VERSION, OSGi_FRAMEWORK_VERSION);

    boolean allowContainerShutdown = frameworkBuilder.getServiceContainer() == null;
    shutdownContainer = new ShutdownContainer(serviceContainer, allowContainerShutdown);
  }
  @Override
  public synchronized void start(StartContext context) throws StartException {
    ServiceController<?> controller = context.getController();
    LOGGER.tracef("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 serviceTarget = context.getChildTarget();
      JAXPServiceProvider.addService(serviceTarget);
      ResolverService.addService(serviceTarget);
      RepositoryService.addService(serviceTarget);

      Activation activation = subsystemState.getActivationPolicy();
      Mode initialMode = (activation == Activation.EAGER ? Mode.ACTIVE : Mode.LAZY);

      // Configure the {@link Framework} builder
      FrameworkBuilder builder = FrameworkBuilderFactory.create(props, initialMode);
      builder.setServiceContainer(serviceContainer);
      builder.setServiceTarget(serviceTarget);

      builder.createFrameworkServices(serviceContainer, true);
      builder.registerIntegrationService(FrameworkPhase.CREATE, new BundleLifecycleIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.CREATE, new FrameworkModuleIntegration(props));
      builder.registerIntegrationService(FrameworkPhase.CREATE, new ModuleLoaderIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.CREATE, new SystemServicesIntegration(resource, extensions));
      builder.registerIntegrationService(FrameworkPhase.INIT, new BootstrapBundlesIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.INIT, new PersistentBundlesIntegration(deploymentTracker));

      // Install the services to create the framework
      builder.installServices(FrameworkPhase.CREATE, serviceTarget, verificationHandler);

      if (activation == Activation.EAGER) {
        builder.installServices(FrameworkPhase.INIT, serviceTarget, verificationHandler);
        builder.installServices(FrameworkPhase.ACTIVE, serviceTarget, verificationHandler);
      }

      // Create the framework activator
      FrameworkActivator.create(builder);

    } catch (Throwable th) {
      throw MESSAGES.startFailedToCreateFrameworkServices(th);
    }
  }