You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2010/08/12 09:00:43 UTC

svn commit: r984658 [1/2] - in /openejb/branches/openejb-jcdi/container/openejb-core/src: main/java/org/apache/openejb/assembler/classic/ main/java/org/apache/openejb/cdi/ main/java/org/apache/openejb/config/ main/java/org/apache/openejb/core/ main/jav...

Author: dblevins
Date: Thu Aug 12 07:00:42 2010
New Revision: 984658

URL: http://svn.apache.org/viewvc?rev=984658&view=rev
Log:
Changed to fit existing architecture a little better

Added:
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/BeansDeployer.java   (contents, props changed)
      - copied, changed from r966519, openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/BeansDeployer.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java   (with props)
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java   (with props)
Removed:
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/BeansDeployer.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContainer.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppScannerService.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiSecurityService.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiTransactionService.java
Modified:
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBeanInfo.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/core/MethodContext.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/Interceptor.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmArtifact.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorTest.java
    openejb/branches/openejb-jcdi/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java

Modified: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=984658&r1=984657&r2=984658&view=diff
==============================================================================
--- openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Thu Aug 12 07:00:42 2010
@@ -28,9 +28,7 @@ import org.apache.openejb.NoSuchApplicat
 import org.apache.openejb.OpenEJB;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.UndeployException;
-import org.apache.openejb.cdi.CdiAppContextsService;
-import org.apache.openejb.cdi.CdiPlugin;
-import org.apache.openejb.cdi.CdiResourceInjectionService;
+import org.apache.openejb.cdi.CdiBuilder;
 import org.apache.openejb.core.AppContext;
 import org.apache.openejb.core.ConnectorReference;
 import org.apache.openejb.core.CoreContainerSystem;
@@ -66,28 +64,13 @@ import org.apache.openejb.util.Reference
 import org.apache.openejb.util.SafeToolkit;
 import org.apache.openejb.util.proxy.ProxyFactory;
 import org.apache.openejb.util.proxy.ProxyManager;
-import org.apache.webbeans.config.WebBeansFinder;
-import org.apache.webbeans.container.BeanManagerImpl;
-import org.apache.webbeans.decorator.DecoratorsManager;
-import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.inject.AlternativesManager;
 import org.apache.webbeans.inject.OWBInjector;
-import org.apache.webbeans.intercept.InterceptorsManager;
-import org.apache.webbeans.plugins.PluginLoader;
-import org.apache.webbeans.portable.AnnotatedElementFactory;
-import org.apache.webbeans.portable.events.ExtensionLoader;
-import org.apache.webbeans.portable.events.ProcessAnnotatedTypeImpl;
-import org.apache.webbeans.spi.ContextsService;
-import org.apache.webbeans.spi.ScannerService;
-import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 import org.apache.xbean.finder.ResourceFinder;
 import org.apache.xbean.recipe.ObjectRecipe;
 import org.apache.xbean.recipe.Option;
 import org.apache.xbean.recipe.UnsetPropertiesRecipe;
 
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.interceptor.Interceptor;
 import javax.naming.Binding;
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -116,7 +99,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -610,6 +592,9 @@ public class Assembler extends Assembler
 
             allDeployments = sort(allDeployments);
 
+            CdiBuilder cdiBuilder = new CdiBuilder(appInfo, appContext);
+            cdiBuilder.build(allDeployments);
+            
             // now that everything is configured, deploy to the container
             if (start) {
                 for (DeploymentInfo deployment : allDeployments) {
@@ -623,8 +608,6 @@ public class Assembler extends Assembler
                 }
             }
 
-            buildCdiBeans(appInfo, classLoader, appContext, allDeployments);
-
             // App Client
             for (ClientInfo clientInfo : appInfo.clients) {
                 // determine the injections
@@ -696,148 +679,6 @@ public class Assembler extends Assembler
         }
     }
 
-    private static void buildCdiBeans(AppInfo appInfo, ClassLoader classLoader, AppContext appContext, List<DeploymentInfo> ejbDeployments) throws OpenEJBException {
-
-        long startTime = System.currentTimeMillis();
-        final ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
-        try {
-            //Set classloader
-            Thread.currentThread().setContextClassLoader(classLoader);
-
-            WebBeansFinder.clearInstances(classLoader);
-
-            BeanManagerImpl beanManager = (BeanManagerImpl) WebBeansFinder.getSingletonInstance(BeanManagerImpl.class.getName(), classLoader);
-            appContext.setBeanManager(beanManager);
-
-            //Configure our scanner service
-
-            //Start our plugins
-            PluginLoader.getInstance().startUp();
-
-            //Initialize our contexts
-            ContextsService contexsServices = (CdiAppContextsService) WebBeansFinder.getSingletonInstance(CdiAppContextsService.class.getName(), classLoader);
-            contexsServices.init(appInfo);
-
-            //Get Plugin
-            CdiPlugin cdiPlugin = (CdiPlugin) PluginLoader.getInstance().getEjbPlugin();
-            cdiPlugin.setAppModule(appInfo);
-            cdiPlugin.setClassLoader(classLoader);
-
-            //Configure EJB Deployments
-            cdiPlugin.configureDeployments();
-
-            //Resournce Injection Service
-            CdiResourceInjectionService injectionService = (CdiResourceInjectionService) WebBeansFinder.getSingletonInstance(CdiResourceInjectionService.class.getName(), classLoader);
-            injectionService.setAppModule(appInfo);
-            injectionService.setClassLoader(classLoader);
-
-            //Deploy the beans
-            try {
-                //Load Extensions
-                ExtensionLoader.getInstance().loadExtensionServices();
-
-                // Register Manager built-in component
-                BeanManagerImpl.getManager().addBean(WebBeansUtil.getManagerBean());
-
-                //Fire Event
-                BeansDeployer.fireBeforeBeanDiscoveryEvent(BeanManagerImpl.getManager());
-
-                //Deploy bean from XML. Also configures deployments, interceptors, decorators.
-                final BeansBuilder beansBuilder = new BeansBuilder(classLoader);
-
-                for (EjbJarInfo ejbJar : appInfo.ejbJars) {
-                    final BeansInfo beans = ejbJar.beans;
-
-                    if (beans == null) continue;
-
-                    beansBuilder.build(beans);
-                }
-
-                //Build injections for managed beans
-                // TODO Maybe we should build injections after the bean discovery
-                injectionService.buildInjections(beansBuilder.getBeanClasses());
-
-                //Checking stereotype conditions
-                BeansDeployer.checkStereoTypes(beansBuilder);
-
-                //Configure Default Beans
-                BeansDeployer.configureDefaultBeans();
-
-                //Discover classpath classes
-                deployManagedBeans(beansBuilder.getBeanClasses());
-
-                deployEnterpriseBeans(ejbDeployments);
-
-                //Check Specialization
-                BeansDeployer.checkSpecializations(beansBuilder);
-
-                //Fire Event
-                BeansDeployer.fireAfterBeanDiscoveryEvent(BeanManagerImpl.getManager());
-
-                //Validate injection Points
-                BeansDeployer.validateInjectionPoints(BeanManagerImpl.getManager());
-
-                //Fire Event
-                BeansDeployer.fireAfterDeploymentValidationEvent(BeanManagerImpl.getManager());
-            } catch (Exception e1) {
-                logger.error("CDI Beans module deployment failed", e1);
-                throw new RuntimeException(e1);
-            }
-
-            if (logger.isInfoEnabled()) {
-                logger.info("CDI Beans module deployed in " + (System.currentTimeMillis() - startTime) + " ms");
-            }
-
-        } catch (Exception e) {
-            String errorMessage = "Error is occurred while starting the CDI container, looks error log for further investigation";
-            throw new OpenEJBException(errorMessage, e);
-        } finally {
-            Thread.currentThread().setContextClassLoader(oldCL);
-        }
-    }
-
-    private static void deployManagedBeans(Set<Class<?>> beanClasses) {
-
-        // Start from the class
-        for (Class<?> implClass : beanClasses) {
-            //Define annotation type
-            AnnotatedType<?> annotatedType = AnnotatedElementFactory.getInstance().newAnnotatedType(implClass);
-
-            //Fires ProcessAnnotatedType
-            ProcessAnnotatedTypeImpl<?> processAnnotatedEvent = WebBeansUtil.fireProcessAnnotatedTypeEvent(annotatedType);
-
-            //if veto() is called
-            if (processAnnotatedEvent.isVeto()) {
-                continue;
-            }
-
-            BeansDeployer.defineManagedBean((Class<Object>) implClass, (ProcessAnnotatedTypeImpl<Object>) processAnnotatedEvent);
-        }
-    }
-
-    private static void deployEnterpriseBeans(List<DeploymentInfo> deployments) {
-
-        for (DeploymentInfo deployment : deployments) {
-            if (!deployment.getComponentType().isSession()) continue;
-
-            final Class implClass = deployment.getBeanClass();
-
-            //Define annotation type
-            AnnotatedType<?> annotatedType = AnnotatedElementFactory.getInstance().newAnnotatedType(implClass);
-
-            //Fires ProcessAnnotatedType
-            ProcessAnnotatedTypeImpl<?> processAnnotatedEvent = WebBeansUtil.fireProcessAnnotatedTypeEvent(annotatedType);
-
-            // TODO Can you really veto an EJB?
-            //if veto() is called
-            if (processAnnotatedEvent.isVeto()) {
-                continue;
-            }
-
-            BeansDeployer.defineEnterpriseWebBean((Class<Object>) implClass, (ProcessAnnotatedTypeImpl<Object>) processAnnotatedEvent);
-        }
-    }
-
 
     private TransactionPolicyFactory createTransactionPolicyFactory(EjbJarInfo ejbJar, ClassLoader classLoader) {
         TransactionPolicyFactory factory = null;
@@ -1619,109 +1460,4 @@ public class Assembler extends Assembler
         }
     }
 
-    private static class BeansBuilder implements ScannerService {
-
-        private final ClassLoader loader;
-        private final AlternativesManager alternativesManager = AlternativesManager.getInstance();
-        private final DecoratorsManager decoratorsManager = DecoratorsManager.getInstance();
-        private final InterceptorsManager interceptorsManager = InterceptorsManager.getInstance();
-
-        // TODO add all annotated class
-        private final Set<Class<?>> classes = new HashSet<Class<?>>();
-
-        private BeansBuilder(ClassLoader loader) {
-            this.loader = loader;
-        }
-
-        @Override
-        public void init(Object object) {
-            // Unused
-        }
-
-        @Override
-        public void scan() {
-            // Unused
-        }
-
-        @Override
-        public Set<URL> getBeanXmls() {
-            return Collections.EMPTY_SET; // Unused
-        }
-
-        @Override
-        public Set<Class<?>> getBeanClasses() {
-            return classes;
-        }
-
-        private Class load(String className, String type) throws OpenEJBException {
-            try {
-                return loader.loadClass(className);
-            } catch (ClassNotFoundException e) {
-                throw new OpenEJBException("Unable to load " + type + " class", e);
-            }
-        }
-
-        public void addInterceptor(String className) throws OpenEJBException {
-            Class<?> clazz = load(className, "interceptor");
-
-            if (AnnotationUtil.hasAnnotation(clazz.getDeclaredAnnotations(), Interceptor.class) &&
-                    !AnnotationUtil.hasInterceptorBindingMetaAnnotation(clazz.getDeclaredAnnotations())) {
-                throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " must have at least one @InterceptorBindingType");
-            }
-
-            if (interceptorsManager.isInterceptorEnabled(clazz)) {
-                throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " is already defined");
-            }
-
-            interceptorsManager.addNewInterceptor(clazz);
-            classes.add(clazz);
-        }
-
-        public void addDecorator(String className) throws OpenEJBException {
-            Class<?> clazz = load(className, "decorator");
-
-            if (decoratorsManager.isDecoratorEnabled(clazz)) {
-                throw new WebBeansConfigurationException("Decorator class : " + clazz.getName() + " is already defined");
-            }
-
-            decoratorsManager.addNewDecorator(clazz);
-            classes.add(clazz);
-        }
-
-        private void addAlternativeStereotype(String className) throws OpenEJBException {
-            Class<?> clazz = load(className, "alternative-stereotype");
-            alternativesManager.addStereoTypeAlternative(clazz);
-            classes.add(clazz);
-        }
-
-        private void addAlternativeClass(String className) throws OpenEJBException {
-            Class<?> clazz = load(className, "alternative-class");
-            alternativesManager.addClazzAlternative(clazz);
-            classes.add(clazz);
-        }
-
-        public void build(BeansInfo beans) throws OpenEJBException {
-            for (String className : beans.interceptors) {
-                addInterceptor(className);
-            }
-
-            for (String className : beans.decorators) {
-                addDecorator(className);
-            }
-
-
-            for (String className : beans.alternativeStereotypes) {
-                addAlternativeStereotype(className);
-            }
-
-            for (String className : beans.alternativeClasses) {
-                addAlternativeClass(className);
-            }
-
-            for (String className : beans.managedClasses) {
-                final Class clazz = load(className, "managed");
-                classes.add(clazz);
-            }
-        }
-    }
 }

Modified: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java?rev=984658&r1=984657&r2=984658&view=diff
==============================================================================
--- openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java (original)
+++ openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java Thu Aug 12 07:00:42 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.assembler.classic;
 
+import org.apache.openejb.cdi.CdiInterceptor;
 import org.apache.openejb.core.CoreDeploymentInfo;
 import org.apache.openejb.core.interceptor.InterceptorData;
 import org.apache.openejb.util.LogCategory;
@@ -101,9 +102,6 @@ public class InterceptorBindingBuilder {
         toMethods(clazz, beanInfo.aroundInvoke, beanAsInterceptor.getAroundInvoke());
         toCallback(clazz, beanInfo.postConstruct, beanAsInterceptor.getPostConstruct());
         toCallback(clazz, beanInfo.preDestroy, beanAsInterceptor.getPreDestroy());
-        
-        //Cdi interceptor add the end of the chain
-        InterceptorData cdiInterceptor = InterceptorData.scan(OpenWebBeansEjbInterceptor.class);
 
         if (beanInfo instanceof StatefulBeanInfo) {
             StatefulBeanInfo stateful = (StatefulBeanInfo) beanInfo;
@@ -120,9 +118,6 @@ public class InterceptorBindingBuilder {
         for (Method method : deploymentInfo.getBeanClass().getMethods()) {
             List<InterceptorData> methodInterceptors = createInterceptorDatas(method, beanInfo.ejbName, this.bindings);
 
-            //Cdi Interceptor
-            methodInterceptors.add(cdiInterceptor);
-
             // The bean itself gets to intercept too and is always last.
             methodInterceptors.add(beanAsInterceptor);
             
@@ -131,9 +126,6 @@ public class InterceptorBindingBuilder {
 
         List<InterceptorData> callbackInterceptorDatas = createInterceptorDatas(null, beanInfo.ejbName, this.packageAndClassBindings);
 
-        //Cdi interceptor
-        callbackInterceptorDatas.add(cdiInterceptor);
-        
         // The bean itself gets to intercept too and is always last.
         callbackInterceptorDatas.add(beanAsInterceptor);
 

Copied: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/BeansDeployer.java (from r966519, openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/BeansDeployer.java)
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/BeansDeployer.java?p2=openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/BeansDeployer.java&p1=openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/BeansDeployer.java&r1=966519&r2=984658&rev=984658&view=diff
==============================================================================
--- openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/BeansDeployer.java (original)
+++ openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/BeansDeployer.java Thu Aug 12 07:00:42 2010
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.openejb.assembler.classic;
+package org.apache.openejb.cdi;
 
 import org.apache.webbeans.component.AbstractInjectionTargetBean;
 import org.apache.webbeans.component.AbstractProducerBean;
@@ -29,7 +29,6 @@ import org.apache.webbeans.component.Web
 import org.apache.webbeans.component.creation.BeanCreator;
 import org.apache.webbeans.component.creation.ManagedBeanCreatorImpl;
 import org.apache.webbeans.config.DefinitionUtil;
-import org.apache.webbeans.config.EJBWebBeansConfigurator;
 import org.apache.webbeans.config.ManagedBeanConfigurator;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.container.BeanManagerImpl;
@@ -46,7 +45,6 @@ import org.apache.webbeans.intercept.Int
 import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
 import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.plugins.PluginLoader;
-import org.apache.webbeans.portable.AnnotatedElementFactory;
 import org.apache.webbeans.portable.events.ProcessAnnotatedTypeImpl;
 import org.apache.webbeans.portable.events.ProcessInjectionTargetImpl;
 import org.apache.webbeans.portable.events.discovery.AfterBeanDiscoveryImpl;
@@ -70,12 +68,8 @@ import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.ProcessAnnotatedType;
 import javax.interceptor.Interceptor;
-import java.io.IOException;
-import java.io.InputStream;
 import java.lang.annotation.Annotation;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -97,31 +91,6 @@ public class BeansDeployer {
     private static final WebBeansLogger logger = WebBeansLogger.getLogger(BeansDeployer.class);
 
     /**
-     * Deployment is started or not
-     */
-    protected boolean deployed = false;
-
-    /**
-     * XML Configurator
-     */
-    protected WebBeansXMLConfigurator xmlConfigurator = null;
-
-    /**
-     * Discover ejb or not
-     */
-    protected boolean discoverEjb = false;
-
-    /**
-     * Creates a new deployer with given xml configurator.
-     *
-     * @param xmlConfigurator xml configurator
-     */
-    public BeansDeployer(WebBeansXMLConfigurator xmlConfigurator) {
-        this.xmlConfigurator = xmlConfigurator;
-        this.discoverEjb = true;
-    }
-
-    /**
      * Configure Default Beans.
      */
     public static void configureDefaultBeans() {
@@ -339,94 +308,6 @@ public class BeansDeployer {
         }
     }
 
-
-    /**
-     * Discovers and deploys classes from class path.
-     *
-     * @param scanner discovery scanner
-     * @throws ClassNotFoundException if class not found
-     */
-    protected static void deployFromClassPath(ScannerService scanner) throws ClassNotFoundException {
-        logger.debug("Deploying configurations from class files has started.");
-
-        // Start from the class
-        Set<Class<?>> classIndex = scanner.getBeanClasses();
-
-        //Iterating over each class
-        if (classIndex != null) {
-            for (Class<?> implClass : classIndex) {
-                //Define annotation type
-                AnnotatedType<?> annotatedType = AnnotatedElementFactory.getInstance().newAnnotatedType(implClass);
-
-                //Fires ProcessAnnotatedType
-                ProcessAnnotatedTypeImpl<?> processAnnotatedEvent = WebBeansUtil.fireProcessAnnotatedTypeEvent(annotatedType);
-
-                //if veto() is called
-                if (processAnnotatedEvent.isVeto()) {
-                    continue;
-                }
-
-                //Try class is Managed Bean
-                boolean isDefined = defineManagedBean((Class<Object>) implClass, (ProcessAnnotatedTypeImpl<Object>) processAnnotatedEvent);
-
-                //Try class is EJB bean
-                if (!isDefined) {
-                    if (EJBWebBeansConfigurator.isSessionBean(implClass)) {
-                        logger.debug("Found Enterprise Bean with class name : [{0}]", implClass.getName());
-                        defineEnterpriseWebBean((Class<Object>) implClass, (ProcessAnnotatedTypeImpl<Object>) processAnnotatedEvent);
-                    }
-                }
-            }
-        }
-
-        logger.debug("Deploying configurations from class files has ended.");
-
-    }
-
-    /**
-     * Discovers and deploys classes from XML.
-     * <p/>
-     * NOTE : Currently XML file is just used for configuring.
-     *
-     * @param scanner discovery scanner
-     * @param xmlConfigurator
-     * @throws org.apache.webbeans.exception.WebBeansDeploymentException
-     *          if exception
-     */
-    protected static void deployFromXML(ScannerService scanner, WebBeansXMLConfigurator xmlConfigurator) throws WebBeansDeploymentException {
-        logger.debug("Deploying configurations from XML files has started.");
-
-        Set<URL> xmlLocations = scanner.getBeanXmls();
-        Iterator<URL> it = xmlLocations.iterator();
-
-        while (it.hasNext()) {
-            URL fileURL = it.next();
-            String fileName = fileURL.getFile();
-            InputStream fis = null;
-            try {
-                fis = fileURL.openStream();
-
-                xmlConfigurator.configure(fis, fileName);
-            }
-            catch (IOException e) {
-                throw new WebBeansDeploymentException(e);
-            }
-            finally {
-                if (fis != null) {
-                    try {
-                        fis.close();
-                    }
-                    catch (IOException e) {
-                        // all ok, ignore this!
-                    }
-                }
-            }
-        }
-
-        logger.debug("Deploying configurations from XML has ended successfully.");
-    }
-
-
     /**
      * Checks specialization.
      *
@@ -671,17 +552,5 @@ public class BeansDeployer {
         else {
             return false;
         }
-
-    }
-
-    /**
-     * Defines enterprise bean via plugin.
-     *
-     * @param <T>   bean class type
-     * @param clazz bean class
-     */
-    protected static <T> void defineEnterpriseWebBean(Class<T> clazz, ProcessAnnotatedType<T> processAnnotatedTypeEvent) {
-        InjectionTargetBean<T> bean = (InjectionTargetBean<T>) EJBWebBeansConfigurator.defineEjbBean(clazz, processAnnotatedTypeEvent);
-        WebBeansUtil.setInjectionTargetBeanEnableFlag(bean);
     }
 }

Propchange: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/BeansDeployer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java?rev=984658&r1=984657&r2=984658&view=diff
==============================================================================
--- openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java (original)
+++ openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java Thu Aug 12 07:00:42 2010
@@ -16,17 +16,6 @@
  */
 package org.apache.openejb.cdi;
 
-import java.lang.annotation.Annotation;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.ContextException;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.context.spi.Context;
-import javax.inject.Singleton;
-import javax.servlet.ServletRequestEvent;
-
-import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.webbeans.context.AbstractContextsService;
@@ -36,6 +25,14 @@ import org.apache.webbeans.context.Reque
 import org.apache.webbeans.context.SingletonContext;
 import org.apache.webbeans.spi.ContextsService;
 
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.ContextException;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.spi.Context;
+import javax.inject.Singleton;
+import java.lang.annotation.Annotation;
+
 public class CdiAppContextsService extends AbstractContextsService implements ContextsService {
 
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB.createChild("cdi"), CdiAppContextsService.class);
@@ -48,213 +45,208 @@ public class CdiAppContextsService exten
     private volatile SingletonContext currentSingletonContext = null;
 
     public CdiAppContextsService() {
-	dependentContext.setActive(true);
+        dependentContext.setActive(true);
     }
-    
+
     @Override
-    public void init(Object initializeObject){        
+    public void init(Object initializeObject) {
         //Start application context
         startContext(ApplicationScoped.class, initializeObject);
-        
+
         //Start signelton context
         startContext(Singleton.class, initializeObject);
-    }        
+    }
 
     @Override
-    public void startContext(Class<? extends Annotation> scopeType,
-	    Object startParameter) throws ContextException {
-	if (supportsContext(scopeType)) {
-	    if (scopeType.equals(RequestScoped.class)) {
-		initRequestContext();
-	    } else if (scopeType.equals(ApplicationScoped.class)) {
-		initApplicationContext();
-	    } else if (scopeType.equals(Dependent.class)) {
-		// Do nothing
-	    } else if (scopeType.equals(Singleton.class)) {
-		initSingletonContext();
-	    } else {
-		if (logger.isWarningEnabled()) {
-		    logger.warning("CDI-OpenWebBeans container in OpenEJB does not support context scope "
-				    + scopeType.getSimpleName()
-				    + ". Scopes @Dependent, @RequestScoped, @ApplicationScoped and @Singleton are supported scope types");
-		}
-	    }
-	}
+    public void startContext(Class<? extends Annotation> scopeType, Object startParameter) throws ContextException {
+        if (supportsContext(scopeType)) {
+            if (scopeType.equals(RequestScoped.class)) {
+                initRequestContext();
+            } else if (scopeType.equals(ApplicationScoped.class)) {
+                initApplicationContext();
+            } else if (scopeType.equals(Dependent.class)) {
+                // Do nothing
+            } else if (scopeType.equals(Singleton.class)) {
+                initSingletonContext();
+            } else {
+                if (logger.isWarningEnabled()) {
+                    logger.warning("CDI-OpenWebBeans container in OpenEJB does not support context scope "
+                            + scopeType.getSimpleName()
+                            + ". Scopes @Dependent, @RequestScoped, @ApplicationScoped and @Singleton are supported scope types");
+                }
+            }
+        }
     }
 
     @Override
-    public void endContext(Class<? extends Annotation> scopeType,
-	    Object endParameters) {
-	if (supportsContext(scopeType)) {
-	    if (scopeType.equals(RequestScoped.class)) {
-		destroyRequestContext((ServletRequestEvent) endParameters);
-	    } else if (scopeType.equals(ApplicationScoped.class)) {
-		destroyApplicationContext((AppInfo) endParameters);
-	    } else if (scopeType.equals(Dependent.class)) {
-		// Do nothing
-	    } else if (scopeType.equals(Singleton.class)) {
-		destroySingletonContext();
-	    } else {
-		if (logger.isWarningEnabled()) {
-		    logger.warning("CDI-OpenWebBeans container in OpenEJB does not support context scope "
-				    + scopeType.getSimpleName()
-				    + ". Scopes @Dependent, @RequestScoped, @ApplicationScoped and @Singleton are supported scope types");
-		}
-	    }
-	}
+    public void endContext(Class<? extends Annotation> scopeType, Object endParameters) {
+
+        if (supportsContext(scopeType)) {
+            if (scopeType.equals(RequestScoped.class)) {
+                destroyRequestContext();
+            } else if (scopeType.equals(ApplicationScoped.class)) {
+                destroyApplicationContext();
+            } else if (scopeType.equals(Dependent.class)) {
+                // Do nothing
+            } else if (scopeType.equals(Singleton.class)) {
+                destroySingletonContext();
+            } else {
+                if (logger.isWarningEnabled()) {
+                    logger.warning("CDI-OpenWebBeans container in OpenEJB does not support context scope "
+                            + scopeType.getSimpleName()
+                            + ". Scopes @Dependent, @RequestScoped, @ApplicationScoped and @Singleton are supported scope types");
+                }
+            }
+        }
 
     }
 
     @Override
     public Context getCurrentContext(Class<? extends Annotation> scopeType) {
-	if (supportsContext(scopeType)) {
-	    if (scopeType.equals(RequestScoped.class)) {
-		return requestContext.get();
-	    } else if (scopeType.equals(ApplicationScoped.class)) {
-		return applicationContext.get();
-	    } else if (scopeType.equals(Dependent.class)) {
-		return dependentContext;
-	    } else {
-		return singletonContext.get();
-	    }
-	}
+        if (supportsContext(scopeType)) {
+            if (scopeType.equals(RequestScoped.class)) {
+                return requestContext.get();
+            } else if (scopeType.equals(ApplicationScoped.class)) {
+                return applicationContext.get();
+            } else if (scopeType.equals(Dependent.class)) {
+                return dependentContext;
+            } else {
+                return singletonContext.get();
+            }
+        }
 
-	return null;
+        return null;
     }
 
     private void initApplicationContext() {
-	if (this.currentApplicationContext != null) {
-	    applicationContext.set(this.currentApplicationContext);
-	}
-
-	else {
-	    ApplicationContext currentApplicationContext = new ApplicationContext();
-	    currentApplicationContext.setActive(true);
-
-	    this.currentApplicationContext = currentApplicationContext;
-	    applicationContext.set(currentApplicationContext);
-	}
-    }
-
-    private void destroyApplicationContext(AppInfo appInfo) {
-	// look for thread local
-	// this can be set by initRequestContext
-	ApplicationContext context = this.currentApplicationContext;
-
-	// using in tests
-	if (context == null) {
-	    context = applicationContext.get();
-	}
-
-	// Destroy context
-	if (context != null) {
-	    context.destroy();
-	}
+        if (this.currentApplicationContext != null) {
+            applicationContext.set(this.currentApplicationContext);
+        } else {
+            ApplicationContext currentApplicationContext = new ApplicationContext();
+            currentApplicationContext.setActive(true);
+
+            this.currentApplicationContext = currentApplicationContext;
+            applicationContext.set(currentApplicationContext);
+        }
+    }
+
+    private void destroyApplicationContext() {
+        // look for thread local
+        // this can be set by initRequestContext
+        ApplicationContext context = this.currentApplicationContext;
+
+        // using in tests
+        if (context == null) {
+            context = applicationContext.get();
+        }
+
+        // Destroy context
+        if (context != null) {
+            context.destroy();
+        }
 
-	this.currentApplicationContext = null;
+        this.currentApplicationContext = null;
     }
 
     private void initSingletonContext() {
-	if (this.currentSingletonContext != null) {
-	    singletonContext.set(currentSingletonContext);
-	}
-
-	else {
-	    SingletonContext context = new SingletonContext();
-	    context.setActive(true);
-	    this.currentSingletonContext = context;
+        if (this.currentSingletonContext != null) {
+            singletonContext.set(currentSingletonContext);
+        } else {
+            SingletonContext context = new SingletonContext();
+            context.setActive(true);
+            this.currentSingletonContext = context;
 
-	    singletonContext.set(context);
-	}
+            singletonContext.set(context);
+        }
 
     }
 
     private void destroySingletonContext() {
-	SingletonContext context = this.currentSingletonContext;
+        SingletonContext context = this.currentSingletonContext;
 
-	// using in tests
-	if (context == null) {
-	    context = singletonContext.get();
-	}
-
-	// context is not null
-	// destroy it
-	if (context != null) {
-	    context.destroy();
-	}
+        // using in tests
+        if (context == null) {
+            context = singletonContext.get();
+        }
+
+        // context is not null
+        // destroy it
+        if (context != null) {
+            context.destroy();
+        }
 
-	this.currentSingletonContext = null;
+        this.currentSingletonContext = null;
     }
 
     @Override
     public boolean supportsContext(Class<? extends Annotation> scopeType) {
-	if (scopeType.equals(RequestScoped.class)
-		|| scopeType.equals(ApplicationScoped.class)
-		|| scopeType.equals(Dependent.class)
-		|| scopeType.equals(Singleton.class)) {
-	    return true;
-	}
+        if (scopeType.equals(RequestScoped.class)
+                || scopeType.equals(ApplicationScoped.class)
+                || scopeType.equals(Dependent.class)
+                || scopeType.equals(Singleton.class)) {
+            return true;
+        }
 
-	return false;
+        return false;
     }
 
     private void initRequestContext() {
 
-	RequestContext rq = new RequestContext();
-	rq.setActive(true);
+        RequestContext rq = new RequestContext();
+        rq.setActive(true);
 
-	requestContext.set(rq);
+        requestContext.set(rq);
 
-	// Init threadLocal application context
-	initApplicationContext();
+        // Init threadLocal application context
+        initApplicationContext();
 
-	// Init threadlocal singleton context
-	initSingletonContext();
+        // Init threadlocal singleton context
+        initSingletonContext();
     }
 
-    private void destroyRequestContext(ServletRequestEvent request) {
-	// Get context
-	RequestContext context = requestContext.get();
+    private void destroyRequestContext() {
+        // Get context
+        RequestContext context = requestContext.get();
 
-	// Destroy context
-	if (context != null) {
-	    context.destroy();
-	}
+        // Destroy context
+        if (context != null) {
+            context.destroy();
+        }
 
-	// Remove
-	requestContext.remove();
-	requestContext.set(null);
+        // Remove
+        requestContext.remove();
+        requestContext.set(null);
 
-	// Remove singleton and application contexts
-	singletonContext.remove();
-	singletonContext.set(null);
+        // Remove singleton and application contexts
+        singletonContext.remove();
+        singletonContext.set(null);
 
-	applicationContext.remove();
-	applicationContext.set(null);
+        applicationContext.remove();
+        applicationContext.set(null);
 
     }
-    
-    public void destroy(Object destroyObject){
+
+    public void destroy(Object destroyObject) {
         //Destroy application context
         endContext(ApplicationScoped.class, destroyObject);
-        
+
         //Destroy singleton context
         endContext(Singleton.class, destroyObject);
-        
+
         this.currentApplicationContext = null;
         this.currentSingletonContext = null;
-             
+
         //Remove thread locals
         //for preventing memory leaks
         requestContext.remove();
         applicationContext.remove();
-        singletonContext.remove();        
-        
+        singletonContext.remove();
+
         //Thread local values to null
         requestContext.set(null);
         applicationContext.set(null);
-        singletonContext.set(null);        
-                
-    }    
-    
+        singletonContext.set(null);
+
+    }
+
 }

Modified: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBeanInfo.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBeanInfo.java?rev=984658&r1=984657&r2=984658&view=diff
==============================================================================
--- openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBeanInfo.java (original)
+++ openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBeanInfo.java Thu Aug 12 07:00:42 2010
@@ -16,11 +16,6 @@
  */
 package org.apache.openejb.cdi;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.openejb.Injection;
 import org.apache.openejb.jee.DataSource;
 import org.apache.openejb.jee.EjbLocalRef;
@@ -38,7 +33,12 @@ import org.apache.openejb.jee.SecurityId
 import org.apache.openejb.jee.SecurityRoleRef;
 import org.apache.openejb.jee.ServiceRef;
 
-public class CdiBeanInfo implements JndiConsumer{
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+public class CdiBeanInfo implements JndiConsumer {
 
     protected KeyedCollection<String, EnvEntry> envEntry;
     protected KeyedCollection<String, EjbRef> ejbRef;
@@ -63,21 +63,17 @@ public class CdiBeanInfo implements Jndi
     public String getBeanName() {
         return beanName;
     }
-    
-     
 
     public List<Injection> getInjections() {
         return injections;
     }
 
 
-
     public void setInjections(List<Injection> injections) {
         this.injections = injections;
     }
 
 
-
     public void setBeanName(String beanName) {
         this.beanName = beanName;
     }
@@ -100,7 +96,6 @@ public class CdiBeanInfo implements Jndi
     }
 
 
-
     public Collection<EnvEntry> getEnvEntry() {
         if (envEntry == null) {
             envEntry = new KeyedCollection<String, EnvEntry>();
@@ -234,7 +229,6 @@ public class CdiBeanInfo implements Jndi
         return this.postConstruct;
     }
 
- 
 
     public List<SecurityRoleRef> getSecurityRoleRef() {
         if (securityRoleRef == null) {
@@ -252,7 +246,6 @@ public class CdiBeanInfo implements Jndi
     }
 
 
-
     public List<LifecycleCallback> getAfterBegin() {
         if (afterBegin == null) {
             afterBegin = new ArrayList<LifecycleCallback>();
@@ -292,7 +285,7 @@ public class CdiBeanInfo implements Jndi
         return beanName;
     }
 
-    public Class<?> getBeanClass(){
-	return this.beanClass;
+    public Class<?> getBeanClass() {
+        return this.beanClass;
     }
 }

Added: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java?rev=984658&view=auto
==============================================================================
--- openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java (added)
+++ openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java Thu Aug 12 07:00:42 2010
@@ -0,0 +1,332 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.cdi;
+
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.BeansInfo;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.core.AppContext;
+import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.config.WebBeansFinder;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.decorator.DecoratorsManager;
+import org.apache.webbeans.ejb.common.util.EjbUtility;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.inject.AlternativesManager;
+import org.apache.webbeans.intercept.InterceptorComparator;
+import org.apache.webbeans.intercept.InterceptorData;
+import org.apache.webbeans.intercept.InterceptorsManager;
+import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
+import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
+import org.apache.webbeans.plugins.PluginLoader;
+import org.apache.webbeans.portable.AnnotatedElementFactory;
+import org.apache.webbeans.portable.events.ExtensionLoader;
+import org.apache.webbeans.portable.events.ProcessAnnotatedTypeImpl;
+import org.apache.webbeans.spi.ScannerService;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.WebBeansUtil;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.interceptor.Interceptor;
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CdiBuilder {
+
+    private final AppInfo appInfo;
+    private final AppContext appContext;
+    private ClassLoader classLoader;
+
+    public CdiBuilder(AppInfo appInfo, AppContext appContext) {
+        this.appInfo = appInfo;
+        this.appContext = appContext;
+        classLoader = appContext.getClassLoader();
+    }
+
+    private static void deployManagedBeans(Set<Class<?>> beanClasses) {
+
+        // Start from the class
+        for (Class<?> implClass : beanClasses) {
+            //Define annotation type
+            AnnotatedType<?> annotatedType = AnnotatedElementFactory.getInstance().newAnnotatedType(implClass);
+
+            //Fires ProcessAnnotatedType
+            ProcessAnnotatedTypeImpl<?> processAnnotatedEvent = WebBeansUtil.fireProcessAnnotatedTypeEvent(annotatedType);
+
+            //if veto() is called
+            if (processAnnotatedEvent.isVeto()) {
+                continue;
+            }
+
+            BeansDeployer.defineManagedBean((Class<Object>) implClass, (ProcessAnnotatedTypeImpl<Object>) processAnnotatedEvent);
+        }
+    }
+
+    public void build(List<DeploymentInfo> ejbDeployments) throws OpenEJBException {
+
+        long startTime = System.currentTimeMillis();
+        final ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+        try {
+            //Set classloader
+            Thread.currentThread().setContextClassLoader(classLoader);
+
+            WebBeansFinder.clearInstances(classLoader);
+
+            BeanManagerImpl beanManager = (BeanManagerImpl) WebBeansFinder.getSingletonInstance(BeanManagerImpl.class.getName(), classLoader);
+            OpenWebBeansConfiguration owb = OpenWebBeansConfiguration.getInstance();
+            owb.setProperty(OpenWebBeansConfiguration.INTERCEPTOR_FORCE_NO_CHECKED_EXCEPTIONS, "false");
+            appContext.setBeanManager(beanManager);
+
+            //Configure our scanner service
+
+            //Start our plugins
+            PluginLoader.getInstance().startUp();
+
+            //Get Plugin
+            CdiPlugin cdiPlugin = (CdiPlugin) PluginLoader.getInstance().getEjbPlugin();
+
+            cdiPlugin.setAppContext(appContext);
+
+            cdiPlugin.startup();
+
+            //Configure EJB Deployments
+            cdiPlugin.configureDeployments(ejbDeployments);
+
+            //Resournce Injection Service
+            CdiResourceInjectionService injectionService = (CdiResourceInjectionService) WebBeansFinder.getSingletonInstance(CdiResourceInjectionService.class.getName(), classLoader);
+            injectionService.setAppModule(appInfo);
+            injectionService.setClassLoader(classLoader);
+
+            //Deploy the beans
+            try {
+                //Load Extensions
+                ExtensionLoader.getInstance().loadExtensionServices();
+
+                // Register Manager built-in component
+                final BeanManagerImpl manager = BeanManagerImpl.getManager();
+
+                manager.addBean(WebBeansUtil.getManagerBean());
+
+                //Fire Event
+                BeansDeployer.fireBeforeBeanDiscoveryEvent(manager);
+
+                //Deploy bean from XML. Also configures deployments, interceptors, decorators.
+
+                final CdiScanner cdiScanner = buildScanner();
+
+                //Build injections for managed beans
+                // TODO Maybe we should build injections after the bean discovery
+                injectionService.buildInjections(cdiScanner.getBeanClasses());
+
+                //Checking stereotype conditions
+                BeansDeployer.checkStereoTypes(cdiScanner);
+
+                //Configure Default Beans
+                BeansDeployer.configureDefaultBeans();
+
+                //Discover classpath classes
+                deployManagedBeans(cdiScanner.getBeanClasses());
+
+                for (DeploymentInfo deployment : ejbDeployments) {
+                    if (!deployment.getComponentType().isSession()) continue;
+
+                    final Class implClass = deployment.getBeanClass();
+
+                    //Define annotation type
+                    AnnotatedType<?> annotatedType = AnnotatedElementFactory.getInstance().newAnnotatedType(implClass);
+
+                    //Fires ProcessAnnotatedType
+                    ProcessAnnotatedTypeImpl<?> processAnnotatedEvent = WebBeansUtil.fireProcessAnnotatedTypeEvent(annotatedType);
+
+                    // TODO Can you really veto an EJB?
+                    //if veto() is called
+                    if (processAnnotatedEvent.isVeto()) {
+                        continue;
+                    }
+
+                    CdiEjbBean<Object> bean = new CdiEjbBean<Object>(deployment);
+
+                    CoreDeploymentInfo info = (CoreDeploymentInfo) deployment;
+                    info.set(CdiEjbBean.class, bean);
+                    
+                    info.addSystemInterceptor(new CdiInterceptor(bean, manager, cdiPlugin.getContexsServices()));
+
+                    EjbUtility.fireEvents((Class<Object>) implClass, bean, (ProcessAnnotatedTypeImpl<Object>) processAnnotatedEvent);
+
+                    WebBeansUtil.setInjectionTargetBeanEnableFlag(bean);
+                }
+
+                //Check Specialization
+                BeansDeployer.checkSpecializations(cdiScanner);
+
+                //Fire Event
+                BeansDeployer.fireAfterBeanDiscoveryEvent(manager);
+
+                //Validate injection Points
+                BeansDeployer.validateInjectionPoints(manager);
+
+                for (DeploymentInfo deployment : ejbDeployments) {
+                    final CoreDeploymentInfo info = (CoreDeploymentInfo) deployment;
+                    if (!info.getComponentType().isSession()) continue;
+                    final CdiEjbBean bean = info.get(CdiEjbBean.class);
+
+                    // The interceptor stack is empty until validateInjectionPoints is called as it does more than validate. 
+                    final List<InterceptorData> datas = bean.getInterceptorStack();
+
+                    final List<org.apache.openejb.core.interceptor.InterceptorData> converted = new ArrayList<org.apache.openejb.core.interceptor.InterceptorData>();
+                    for (InterceptorData data : datas) {
+                        // todo this needs to use the code in InterceptorBindingBuilder that respects override rules and private methods
+                        converted.add(org.apache.openejb.core.interceptor.InterceptorData.scan(data.getInterceptorClass()));
+                    }
+
+                    info.setCdiInterceptors(converted);
+                }
+
+                //Fire Event
+                BeansDeployer.fireAfterDeploymentValidationEvent(manager);
+            } catch (Exception e1) {
+                Assembler.logger.error("CDI Beans module deployment failed", e1);
+                throw new RuntimeException(e1);
+            }
+
+            if (Assembler.logger.isInfoEnabled()) {
+                Assembler.logger.info("CDI Beans module deployed in " + (System.currentTimeMillis() - startTime) + " ms");
+            }
+
+        } catch (Exception e) {
+            String errorMessage = "Error is occurred while starting the CDI container, looks error log for further investigation";
+            throw new OpenEJBException(errorMessage, e);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCL);
+        }
+    }
+
+    private CdiScanner buildScanner() throws OpenEJBException {
+
+        final Set<Class<?>> classes = new HashSet<Class<?>>();
+
+        final AlternativesManager alternativesManager = AlternativesManager.getInstance();
+        final DecoratorsManager decoratorsManager = DecoratorsManager.getInstance();
+        final InterceptorsManager interceptorsManager = InterceptorsManager.getInstance();
+        
+        for (EjbJarInfo ejbJar : appInfo.ejbJars) {
+            final BeansInfo beans = ejbJar.beans;
+
+            if (beans == null) continue;
+
+            for (String className : beans.interceptors) {
+                Class<?> clazz = load(className, "interceptor");
+
+                // TODO: Move check to validation phase
+                if (AnnotationUtil.hasAnnotation(clazz.getDeclaredAnnotations(), Interceptor.class) && !AnnotationUtil.hasInterceptorBindingMetaAnnotation(clazz.getDeclaredAnnotations())) {
+                    throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " must have at least one @InterceptorBindingType");
+                }
+
+                if (interceptorsManager.isInterceptorEnabled(clazz)) {
+                    throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " is already defined");
+                }
+
+                interceptorsManager.addNewInterceptor(clazz);
+                classes.add(clazz);
+            }
+
+            for (String className : beans.decorators) {
+                Class<?> clazz = load(className, "decorator");
+
+                if (decoratorsManager.isDecoratorEnabled(clazz)) {
+                    throw new WebBeansConfigurationException("Decorator class : " + clazz.getName() + " is already defined");
+                }
+
+                decoratorsManager.addNewDecorator(clazz);
+                classes.add(clazz);
+            }
+
+
+            for (String className : beans.alternativeStereotypes) {
+                Class<?> clazz = load(className, "alternative-stereotype");
+                alternativesManager.addStereoTypeAlternative(clazz);
+                classes.add(clazz);
+            }
+
+            for (String className : beans.alternativeClasses) {
+                Class<?> clazz = load(className, "alternative-class");
+                alternativesManager.addClazzAlternative(clazz);
+                classes.add(clazz);
+            }
+
+            for (String className : beans.managedClasses) {
+                final Class clazz = load(className, "managed");
+                classes.add(clazz);
+            }
+        }
+
+        return new CdiScanner(classes);
+    }
+
+    private Class load(String className, String type) throws OpenEJBException {
+        try {
+            return classLoader.loadClass(className);
+        } catch (ClassNotFoundException e) {
+            throw new OpenEJBException("Unable to load " + type + " class", e);
+        }
+    }
+
+    public static class CdiScanner implements ScannerService {
+
+        // TODO add all annotated class
+        private final Set<Class<?>> classes = new HashSet<Class<?>>();
+
+        public CdiScanner(Collection<Class<?>> classes) {
+            this.classes.addAll(classes);
+        }
+
+        @Override
+        public void init(Object object) {
+            // Unused
+        }
+
+        @Override
+        public void scan() {
+            // Unused
+        }
+
+        @Override
+        public Set<URL> getBeanXmls() {
+            return Collections.EMPTY_SET; // Unused
+        }
+
+        @Override
+        public Set<Class<?>> getBeanClasses() {
+            return classes;
+        }
+    }
+}

Propchange: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java?rev=984658&r1=984657&r2=984658&view=diff
==============================================================================
--- openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java (original)
+++ openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java Thu Aug 12 07:00:42 2010
@@ -16,30 +16,22 @@
  */
 package org.apache.openejb.cdi;
 
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.assembler.classic.ProxyInterfaceResolver;
+import org.apache.webbeans.ejb.common.component.BaseEjbBean;
 
 import javax.ejb.Remove;
 import javax.enterprise.context.spi.CreationalContext;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import org.apache.openejb.DeploymentInfo;
-import org.apache.openejb.InterfaceType;
-import org.apache.openejb.assembler.classic.JndiBuilder;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.spi.ContainerSystem;
-import org.apache.webbeans.ejb.common.component.BaseEjbBean;
+import javax.enterprise.inject.spi.SessionBeanType;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
 
 public class CdiEjbBean<T> extends BaseEjbBean<T> {
-    private DeploymentInfo deploymentInfo;
+    private final DeploymentInfo deploymentInfo;
 
-    public CdiEjbBean(Class<T> ejbClassType) {
-        super(ejbClassType);
-    }
-
-    public void setDeploymentInfo(DeploymentInfo deploymentInfo) {
+    public CdiEjbBean(DeploymentInfo deploymentInfo) {
+        super(deploymentInfo.getBeanClass());
         this.deploymentInfo = deploymentInfo;
     }
 
@@ -48,34 +40,38 @@ public class CdiEjbBean<T> extends BaseE
     }
 
     @Override
-    @SuppressWarnings("unchecked")
-    protected T getInstance(CreationalContext<T> creationalContext) {
-        T instance = null;
+    public void setEjbType(SessionBeanType type) {
+        throw new IllegalStateException("The SessionBeanType cannot be changed");
+    }
 
-        ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
-        Context jndiContext = containerSystem.getJNDIContext();
-        DeploymentInfo deploymentInfo = this.getDeploymentInfo();
-        try {
-            if (iface != null) {
-                InterfaceType type = deploymentInfo.getInterfaceType(iface);
-                if (!type.equals(InterfaceType.BUSINESS_LOCAL)) {
-                    throw new IllegalArgumentException(
-                            "Interface type is not legal business local interface for session bean class : "
-                                    + getReturnType().getName());
-                }
-            } else {
-                iface = this.deploymentInfo.getBusinessLocalInterface();
-            }
+    @Override
+    public SessionBeanType getEjbType() {
+        switch (deploymentInfo.getComponentType()) {
+            case SINGLETON:
+                return SessionBeanType.SINGLETON;
+            case STATELESS:
+                return SessionBeanType.STATELESS;
+            case STATEFUL:
+            case MANAGED:
+                return SessionBeanType.STATEFUL;
+            default:
+                throw new IllegalStateException("Unknown Session BeanType " + deploymentInfo.getComponentType());
+        }
+    }
 
-            String jndiName = "java:openejb/Deployment/"
-                    + JndiBuilder.format(deploymentInfo.getDeploymentID(), this.iface.getName());
-            instance = (T) this.iface.cast(jndiContext.lookup(jndiName));
+    @Override
+    public String getId() {
+        return (String) deploymentInfo.getDeploymentID();
+    }
 
-        } catch (NamingException e) {
-            throw new RuntimeException(e);
-        }
+    @Override
+    @SuppressWarnings("unchecked")
+    protected T getInstance(CreationalContext<T> creationalContext) {
 
-        return instance;
+        List<Class> interfaces = ProxyInterfaceResolver.getInterfaces(deploymentInfo.getBeanClass(), iface, deploymentInfo.getBusinessLocalInterfaces());
+        DeploymentInfo.BusinessLocalHome home = deploymentInfo.getBusinessLocalHome(interfaces);
+
+        return (T) home.create();
     }
 
     public String getEjbName() {
@@ -133,4 +129,8 @@ public class CdiEjbBean<T> extends BaseE
         return toReturn;
     }
 
+    @Override
+    public String getName() {
+        return deploymentInfo.getEjbName();
+    }
 }
\ No newline at end of file

Added: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java?rev=984658&view=auto
==============================================================================
--- openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java (added)
+++ openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java Thu Aug 12 07:00:42 2010
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.openejb.cdi;
+
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+import org.apache.openejb.core.ivm.IntraVmArtifact;
+import org.apache.webbeans.component.InjectionTargetBean;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.decorator.DelegateHandler;
+import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
+import org.apache.webbeans.proxy.JavassistProxyFactory;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CdiInterceptor implements Serializable {
+
+    private final CdiEjbBean<Object> bean;
+    private final BeanManagerImpl manager;
+    private final CdiAppContextsService contextService;
+
+    public CdiInterceptor(CdiEjbBean<Object> bean, BeanManagerImpl manager, CdiAppContextsService contextService) {
+        this.bean = bean;
+        this.manager = manager;
+        this.contextService = contextService;
+    }
+
+    @AroundInvoke
+    public Object aroundInvoke(final InvocationContext ejbContext) throws Exception {
+
+        Callable callable = new Callable() {
+            @Override
+            public Object call() throws Exception {
+                return invoke(ejbContext);
+            }
+        };
+
+        callable = new ScopeActivator(callable, ApplicationScoped.class);
+        callable = new ScopeActivator(callable, RequestScoped.class);
+        return callable.call();
+    }
+
+    public class ScopeActivator implements Callable {
+        private final Callable callable;
+        private final Class<? extends Annotation> scopeType;
+
+        public ScopeActivator(Callable callable, Class<? extends Annotation> scopeType) {
+            this.callable = callable;
+            this.scopeType = scopeType;
+        }
+
+        @Override
+        public Object call() throws Exception {
+
+            Context ctx = contextService.getCurrentContext(scopeType);
+            boolean active = false;
+
+            if (ctx == null) {
+                contextService.startContext(scopeType, null);
+            } else if (!ctx.isActive()) {
+                contextService.activateContext(scopeType);
+            } else {
+                active = true;
+            }
+
+            try {
+                return callable.call();
+            } finally {
+                if (ctx == null) {
+                    contextService.endContext(scopeType, null);
+                } else if (!active) {
+                    contextService.deActivateContext(scopeType);
+                }
+            }
+        }
+    }
+
+    private Object invoke(InvocationContext ejbContext) throws Exception {
+        final CreationalContext<?> context = getCreationalContext();
+
+        Object instance = ejbContext.getTarget();
+
+        if (bean.getDecoratorStack().size() > 0) {
+
+            Class<?> proxyClass = JavassistProxyFactory.getInstance().getInterceptorProxyClasses().get((InjectionTargetBean<?>) bean);
+            if (proxyClass == null) {
+                ProxyFactory delegateFactory = JavassistProxyFactory.getInstance().createProxyFactory(bean);
+                proxyClass = JavassistProxyFactory.getInstance().getProxyClass(delegateFactory);
+                JavassistProxyFactory.getInstance().getInterceptorProxyClasses().put((InjectionTargetBean<?>) bean, proxyClass);
+            }
+            Object delegate = proxyClass.newInstance();
+            DelegateHandler delegateHandler = new DelegateHandler(bean, ejbContext);
+            ((ProxyObject) delegate).setHandler(delegateHandler);
+
+            // Gets component decorator stack
+            List<Object> decorators = WebBeansDecoratorConfig.getDecoratorStack(bean, instance, delegate, (CreationalContextImpl<?>) context);
+            //Sets decorator stack of delegate
+            delegateHandler.setDecorators(decorators);
+
+            return delegateHandler.invoke(instance, ejbContext.getMethod(), null, ejbContext.getParameters());
+        } else {
+            return ejbContext.proceed();
+        }
+    }
+
+    private CreationalContext<?> getCreationalContext() {
+        // TODO This has the outcome that decorators are created every request
+        // need to instantiate decorators at instance creation time
+        // when and where we create interceptor instances
+        return manager.createCreationalContext(null);
+    }
+
+    protected Object writeReplace() throws ObjectStreamException {
+        return new IntraVmArtifact(this, true);
+    }
+
+}
+

Propchange: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java?rev=984658&r1=984657&r2=984658&view=diff
==============================================================================
--- openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java (original)
+++ openejb/branches/openejb-jcdi/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java Thu Aug 12 07:00:42 2010
@@ -16,198 +16,265 @@
  */
 package org.apache.openejb.cdi;
 
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.ProcessAnnotatedType;
-import javax.enterprise.inject.spi.SessionBeanType;
-
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
 import org.apache.openejb.DeploymentInfo;
-import org.apache.openejb.assembler.classic.AppInfo;
-import org.apache.openejb.assembler.classic.EjbJarInfo;
-import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.ProxyInterfaceResolver;
+import org.apache.openejb.core.AppContext;
+import org.apache.openejb.core.CoreUserTransaction;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.ContainerSystem;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
-import org.apache.webbeans.ejb.common.util.EjbDefinitionUtility;
-import org.apache.webbeans.ejb.common.util.EjbUtility;
-import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.config.WebBeansFinder;
+import org.apache.webbeans.container.InjectionResolver;
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.ee.event.TransactionalEventNotifier;
+import org.apache.webbeans.ejb.common.component.BaseEjbBean;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.jms.JMSManager;
+import org.apache.webbeans.plugins.PluginLoader;
+import org.apache.webbeans.portable.AnnotatedElementFactory;
+import org.apache.webbeans.portable.events.ExtensionLoader;
+import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
+import org.apache.webbeans.proxy.JavassistProxyFactory;
 import org.apache.webbeans.spi.SecurityService;
 import org.apache.webbeans.spi.TransactionService;
 import org.apache.webbeans.spi.plugins.AbstractOwbPlugin;
 import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
 import org.apache.webbeans.spi.plugins.OpenWebBeansJavaEEPlugin;
+import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.WebBeansUtil;
 
-public class CdiPlugin extends AbstractOwbPlugin implements OpenWebBeansJavaEEPlugin,OpenWebBeansEjbPlugin {
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.TransactionPhase;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.ObserverMethod;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.naming.NamingException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+import java.lang.annotation.Annotation;
+import java.security.Principal;
+import java.util.List;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+public class CdiPlugin extends AbstractOwbPlugin implements OpenWebBeansJavaEEPlugin, OpenWebBeansEjbPlugin, TransactionService, SecurityService {
 
-    private Logger logger = Logger.getInstance(LogCategory.OPENEJB.createChild("cdi"),CdiPlugin.class);
-    
-    private AppInfo appModule;
-    private ClassLoader classLoader;
-    private final Map<Integer, Set<Class<?>>> beans = new HashMap<Integer, Set<Class<?>>>();
-    private final Map<Class<?>, String> beanIds = new HashMap<Class<?>, String>();
-    private final SecurityService SECURITY_SERVICE = new CdiSecurityService();
-    public final TransactionService TRANSACTION_SERVICE = new CdiTransactionService();
+    private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB.createChild("cdi"), CdiPlugin.class);
+    private AppContext appContext;
+    private Set<Class<?>> beans;
+
+    private CdiAppContextsService contexsServices;
 
     @Override
     public void shutDown() throws Exception {
         super.shutDown();
-        this.beanIds.clear();
         this.beans.clear();
     }
 
-    public void setClassLoader(ClassLoader classLoader) {
-        this.classLoader = classLoader;
+    public void setAppContext(AppContext appContext) {
+        this.appContext = appContext;
     }
 
-    public void setAppModule(AppInfo appModule) {
-        this.appModule = appModule;
-    }
-
-    public void configureDeployments() {
-        List<EjbJarInfo> ejbModules = appModule.ejbJars;
-        for (EjbJarInfo ejbModule : ejbModules) {
-            List<EnterpriseBeanInfo> enterpriseBeans = ejbModule.enterpriseBeans;
-            for (EnterpriseBeanInfo eb : enterpriseBeans) {
-                try {
-                    Class<?> clazz = this.classLoader.loadClass(eb.ejbClass);
-                    beanIds.put(clazz, eb.ejbDeploymentId);
-                    putClass(eb.type, clazz);
-                } catch (Exception e) {
-                    String error = "Error is occured while getting information from ejb modules";
-                    logger.error(error, e);
-                    throw new RuntimeException(error, e);
-                }
+    public void configureDeployments(List<DeploymentInfo> ejbDeployments) {
+        WeakHashMap<Class<?>, Object> beans = new WeakHashMap<Class<?>, Object>();
+        for (DeploymentInfo deployment : ejbDeployments) {
+            if (deployment.getComponentType().isSession()) {
+                beans.put(deployment.getBeanClass(), null);
             }
         }
+        this.beans = beans.keySet();
     }
 
-    private void putClass(Integer type, Class<?> clazz) {
-        Set<Class<?>> classes = beans.get(type);
-        if (classes == null) {
-            classes = new HashSet<Class<?>>();
-            beans.put(type, classes);
-        }
+    public CdiAppContextsService getContexsServices() {
+        return contexsServices;
+    }
 
-        classes.add(clazz);
+    public void startup() {
+        this.contexsServices = (CdiAppContextsService) WebBeansFinder.getSingletonInstance("org.apache.openejb.cdi.CdiAppContextsService", appContext.getClassLoader());
+        this.contexsServices.init(null);
     }
 
-    @Override
-    public <T> T getSupportedService(Class<T> serviceClass) {
-        if (serviceClass == TransactionService.class) {
-            return serviceClass.cast(TRANSACTION_SERVICE);
-        } else if (serviceClass == SecurityService.class) {
-            return serviceClass.cast(SECURITY_SERVICE);
+    public void stop() throws OpenEJBException {
+        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+        try {
+            //Setting context class loader for cleaning
+            Thread.currentThread().setContextClassLoader(appContext.getClassLoader());
+
+            //Fire shut down
+            appContext.getBeanManager().fireEvent(new BeforeShutdownImpl(), new Annotation[0]);
+
+            //Destroys context
+            this.contexsServices.destroy(null);
+
+            //Free all plugin resources
+            PluginLoader.getInstance().shutDown();
+
+            //Clear extensions
+            ExtensionLoader.getInstance().clear();
+
+            //Delete Resolutions Cache
+            InjectionResolver.getInstance().clearCaches();
+
+            //Delte proxies
+            JavassistProxyFactory.getInstance().clear();
+
+            //Delete AnnotateTypeCache
+            AnnotatedElementFactory.getInstance().clear();
+
+            //JMs Manager clear
+            JMSManager.getInstance().clear();
+
+            //Clear the resource injection service
+            CdiResourceInjectionService injectionServices = (CdiResourceInjectionService) WebBeansFinder.getSingletonInstance("org.apache.openejb.cdi.CdiResourceInjectionService", appContext.getClassLoader());
+            injectionServices.clear();
+
+            //ContextFactory cleanup
+            ContextFactory.cleanUpContextFactory();
+
+            //Clear singleton list
+            WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
+
+
+        } catch (Exception e) {
+            throw new OpenEJBException(e);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCl);
         }
+    }
 
-        return null;
+    @Override
+    public <T> T getSupportedService(Class<T> serviceClass) {
+        return supportService(serviceClass) ? serviceClass.cast(this) : null;
     }
 
     @Override
     public void isManagedBean(Class<?> clazz) throws Exception {
-        if (isSessionBean(clazz)) {
-            throw new WebBeansConfigurationException("Managed Bean implementation class : "
-                    + clazz.getName() + " can not be sesion bean class");
-        }
-
     }
 
     @Override
     public boolean supportService(Class<?> serviceClass) {
-        if ((serviceClass == TransactionService.class) || serviceClass == SecurityService.class) {
-            return true;
-        }
-
-        return false;
+        return serviceClass == TransactionService.class || serviceClass == SecurityService.class;
     }
 
     @Override
-    public <T> Bean<T> defineSessionBean(Class<T> clazz,
-            ProcessAnnotatedType<T> processAnnotateTypeEvent) {
-        if (!isSessionBean(clazz)) {
-            throw new IllegalArgumentException("Given class is not an session bean class");
-        }
-
-        ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
-        DeploymentInfo info = null;
-        SessionBeanType type = SessionBeanType.STATELESS;
-
-        info = cs.getDeploymentInfo(this.beanIds.get(clazz));
-
-        CdiEjbBean<T> bean = new CdiEjbBean<T>(clazz);
-        bean.setDeploymentInfo(info);
-        bean.setEjbType(type);
+    public Object getSessionBeanProxy(Bean<?> bean, Class<?> interfce, CreationalContext<?> creationalContext) {
+        final CdiEjbBean ejbBean = (CdiEjbBean) bean;
+        final DeploymentInfo deployment = ejbBean.getDeploymentInfo();
+
+        final Class beanClass = deployment.getBeanClass();
+        final List<Class> localInterfaces = deployment.getBusinessLocalInterfaces();
+
+        List<Class> interfaces = ProxyInterfaceResolver.getInterfaces(beanClass, interfce, localInterfaces);
+        DeploymentInfo.BusinessLocalHome home = deployment.getBusinessLocalHome(interfaces);
+        return home.create();
+
+//        try {
+//
+//            ((CdiEjbBean<Object>) bean).setIface(iface);
+//
+//            Class<?> clazz = JavassistProxyFactory.getInstance().getEjbBeanProxyClass((BaseEjbBean<Object>) (CdiEjbBean<Object>) bean);
+//
+//            if (clazz == null) {
+//                ProxyFactory factory = new ProxyFactory();
+//                factory.setInterfaces(new Class[]{(Class<?>) iface});
+//                clazz = JavassistProxyFactory.getInstance().defineEjbBeanProxyClass((BaseEjbBean<Object>) (CdiEjbBean<Object>) bean, factory);
+//            }
+//
+//            Object proxyInstance = (Object) ClassUtil.newInstance(clazz);
+//
+//            EjbBeanProxyHandler handler = new EjbBeanProxyHandler((CdiEjbBean<Object>) bean, creationalContext);
+//
+//            ((ProxyObject) proxyInstance).setHandler(handler);
+//
+//            return proxyInstance;
+//
+//        } catch (Exception e) {
+//            throw new WebBeansException(e);
+//        }
+    }
 
-        EjbUtility.fireEvents(clazz, bean, processAnnotateTypeEvent);
+    @Override
+    public boolean isSessionBean(Class<?> clazz) {
+        return beans.contains(clazz);
+    }
 
-        return bean;
+    @Override
+    public <T> Bean<T> defineSessionBean(Class<T> clazz, ProcessAnnotatedType<T> processAnnotateTypeEvent) {
+        throw new IllegalStateException("Statement should never be reached");
+    }
 
+    @Override
+    public boolean isSingletonBean(Class<?> clazz) {
+        throw new IllegalStateException("Statement should never be reached");
     }
 
     @Override
-    public Object getSessionBeanProxy(Bean<?> bean, Class<?> iface,
-            CreationalContext<?> creationalContext) {
-        return EjbDefinitionUtility.defineEjbBeanProxy((CdiEjbBean<?>) bean, iface,
-                creationalContext);
+    public boolean isStatefulBean(Class<?> clazz) {
+        throw new IllegalStateException("Statement should never be reached");
     }
 
     @Override
-    public boolean isSessionBean(Class<?> clazz) {
+    public boolean isStatelessBean(Class<?> clazz) {
+        throw new IllegalStateException("Statement should never be reached");
+    }
 
-        for (Entry<Integer, Set<Class<?>>> entries : this.beans.entrySet()) {
-            Set<Class<?>> classes = entries.getValue();
-            if (classes.contains(clazz)) {
-                return true;
+    @Override
+    public Transaction getTransaction() {
+        TransactionManager manager = getTransactionManager();
+        if (manager != null) {
+            try {
+                return manager.getTransaction();
+            } catch (SystemException e) {
+                logger.error("Error is occured while getting transaction instance from system", e);
             }
         }
 
-        return false;
+        return null;
     }
 
     @Override
-    public boolean isSingletonBean(Class<?> clazz) {
-        for (Entry<Integer, Set<Class<?>>> entries : this.beans.entrySet()) {
-            Set<Class<?>> classes = entries.getValue();
-            for (Class<?> clazzFound : classes) {
-                if (clazzFound == clazz && entries.getKey().equals(EnterpriseBeanInfo.SINGLETON)) {
-                    return true;
-                }
-            }
-        }
-
-        return false;
+    public TransactionManager getTransactionManager() {
+        // TODO Convert to final field
+        return SystemInstance.get().getComponent(TransactionManager.class);
     }
 
     @Override
-    public boolean isStatefulBean(Class<?> clazz) {
-        for (Entry<Integer, Set<Class<?>>> entries : this.beans.entrySet()) {
-            Set<Class<?>> classes = entries.getValue();
-            for (Class<?> clazzFound : classes) {
-                if (clazzFound == clazz && entries.getKey().equals(EnterpriseBeanInfo.STATEFUL)) {
-                    return true;
-                }
-            }
+    public UserTransaction getUserTransaction() {
+        UserTransaction ut = null;
+
+        // TODO Convert to final field
+        ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+        
+        try {
+            ut = (UserTransaction) containerSystem.getJNDIContext().lookup("comp/UserTransaction");
+        } catch (NamingException e) {
+            logger.debug("User transaction is not bound to context, lets create it");
+            ut = new CoreUserTransaction(getTransactionManager());
+
         }
-        return false;
+        return ut;
     }
 
     @Override
-    public boolean isStatelessBean(Class<?> clazz) {
-        for (Entry<Integer, Set<Class<?>>> entries : this.beans.entrySet()) {
-            Set<Class<?>> classes = entries.getValue();
-            for (Class<?> clazzFound : classes) {
-                if (clazzFound == clazz && entries.getKey().equals(EnterpriseBeanInfo.STATELESS)) {
-                    return true;
-                }
-            }
+    public void registerTransactionSynchronization(TransactionPhase phase, ObserverMethod<? super Object> observer, Object event) throws Exception {
+        TransactionalEventNotifier.registerTransactionSynchronization(phase, observer, event);
+    }
+
+    @Override
+    public Principal getCurrentPrincipal() {
+
+        // TODO Convert to final field
+        org.apache.openejb.spi.SecurityService<?> service = SystemInstance.get().getComponent(org.apache.openejb.spi.SecurityService.class);
+        if (service != null) {
+            return service.getCallerPrincipal();
         }
-        return false;
+
+        return null;
     }
 }