Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, Red Hat Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.as.weld;
 
 import java.util.Map;
 import java.util.Set;
 
 
 import  org.jboss.weld.bootstrap.WeldBootstrap;
 import  org.jboss.weld.manager.BeanManagerImpl;

Provides access to a running weld deployment.

Thread Safety: This class is thread safe, and requires a happens before action between construction and usage

Author(s):
Stuart Douglas
 
 public class WeldContainer {
 
     private final WeldBootstrap bootstrap;
     private final WeldDeployment deployment;
     private final Environment environment;
     private volatile boolean started;
 
     public WeldContainer(WeldDeployment deploymentEnvironment environment) {
         this. = deployment;
         this. = environment;
         this. = new WeldBootstrap();
         Map<StringBeanDeploymentArchivebdas = new HashMap<StringBeanDeploymentArchive>();
         BeanDeploymentArchiveImpl rootBeanDeploymentArchive = null;
         for (BeanDeploymentArchive archive : deployment.getBeanDeploymentArchives()) {
             bdas.put(archive.getId(), archive);
             if (archive instanceof BeanDeploymentArchiveImpl) {
                 BeanDeploymentArchiveImpl bda = (BeanDeploymentArchiveImplarchive;
                 if (bda.isRoot()) {
                     rootBeanDeploymentArchive = bda;
                 }
             }
         }
         this. = rootBeanDeploymentArchive;
         this. = Collections.unmodifiableMap(bdas);
     }

    
Starts the weld container

Throws:
IllegalStateException if the container is already running
 
     public synchronized void start() {
         if () {
             throw ..alreadyRunning("WeldContainer");
         }
         ModuleGroupSingletonProvider.addClassLoaders(.getModule().getClassLoader(), .getSubDeploymentClassLoaders());
          = true;
         ClassLoader oldTccl = SecurityActions.getContextClassLoader();
         try {
             SecurityActions.setContextClassLoader(.getModule().getClassLoader());
             .startContainer();
             .startInitialization();
             .deployBeans();
             .validateBeans();
             .endInitialization();
         } finally {
             SecurityActions.setContextClassLoader(oldTccl);
         }
 
     }

    
Stops the container

Throws:
IllegalStateException if the container is not running
    public synchronized void stop() {
        if (!) {
            throw ..notStarted("WeldContainer");
        }
        ClassLoader oldTccl = SecurityActions.getContextClassLoader();
        try {
            SecurityActions.setContextClassLoader(.getModule().getClassLoader());
            .shutdown();
        } finally {
            SecurityActions.setContextClassLoader(oldTccl);
            ModuleGroupSingletonProvider.removeClassLoader(.getModule().getClassLoader());
        }
         = false;
    }

    
Gets the BeanManager for a given bean deployment archive.

Throws:
IllegalStateException if the container is not running
        if (!) {
            throw ..notStarted("WeldContainer");
        }
        return .getManager(archive);
    }

    
Gets the BeanManager for a given bean deployment archive id.

Throws:
IllegalStateException if the container is not running
IllegalArgumentException if the bean deployment archive id is not found
    public BeanManagerImpl getBeanManager(String beanArchiveId) {
        if (!) {
            throw ..notStarted("WeldContainer");
        }
        BeanDeploymentArchive beanDeploymentArchive = .get(beanArchiveId);
        if (beanDeploymentArchive == null) {
            throw ..beanDeploymentNotFound(beanArchiveId);
        }
        return .getManager(beanDeploymentArchive);
    }

    
Adds a Service to the deployment. This method must not be called after the container has started
    public <T extends Servicevoid addWeldService(Class<T> type, T service) {
        if () {
            throw ..cannotAddServicesAfterStart();
        }
        .addWeldService(typeservice);
    }

    
Gets the BeanManager linked to the root bean deployment archive. This BeanManager has access to all beans in a deployment

Throws:
IllegalStateException if the container is not running
    public BeanManager getBeanManager() {
        if (!) {
            throw ..notStarted("WeldContainer");
        }
        return .getManager();
    }

    
get all beans deployment archives in the deployment
    }
    public boolean isStarted() {
        return ;
    }
New to GrepCode? Check out our FAQ X