/**
   * Starts the weld container
   *
   * @throws IllegalStateException if the container is already running
   */
  public synchronized void start(final StartContext context) {
    if (started) {
      throw WeldLogger.ROOT_LOGGER.alreadyRunning("WeldContainer");
    }
    started = true;

    WeldLogger.DEPLOYMENT_LOGGER.startingWeldService(deploymentName);
    // set up injected services
    addWeldService(SecurityServices.class, securityServices.getValue());
    addWeldService(TransactionServices.class, weldTransactionServices.getValue());

    if (!deployment.getServices().contains(ExecutorServices.class)) {
      addWeldService(ExecutorServices.class, executorServices.getValue());
    }

    ModuleGroupSingletonProvider.addClassLoaders(
        deployment.getModule().getClassLoader(), deployment.getSubDeploymentClassLoaders());

    ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
      WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(
          deployment.getModule().getClassLoader());
      bootstrap.startContainer(deploymentName, environment, deployment);
      WeldProvider.containerInitialized(
          Container.instance(deploymentName), getBeanManager(), deployment);
    } finally {
      WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
    }
  }
 /**
  * Stops the container
  *
  * @throws IllegalStateException if the container is not running
  */
 public synchronized void stop() {
   if (!started) {
     throw WeldMessages.MESSAGES.notStarted("WeldContainer");
   }
   ClassLoader oldTccl = SecurityActions.getContextClassLoader();
   try {
     SecurityActions.setContextClassLoader(deployment.getModule().getClassLoader());
     bootstrap.shutdown();
   } finally {
     SecurityActions.setContextClassLoader(oldTccl);
     ModuleGroupSingletonProvider.removeClassLoader(deployment.getModule().getClassLoader());
   }
   started = false;
 }
 /**
  * Stops the container
  *
  * @throws IllegalStateException if the container is not running
  */
 public synchronized void stop(final StopContext context) {
   if (!started) {
     throw WeldLogger.ROOT_LOGGER.notStarted("WeldContainer");
   }
   WeldLogger.DEPLOYMENT_LOGGER.stoppingWeldService(deploymentName);
   ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
   try {
     WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(
         deployment.getModule().getClassLoader());
     WeldProvider.containerShutDown(Container.instance(deploymentName));
     bootstrap.shutdown();
   } finally {
     WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
     ModuleGroupSingletonProvider.removeClassLoader(deployment.getModule().getClassLoader());
   }
   started = false;
 }
 /**
  * Starts the weld container
  *
  * @throws IllegalStateException if the container is already running
  */
 public synchronized void start() {
   if (started) {
     throw WeldMessages.MESSAGES.alreadyRunning("WeldContainer");
   }
   ModuleGroupSingletonProvider.addClassLoaders(
       deployment.getModule().getClassLoader(), deployment.getSubDeploymentClassLoaders());
   started = true;
   ClassLoader oldTccl = SecurityActions.getContextClassLoader();
   try {
     SecurityActions.setContextClassLoader(deployment.getModule().getClassLoader());
     bootstrap.startContainer(environment, deployment);
     bootstrap.startInitialization();
     bootstrap.deployBeans();
     bootstrap.validateBeans();
     bootstrap.endInitialization();
   } finally {
     SecurityActions.setContextClassLoader(oldTccl);
   }
 }
 public WeldContainer(WeldDeployment deployment, Environment environment) {
   this.deployment = deployment;
   this.environment = environment;
   this.bootstrap = new WeldBootstrap();
   Map<String, BeanDeploymentArchive> bdas = new HashMap<String, BeanDeploymentArchive>();
   BeanDeploymentArchiveImpl rootBeanDeploymentArchive = null;
   for (BeanDeploymentArchive archive : deployment.getBeanDeploymentArchives()) {
     bdas.put(archive.getId(), archive);
     if (archive instanceof BeanDeploymentArchiveImpl) {
       BeanDeploymentArchiveImpl bda = (BeanDeploymentArchiveImpl) archive;
       if (bda.isRoot()) {
         rootBeanDeploymentArchive = bda;
       }
     }
   }
   this.rootBeanDeploymentArchive = rootBeanDeploymentArchive;
   this.beanDeploymentArchives = Collections.unmodifiableMap(bdas);
 }
 /**
  * Adds a {@link Service} to the deployment. This method must not be called after the container
  * has started
  */
 public <T extends Service> void addWeldService(Class<T> type, T service) {
   if (started) {
     throw WeldMessages.MESSAGES.cannotAddServicesAfterStart();
   }
   deployment.addWeldService(type, service);
 }
 /**
  * Adds a {@link Service} to the deployment. This method must not be called after the container
  * has started
  */
 public <T extends org.jboss.weld.bootstrap.api.Service> void addWeldService(
     Class<T> type, T service) {
   deployment.addWeldService(type, service);
 }