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
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld;
 
 import java.util.Map;
 import java.util.Set;
 
 
Provides convenient way to access the CDI container.

Author(s):
Jozef Hartinger
 
 public class SimpleCDI extends AbstractCDI<Object> {
 
     private class ClassNameToBeanManager extends CacheLoader<StringBeanManagerProxy> {

        
Determines the correct org.jboss.weld.manager.BeanManagerImpl based on a class name of the caller.
 
         @Override
         public BeanManagerProxy load(String callerClassName) {
             return new BeanManagerProxy(findBeanManager(callerClassName));
         }
 
         public BeanManagerImpl findBeanManager(String callerClassName) {
             if (callerClassName == null) {
                 throw ..unableToIdentifyBeanManager();
             }
             Set<BeanManagerImplmanagers = new HashSet<BeanManagerImpl>();
             for (Map.Entry<BeanDeploymentArchiveBeanManagerImplentry : .beanDeploymentArchives().entrySet()) {
                 for (String className : entry.getKey().getBeanClasses()) {
                     if (className.equals(callerClassName)) {
                         managers.add(entry.getValue());
                     }
                 }
             }
 
             if (managers.size() == 1) {
                 return managers.iterator().next();
             }
             if (managers.size() == 0) {
                 return unsatisfiedBeanManager(callerClassName);
             }
             return ambiguousBeanManager(callerClassNamemanagers);
         }
     }
 
     private final LoadingCache<StringBeanManagerProxybeanManagers;
     private final Container container;
 
     public SimpleCDI() {
         this(Container.instance());
     }
 
     public SimpleCDI(Container container) {
         this. = container;
          = CacheBuilder.newBuilder().weakValues().build(new ClassNameToBeanManager());
     }

    
Callback that allows to override the behavior when CDI.current() is not called from within a bean archive.
 
     protected BeanManagerImpl unsatisfiedBeanManager(String callerClassName) {
         throw ..unsatisfiedBeanManager(callerClassName);
     }

    
Callback that allows to override the behavior when class that invoked CDI.current() is placed in multiple bean archives.
 
     protected BeanManagerImpl ambiguousBeanManager(String callerClassNameSet<BeanManagerImplmanagers) {
         throw ..ambiguousBeanManager(callerClassName);
     }
 
     @Override
    public BeanManagerProxy getBeanManager() {
        ContainerState state = .getState();
        if (state.equals(.) || state.equals(.)) {
            throw ..beanManagerNotAvailable();
        }
    }
    @Override
    public String toString() {
        return "Weld";
    }
    protected Container getContainer() {
        return ;
    }
    public void cleanup() {
        .invalidateAll();
    }
New to GrepCode? Check out our FAQ X