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 2011/06/20 08:00:07 UTC

svn commit: r1137507 [1/2] - in /openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/ container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ container/openejb-core/src/main/java/org/apache/openejb/cdi/ co...

Author: dblevins
Date: Mon Jun 20 06:00:06 2011
New Revision: 1137507

URL: http://svn.apache.org/viewvc?rev=1137507&view=rev
Log:
Reworked: OPENEJB-1578 EJB Constructor Injection via CDI
OPENEJB-1601 EJB Interceptor Constructor Injection
OPENEJB-1584 @Inject Instance<java.security.Principal> built-in bean
OPENEJB-1589 @ApplicationScoped Session bean dependencies
OPENEJB-1205 Expose Stateful remove method from proxy for Scope management
OPENEJB-1581 InjectionTarget replacement for EJBs
OPENEJB-1587 @Remote disabled for @Stateful beans in a non @Dependent scope
OPENEJB-1588 @Interceptors invoked before @InterceptorBinding interceptors
OPENEJB-1590 @PostConstruct called after @Inject
OPENEJB-1591 @Inject called after @Resource, @EJB, @PersistenceContext and @PersistenceUnit
OPENEJB-1592 @Inject support for @WebService beans


Added:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ConstructorInjectionBean.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/NewCdiEjbBean.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/ApplicationScopedTest.java
      - copied, changed from r1135908, openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/InjectionTest.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulInternalRemoveTest.java
      - copied, changed from r1135908, openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java
    openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/InstanceContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
    openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/Report.java
    openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/failing.xml
    openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java Mon Jun 20 06:00:06 2011
@@ -38,11 +38,12 @@ import javax.ejb.LockType;
 import javax.ejb.MessageDrivenBean;
 import javax.ejb.TimedObject;
 import javax.ejb.Timer;
-import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.context.spi.CreationalContext;
 import javax.naming.Context;
 import javax.persistence.EntityManagerFactory;
 
 import org.apache.openejb.cdi.CdiEjbBean;
+import org.apache.openejb.cdi.ConstructorInjectionBean;
 import org.apache.openejb.cdi.OWBInjector;
 import org.apache.openejb.core.ExceptionType;
 import org.apache.openejb.core.InstanceContext;
@@ -60,6 +61,7 @@ import org.apache.openejb.core.transacti
 import org.apache.openejb.core.transaction.TransactionType;
 import org.apache.openejb.util.Duration;
 import org.apache.openejb.util.Index;
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.xbean.recipe.ConstructionException;
 
@@ -78,6 +80,10 @@ public class BeanContext extends Deploym
         Object create();
     }
 
+    public interface Removable {
+        void $$remove();
+    }
+
     public interface ServiceEndpoint {
     }
 
@@ -1149,32 +1155,37 @@ public class BeanContext extends Deploym
         ThreadContext callContext = new ThreadContext(this, null, Operation.INJECTION);
         ThreadContext oldContext = ThreadContext.enter(callContext);
 
-        CdiEjbBean<?> owbBean = (CdiEjbBean<?>) get(Bean.class);
-        WebBeansContext webBeansContext = owbBean == null? WebBeansContext.getInstance(): owbBean.getWebBeansContext();
+        WebBeansContext webBeansContext = getModuleContext().getAppContext().getWebBeansContext();
+
+        AbstractInjectionTargetBean<Object> beanDefinition = get(CdiEjbBean.class);
+
+        final ConstructorInjectionBean<Object> beanConstructor = new ConstructorInjectionBean<Object>(webBeansContext, beanClass);
+
+        if (beanDefinition == null) {
+            beanDefinition = beanConstructor;
+        }
 
         try {
+            final CreationalContext<Object> creationalContext;
+            if (get(CreationalContext.class) == null) {
+                creationalContext = webBeansContext.getBeanManagerImpl().createCreationalContext(beanDefinition);
+            } else {
+                creationalContext = get(CreationalContext.class);
+            }
+
             final Context ctx = this.getJndiEnc();
             final Class beanClass = this.getBeanClass();
 
             // Create bean instance
 
-            //TODO OPENEJB-1578 owbBean == null for MDBs.  Figure out how to get the Bean for an MDB and allow constructor injection there too.
-            InjectionProcessor injectionProcessor;
-            if (owbBean != null) {
-                injectionProcessor = new InjectionProcessor(owbBean.create(), this.getInjections(), InjectionProcessor.unwrap(ctx));
-            } else {
-                injectionProcessor = new InjectionProcessor(beanClass, this.getInjections(), null, null, org.apache.openejb.InjectionProcessor.unwrap(ctx));
-            }
-            final Object bean = injectionProcessor.createInstance();
+            final InjectionProcessor injectionProcessor = new InjectionProcessor(beanConstructor.create(creationalContext), this.getInjections(), InjectionProcessor.unwrap(ctx));
 
-            // TODO we likely don't want to create a new one each time -- investigate the destroy() method
-            try {
-                OWBInjector beanInjector = new OWBInjector(webBeansContext);
-                beanInjector.inject(bean);
-            } catch (Throwable t) {
-                // TODO handle this differently
-                // this is temporary till the injector can be rewritten
-            }
+            final Object beanInstance = injectionProcessor.createInstance();
+
+            beanDefinition.injectSuperFields(beanInstance, creationalContext);
+            beanDefinition.injectSuperMethods(beanInstance, creationalContext);
+            beanDefinition.injectFields(beanInstance, creationalContext);
+            beanDefinition.injectMethods(beanInstance, creationalContext);
 
             // Create interceptors
             final HashMap<String, Object> interceptorInstances = new HashMap<String, Object>();
@@ -1191,14 +1202,16 @@ public class BeanContext extends Deploym
                 }
 
                 final Class clazz = interceptorData.getInterceptorClass();
-                final InjectionProcessor interceptorInjector = new InjectionProcessor(clazz, this.getInjections(), org.apache.openejb.InjectionProcessor.unwrap(ctx));
+
+                final ConstructorInjectionBean interceptorConstructor = new ConstructorInjectionBean(webBeansContext, clazz);
+                final InjectionProcessor interceptorInjector = new InjectionProcessor(interceptorConstructor.create(creationalContext), this.getInjections(), org.apache.openejb.InjectionProcessor.unwrap(ctx));
                 try {
                     final Object interceptorInstance = interceptorInjector.createInstance();
 
                     // TODO we likely don't want to create a new one each time -- investigate the destroy() method
                     try {
                         OWBInjector interceptorCdiInjector = new OWBInjector(webBeansContext);
-                        interceptorCdiInjector.inject(interceptorInstance);
+                        interceptorCdiInjector.inject(interceptorInstance, creationalContext);
                     } catch (Throwable t) {
                         // TODO handle this differently
                         // this is temporary till the injector can be rewritten
@@ -1210,12 +1223,12 @@ public class BeanContext extends Deploym
                 }
             }
 
-            interceptorInstances.put(beanClass.getName(), bean);
+            interceptorInstances.put(beanClass.getName(), beanInstance);
 
             // Invoke post construct method
             callContext.setCurrentOperation(Operation.POST_CONSTRUCT);
             final List<InterceptorData> callbackInterceptors = this.getCallbackInterceptors();
-            final InterceptorStack postConstruct = new InterceptorStack(bean, null, Operation.POST_CONSTRUCT, callbackInterceptors, interceptorInstances);
+            final InterceptorStack postConstruct = new InterceptorStack(beanInstance, null, Operation.POST_CONSTRUCT, callbackInterceptors, interceptorInstances);
             
             //Transaction Demarcation for Singleton PostConstruct method
             TransactionType transactionType;
@@ -1245,7 +1258,7 @@ public class BeanContext extends Deploym
                 EjbTransactionUtil.afterInvoke(transactionPolicy, callContext);
             }
 
-            return new InstanceContext(this, bean, interceptorInstances);
+            return new InstanceContext(this, beanInstance, interceptorInstances, creationalContext);
         } finally {
             ThreadContext.exit(oldContext);
         }                        

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java Mon Jun 20 06:00:06 2011
@@ -273,6 +273,7 @@ public class InterceptorBindingBuilder {
         for (CallbackInfo callbackInfo : callbackInfos) {
             try {
                 Method method = getMethod(clazz, callbackInfo.method, InvocationContext.class);
+                SetAccessible.on(method);
                 if (callbackInfo.className == null && method.getDeclaringClass().equals(clazz) && !methods.contains(method)){
                     methods.add(method);
                 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java Mon Jun 20 06:00:06 2011
@@ -22,6 +22,7 @@ import org.apache.webbeans.context.Abstr
 import org.apache.webbeans.context.ApplicationContext;
 import org.apache.webbeans.context.DependentContext;
 import org.apache.webbeans.context.RequestContext;
+import org.apache.webbeans.context.SessionContext;
 import org.apache.webbeans.context.SingletonContext;
 import org.apache.webbeans.spi.ContextsService;
 
@@ -29,6 +30,7 @@ import javax.enterprise.context.Applicat
 import javax.enterprise.context.ContextException;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
 import javax.enterprise.context.spi.Context;
 import javax.inject.Singleton;
 import java.lang.annotation.Annotation;
@@ -36,13 +38,12 @@ 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);
-    private static ThreadLocal<RequestContext> requestContext = new ThreadLocal<RequestContext>();
-    private static ThreadLocal<ApplicationContext> applicationContext = new ThreadLocal<ApplicationContext>();
-    private static ThreadLocal<SingletonContext> singletonContext = new ThreadLocal<SingletonContext>();
-    private static DependentContext dependentContext = new DependentContext();
+    private ThreadLocal<RequestContext> requestContext = new ThreadLocal<RequestContext>();
+    private ThreadLocal<SessionContext> sessionContext = new ThreadLocal<SessionContext>();
+    private DependentContext dependentContext = new DependentContext();
 
-    private volatile ApplicationContext currentApplicationContext = null;
-    private volatile SingletonContext currentSingletonContext = null;
+    private final ApplicationContext currentApplicationContext = new ApplicationContext();
+    private final SingletonContext currentSingletonContext = new SingletonContext();
 
     public CdiAppContextsService() {
         dependentContext.setActive(true);
@@ -50,11 +51,8 @@ public class CdiAppContextsService exten
 
     @Override
     public void init(Object initializeObject) {
-        //Start application context
-        startContext(ApplicationScoped.class, initializeObject);
-
-        //Start signelton context
-        startContext(Singleton.class, initializeObject);
+        currentApplicationContext.setActive(true);
+        currentSingletonContext.setActive(true);
     }
 
     @Override
@@ -62,8 +60,9 @@ public class CdiAppContextsService exten
         if (supportsContext(scopeType)) {
             if (scopeType.equals(RequestScoped.class)) {
                 initRequestContext();
+            } else if (scopeType.equals(SessionScoped.class)) {
+                initSessionContext();
             } else if (scopeType.equals(ApplicationScoped.class)) {
-                initApplicationContext();
             } else if (scopeType.equals(Dependent.class)) {
                 // Do nothing
             } else if (scopeType.equals(Singleton.class)) {
@@ -84,6 +83,8 @@ public class CdiAppContextsService exten
         if (supportsContext(scopeType)) {
             if (scopeType.equals(RequestScoped.class)) {
                 destroyRequestContext();
+            } else if (scopeType.equals(SessionScoped.class)) {
+                destroySessionContext();
             } else if (scopeType.equals(ApplicationScoped.class)) {
                 destroyApplicationContext();
             } else if (scopeType.equals(Dependent.class)) {
@@ -105,82 +106,62 @@ public class CdiAppContextsService exten
     public Context getCurrentContext(Class<? extends Annotation> scopeType) {
         if (supportsContext(scopeType)) {
             if (scopeType.equals(RequestScoped.class)) {
-                return requestContext.get();
+                return getRequestContext();
+            } else if (scopeType.equals(SessionScoped.class)) {
+                return getSessionContext();
             } else if (scopeType.equals(ApplicationScoped.class)) {
-                return applicationContext.get();
+                return currentApplicationContext;
             } else if (scopeType.equals(Dependent.class)) {
                 return dependentContext;
             } else {
-                return singletonContext.get();
+                return currentSingletonContext;
             }
         }
 
         return null;
     }
 
-    private void initApplicationContext() {
-        if (this.currentApplicationContext != null) {
-            applicationContext.set(this.currentApplicationContext);
-        } else {
-            ApplicationContext currentApplicationContext = new ApplicationContext();
-            currentApplicationContext.setActive(true);
+    private Context getRequestContext() {
+        RequestContext context = requestContext.get();
+        if (context == null) {
+
+            context = new RequestContext();
+            context.setActive(true);
 
-            this.currentApplicationContext = currentApplicationContext;
-            applicationContext.set(currentApplicationContext);
+            requestContext.set(context);
         }
+        return context;
     }
 
-    private void destroyApplicationContext() {
-        // look for thread local
-        // this can be set by initRequestContext
-        ApplicationContext context = this.currentApplicationContext;
-
-        // using in tests
+    private Context getSessionContext() {
+        SessionContext context = sessionContext.get();
         if (context == null) {
-            context = applicationContext.get();
-        }
 
-        // Destroy context
-        if (context != null) {
-            context.destroy();
+            context = new SessionContext();
+            context.setActive(true);
+
+            sessionContext.set(context);
         }
+        return context;
+    }
 
-        this.currentApplicationContext = null;
+    private void destroyApplicationContext() {
+        // look for thread local
+        // this can be set by initRequestContext
+//        this.currentApplicationContext.destroy();
     }
 
     private void initSingletonContext() {
-        if (this.currentSingletonContext != null) {
-            singletonContext.set(currentSingletonContext);
-        } else {
-            SingletonContext context = new SingletonContext();
-            context.setActive(true);
-            this.currentSingletonContext = context;
-
-            singletonContext.set(context);
-        }
-
     }
 
     private void destroySingletonContext() {
-        SingletonContext context = this.currentSingletonContext;
-
-        // 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.destroy();
     }
 
     @Override
     public boolean supportsContext(Class<? extends Annotation> scopeType) {
         if (scopeType.equals(RequestScoped.class)
+                || scopeType.equals(SessionScoped.class)
                 || scopeType.equals(ApplicationScoped.class)
                 || scopeType.equals(Dependent.class)
                 || scopeType.equals(Singleton.class)) {
@@ -196,12 +177,6 @@ public class CdiAppContextsService exten
         rq.setActive(true);
 
         requestContext.set(rq);
-
-        // Init threadLocal application context
-        initApplicationContext();
-
-        // Init threadlocal singleton context
-        initSingletonContext();
     }
 
     private void destroyRequestContext() {
@@ -215,38 +190,43 @@ public class CdiAppContextsService exten
 
         // Remove
         requestContext.remove();
-        requestContext.set(null);
+    }
+
+    private void initSessionContext() {
 
-        // Remove singleton and application contexts
-        singletonContext.remove();
-        singletonContext.set(null);
+        SessionContext rq = new SessionContext();
+        rq.setActive(true);
+
+        sessionContext.set(rq);
+    }
 
-        applicationContext.remove();
-        applicationContext.set(null);
+    private void destroySessionContext() {
+        // Get context
+        SessionContext context = sessionContext.get();
+
+        // Destroy context
+        if (context != null) {
+            context.destroy();
+        }
 
+        // Remove
+        sessionContext.remove();
     }
 
     public void destroy(Object destroyObject) {
-        //Destroy application context
-        endContext(ApplicationScoped.class, destroyObject);
-
-        //Destroy singleton context
-        endContext(Singleton.class, 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();
 
         //Thread local values to null
         requestContext.set(null);
-        applicationContext.set(null);
-        singletonContext.set(null);
-
     }
 
 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java Mon Jun 20 06:00:06 2011
@@ -20,24 +20,31 @@ import org.apache.openejb.BeanContext;
 import org.apache.openejb.BeanType;
 import org.apache.openejb.assembler.classic.ProxyInterfaceResolver;
 import org.apache.webbeans.annotation.DependentScopeLiteral;
+import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.component.WebBeansType;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.ejb.common.component.BaseEjbBean;
 import org.apache.webbeans.inject.InjectableConstructor;
 
 import javax.ejb.Remove;
+import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.New;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.SessionBeanType;
+import javax.enterprise.util.AnnotationLiteral;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 public class CdiEjbBean<T> extends BaseEjbBean<T> {
     private final BeanContext beanContext;
-    private final CreationalContext<T> creationalContext;
-    private final Constructor<T> constructor;
 
     public CdiEjbBean(BeanContext beanContext, WebBeansContext webBeansContext) {
         super(beanContext.getBeanClass(), toSessionType(beanContext.getComponentType()), webBeansContext);
@@ -52,13 +59,6 @@ public class CdiEjbBean<T> extends BaseE
         for (Class clazz : beanContext.getBusinessLocalInterfaces()) addApiType(clazz);
 
         beanContext.set(Bean.class, this);
-
-        //TODO correct scope not clear
-        setImplScopeType(new DependentScopeLiteral());
-        BeanManagerImpl beanManagerImpl = webBeansContext.getBeanManagerImpl();
-        creationalContext = beanManagerImpl.createCreationalContext(this);
-        constructor = webBeansContext.getWebBeansUtil().defineConstructor(getReturnType());
-        webBeansContext.getDefinitionUtil().addConstructorInjectionPointMetaData(this, constructor);
     }
 
     @Override
@@ -72,12 +72,6 @@ public class CdiEjbBean<T> extends BaseE
         return this.beanContext;
     }
 
-    public T create() {
-        InjectableConstructor<T> ic = new InjectableConstructor<T>(constructor, this, creationalContext);
-
-        return ic.doInjection();
-    }
-
     private static SessionBeanType toSessionType(BeanType beanType) {
         switch (beanType) {
         case SINGLETON:
@@ -107,6 +101,7 @@ public class CdiEjbBean<T> extends BaseE
         List<Class> interfaces = ProxyInterfaceResolver.getInterfaces(beanContext.getBeanClass(), mainInterface, classes);
         BeanContext.BusinessLocalHome home = beanContext.getBusinessLocalHome(interfaces, mainInterface);
 
+        beanContext.set(CreationalContext.class, creationalContext);
         return (T) home.create();
     }
 
@@ -130,6 +125,21 @@ public class CdiEjbBean<T> extends BaseE
     }
 
     @Override
+    protected void destroyComponentInstance(T instance, CreationalContext<T> creational) {
+
+        if (instance instanceof BeanContext.Removable) {
+            BeanContext.Removable removable = (BeanContext.Removable) instance;
+            removable.$$remove();
+        }
+
+    }
+
+    @Override
+    protected void destroyStatefulSessionBeanInstance(T proxyInstance, Object ejbInstance) {
+        super.destroyStatefulSessionBeanInstance(proxyInstance, ejbInstance);
+    }
+
+    @Override
     public List<Method> getRemoveMethods() {
         // Should we delegate to super and merge both?
         return findRemove(beanContext.getBeanClass(), beanContext.getBusinessLocalInterface());

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiInterceptor.java Mon Jun 20 06:00:06 2011
@@ -67,7 +67,7 @@ public class CdiInterceptor implements S
             }
         };
 
-        callable = new ScopeActivator(callable, ApplicationScoped.class);
+//        callable = new ScopeActivator(callable, ApplicationScoped.class);
         callable = new ScopeActivator(callable, RequestScoped.class);
         return callable.call();
     }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java Mon Jun 20 06:00:06 2011
@@ -38,6 +38,7 @@ import org.apache.webbeans.spi.plugins.O
 import org.apache.webbeans.spi.plugins.OpenWebBeansJavaEEPlugin;
 import org.apache.webbeans.util.WebBeansUtil;
 
+import javax.ejb.Stateful;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.TransactionPhase;
 import javax.enterprise.inject.spi.Bean;
@@ -215,7 +216,8 @@ public class CdiPlugin extends AbstractO
 
 	@Override
 	public boolean isStatefulBean(Class<?> clazz) {
-		throw new IllegalStateException("Statement should never be reached");
+        // TODO Make the EjbPlugin pass in the Bean<T> instance
+		return clazz.isAnnotationPresent(Stateful.class);
 	}
 
 	@Override
@@ -349,4 +351,36 @@ public class CdiPlugin extends AbstractO
 		return System.getProperties();
 	}
 
+    @Override
+    public Method resolveViewMethod(Bean<?> component, Method declaredMethod) {
+//        if (true)return declaredMethod;
+        if (!(component instanceof CdiEjbBean)) return declaredMethod;
+
+        CdiEjbBean cdiEjbBean = (CdiEjbBean) component;
+
+        final BeanContext beanContext = cdiEjbBean.getBeanContext();
+
+        for (Class intface : beanContext.getBusinessLocalInterfaces()) {
+            try {
+                return intface.getMethod(declaredMethod.getName(), declaredMethod.getParameterTypes());
+            } catch (NoSuchMethodException e) {
+            }
+        }
+        return declaredMethod;
+    }
+
+    //TODO Delete if we end up not needing this
+    public Method resolveBeanMethod(Bean<?> component, Method declaredMethod) {
+        if (!(component instanceof CdiEjbBean)) return declaredMethod;
+
+        CdiEjbBean cdiEjbBean = (CdiEjbBean) component;
+
+        final BeanContext beanContext = cdiEjbBean.getBeanContext();
+
+        try {
+            return beanContext.getBeanClass().getMethod(declaredMethod.getName(), declaredMethod.getParameterTypes());
+        } catch (NoSuchMethodException e) {
+            return declaredMethod;
+        }
+    }
 }

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ConstructorInjectionBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ConstructorInjectionBean.java?rev=1137507&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ConstructorInjectionBean.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ConstructorInjectionBean.java Mon Jun 20 06:00:06 2011
@@ -0,0 +1,47 @@
+/**
+ * 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.webbeans.component.AbstractInjectionTargetBean;
+import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.component.WebBeansType;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.inject.InjectableConstructor;
+
+import javax.enterprise.context.spi.CreationalContext;
+import java.lang.reflect.Constructor;
+
+/**
+* @version $Rev$ $Date$
+*/
+public class ConstructorInjectionBean<T> extends AbstractInjectionTargetBean<T> {
+
+    private final Constructor<T> constructor;
+
+    public ConstructorInjectionBean(WebBeansContext webBeansContext, Class<T> returnType) {
+        super(WebBeansType.DEPENDENT, returnType, webBeansContext);
+
+        constructor = webBeansContext.getWebBeansUtil().defineConstructor(getReturnType());
+        webBeansContext.getDefinitionUtil().addConstructorInjectionPointMetaData(this, constructor);
+    }
+
+    @Override
+    protected T createInstance(CreationalContext<T> tCreationalContext) {
+        InjectableConstructor<T> ic = new InjectableConstructor<T>(constructor, this, tCreationalContext);
+        return ic.doInjection();
+    }
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/NewCdiEjbBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/NewCdiEjbBean.java?rev=1137507&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/NewCdiEjbBean.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/NewCdiEjbBean.java Mon Jun 20 06:00:06 2011
@@ -0,0 +1,67 @@
+/**
+ * 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.webbeans.annotation.NewLiteral;
+import org.apache.webbeans.component.NewBean;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.New;
+import javax.enterprise.util.AnnotationLiteral;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+* @version $Rev$ $Date$
+*/
+public class NewCdiEjbBean<T> extends CdiEjbBean<T> implements NewBean<T> {
+
+    public NewCdiEjbBean(CdiEjbBean<T> that) {
+        super(that.getBeanContext(), that.getWebBeansContext());
+
+        this.getImplQualifiers().add(new NewLiteral(getReturnType()));
+
+
+        this.setName(null);
+        this.getInjectedFields().addAll(that.getInjectedFields());
+        this.getInjectedFromSuperFields().addAll(that.getInjectedFromSuperFields());
+        this.getInjectedFromSuperMethods().addAll(that.getInjectedFromSuperMethods());
+        this.getInjectedMethods().addAll(that.getInjectedMethods());
+    }
+
+    @Override
+    public Class<? extends Annotation> getScope() {
+        return Dependent.class;
+    }
+
+    @Override
+    public Set<Class<? extends Annotation>> getStereotypes() {
+        return Collections.EMPTY_SET;
+    }
+
+    @Override
+    public Set<Method> getObservableMethods() {
+        return Collections.EMPTY_SET;
+    }
+
+    @Override
+    public String getId() {
+        return super.getId()+"@NewBean";
+    }
+}

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java Mon Jun 20 06:00:06 2011
@@ -40,6 +40,7 @@ import javax.enterprise.inject.spi.Exten
 import org.apache.openejb.AppContext;
 import org.apache.openejb.BeanContext;
 import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.webbeans.component.NewBean;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.config.WebBeansFinder;
@@ -242,6 +243,10 @@ public class OpenEJBLifecycle implements
                 EjbUtility.fireEvents((Class<Object>) implClass, bean, (ProcessAnnotatedTypeImpl<Object>) processAnnotatedEvent);
 
                 webBeansContext.getWebBeansUtil().setInjectionTargetBeanEnableFlag(bean);
+
+
+//                final BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
+//                manager.addBean(new NewCdiEjbBean<Object>(bean));
             }
 
             //Check Specialization
@@ -281,6 +286,15 @@ public class OpenEJBLifecycle implements
         logger.info(OWBLogConst.INFO_0001, Long.toString(System.currentTimeMillis() - begin));
     }
 
+    public static class NewEjbBean<T> extends CdiEjbBean<T> implements NewBean<T> {
+
+        public NewEjbBean(BeanContext beanContext, WebBeansContext webBeansContext) {
+            super(beanContext, webBeansContext);
+        }
+
+
+    }
+
     private void loadExtensions(AppContext appContext) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
         final ExtensionLoader extensionLoader = webBeansContext.getExtensionLoader();
 

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseSessionContext.java Mon Jun 20 06:00:06 2011
@@ -136,6 +136,7 @@ public abstract class BaseSessionContext
                 List<Class> interfaces = new ArrayList<Class>();
                 interfaces.addAll(di.getInterfaces(interfaceType));
                 interfaces.add(IntraVmProxy.class);
+                interfaces.add(BeanContext.Removable.class);
                 return ProxyManager.newProxyInstance(interfaces.toArray(new Class[interfaces.size()]), handler);
             }
         } catch (IllegalAccessException iae) {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/InstanceContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/InstanceContext.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/InstanceContext.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/InstanceContext.java Mon Jun 20 06:00:06 2011
@@ -18,6 +18,7 @@ package org.apache.openejb.core;
 
 import org.apache.openejb.BeanContext;
 
+import javax.enterprise.context.spi.CreationalContext;
 import java.util.Map;
 
 /**
@@ -28,6 +29,7 @@ public class InstanceContext {
     private final BeanContext beanContext;
     private final Object bean;
     private final Map<String, Object> interceptors;
+    private final CreationalContext creationalContext;
 
     /**
      * A slot where the container can put instance-specific
@@ -35,10 +37,15 @@ public class InstanceContext {
      */
     private Object instanceData;
 
-    public InstanceContext(BeanContext beanContext, Object bean, Map<String, Object> interceptors) {
+    public InstanceContext(BeanContext beanContext, Object bean, Map<String, Object> interceptors, CreationalContext creationalContext) {
         this.beanContext = beanContext;
         this.bean = bean;
         this.interceptors = interceptors;
+        this.creationalContext = creationalContext;
+    }
+
+    public CreationalContext getCreationalContext() {
+        return creationalContext;
     }
 
     public BeanContext getBeanContext() {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java Mon Jun 20 06:00:06 2011
@@ -202,4 +202,18 @@ public class ThreadContext {
     public void setDiscardInstance(boolean discardInstance) {
         this.discardInstance = discardInstance;
     }
+
+    @Override
+    public String toString() {
+        return "ThreadContext{" +
+                "beanContext=" + beanContext.getId() +
+                ", primaryKey=" + primaryKey +
+                ", data=" + data.size() +
+                ", oldClassLoader=" + oldClassLoader +
+                ", currentOperation=" + currentOperation +
+                ", invokedInterface=" + invokedInterface +
+                ", transactionPolicy=" + transactionPolicy +
+                ", discardInstance=" + discardInstance +
+                '}';
+    }
 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorData.java Mon Jun 20 06:00:06 2011
@@ -18,7 +18,9 @@
 package org.apache.openejb.core.interceptor;
 
 import org.apache.openejb.core.Operation;
+import org.apache.openejb.util.SetAccessible;
 import org.apache.xbean.finder.ClassFinder;
+import serp.bytecode.Annotation;
 
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.AroundTimeout;
@@ -138,19 +140,28 @@ public class InterceptorData {
 
         InterceptorData data = new InterceptorData(clazz);
 
-        data.aroundInvoke.addAll(finder.findAnnotatedMethods(AroundInvoke.class));
-        data.postConstruct.addAll(finder.findAnnotatedMethods(PostConstruct.class));
-        data.preDestroy.addAll(finder.findAnnotatedMethods(PreDestroy.class));
-        data.postActivate.addAll(finder.findAnnotatedMethods(PostActivate.class));
-        data.prePassivate.addAll(finder.findAnnotatedMethods(PrePassivate.class));
-        data.afterBegin.addAll(finder.findAnnotatedMethods(AfterBegin.class));
-        data.beforeCompletion.addAll(finder.findAnnotatedMethods(BeforeCompletion.class));
-        data.afterCompletion.addAll(finder.findAnnotatedMethods(AfterCompletion.class));
-        data.aroundTimeout.addAll(finder.findAnnotatedMethods(AroundTimeout.class));
+        add(finder, data.aroundInvoke, AroundInvoke.class);
+        add(finder, data.postConstruct, PostConstruct.class);
+        add(finder, data.preDestroy, PreDestroy.class);
+        add(finder, data.postActivate, PostActivate.class);
+        add(finder, data.prePassivate, PrePassivate.class);
+        add(finder, data.afterBegin, AfterBegin.class);
+        add(finder, data.beforeCompletion, BeforeCompletion.class);
+        add(finder, data.afterCompletion, AfterCompletion.class);
+        add(finder, data.aroundTimeout, AroundTimeout.class);
 
         return data;
     }
 
+    private static void add(ClassFinder finder, Set<Method> methods, Class<? extends java.lang.annotation.Annotation> annotation) {
+
+        final List<Method> annotatedMethods = finder.findAnnotatedMethods(annotation);
+        for (Method method : annotatedMethods) {
+            SetAccessible.on(method);
+            methods.add(method);
+        }
+    }
+
     @Override
     public String toString() {
         return "InterceptorData{" +

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java Mon Jun 20 06:00:06 2011
@@ -56,6 +56,7 @@ import org.apache.openejb.BeanContext;
 import org.apache.openejb.BeanType;
 import org.apache.openejb.InterfaceType;
 import org.apache.openejb.RpcContainer;
+import org.apache.openejb.core.BaseContext;
 import org.apache.openejb.core.ThreadContext;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.ContainerSystem;
@@ -236,6 +237,8 @@ public abstract class BaseEjbProxyHandle
 
             if (methodName.equals("writeReplace")) return _writeReplace(proxy);
             else throw new UnsupportedOperationException("Unknown method: " + method);
+        } else if (method.getDeclaringClass() == BeanContext.Removable.class) {
+            return _invoke(proxy, BeanContext.Removable.class, method, args);
         }
 
         Class interfce = getInvokedInterface(method);

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java Mon Jun 20 06:00:06 2011
@@ -138,6 +138,7 @@ public abstract class EjbHomeProxyHandle
                 List<Class> proxyInterfaces = new ArrayList<Class>(handler.getInterfaces().size() + 1);
                 proxyInterfaces.addAll(handler.getInterfaces());
                 proxyInterfaces.add(IntraVmProxy.class);
+                proxyInterfaces.add(BeanContext.Removable.class);
                 return ProxyManager.newProxyInstance(proxyInterfaces.toArray(new Class[]{}), handler);
             }
 

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java Mon Jun 20 06:00:06 2011
@@ -37,6 +37,8 @@ import javax.ejb.RemoveException;
 import javax.ejb.SessionBean;
 import javax.ejb.SessionContext;
 import javax.ejb.ConcurrentAccessTimeoutException;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.spi.Bean;
 import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.persistence.EntityManager;
@@ -54,6 +56,7 @@ import org.apache.openejb.OpenEJBExcepti
 import org.apache.openejb.ProxyInfo;
 import org.apache.openejb.RpcContainer;
 import org.apache.openejb.SystemException;
+import org.apache.openejb.config.rules.CheckDependsOn;
 import org.apache.openejb.monitoring.StatsInterceptor;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.monitoring.ManagedMBean;
@@ -122,6 +125,12 @@ public class StatefulContainer implement
     private Map<Method, MethodType> getLifecycleMethodsOfInterface(BeanContext beanContext) {
         Map<Method, MethodType> methods = new HashMap<Method, MethodType>();
 
+        try {
+            methods.put(BeanContext.Removable.class.getDeclaredMethod("$$remove"), MethodType.REMOVE);
+        } catch (NoSuchMethodException e) {
+            throw new IllegalStateException("Internal code change: BeanContext.Removable.$$remove() method was deleted", e);
+        }
+
         List<Method> removeMethods = beanContext.getRemoveMethods();
         for (Method removeMethod : removeMethods) {
             methods.put(removeMethod, MethodType.REMOVE);
@@ -433,11 +442,19 @@ public class StatefulContainer implement
     protected Object removeEJBObject(BeanContext beanContext, Object primKey, Class callInterface, Method callMethod, Object[] args, InterfaceType interfaceType) throws OpenEJBException {
         if (primKey == null) throw new NullPointerException("primKey is null");
 
+        final Class scope = beanContext.get(Bean.class).getScope();
+        if(scope != Dependent.class) {
+            throw new UnsupportedOperationException("Can not call EJB Statefull Bean Remove Method without scoped @Dependent.  Found scope: @"+scope.getSimpleName());
+        }
+
+
+        final boolean internalRemove = BeanContext.Removable.class == callMethod.getDeclaringClass();
+
         ThreadContext callContext = new ThreadContext(beanContext, primKey);
         ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
             // Security check
-            checkAuthorization(callMethod, interfaceType);
+            if (!internalRemove) checkAuthorization(callMethod, interfaceType);
 
             // If a bean managed transaction is active, the bean can not be removed
             if (interfaceType.isComponent()) {
@@ -479,34 +496,36 @@ public class StatefulContainer implement
                     }
                 }
 
-                // Register the entity managers
-                registerEntityManagers(instance, callContext);
-
-                // Register for synchronization callbacks
-                registerSessionSynchronization(instance, callContext);
-
-                // Setup for remove invocation
-                callContext.setCurrentOperation(Operation.REMOVE);
-                callContext.setCurrentAllowedStates(null);
-                callContext.setInvokedInterface(callInterface);
-                runMethod = beanContext.getMatchingBeanMethod(callMethod);
-                callContext.set(Method.class, runMethod);
-
-                // Do not pass arguments on home.remove(remote) calls
-                Class<?> declaringClass = callMethod.getDeclaringClass();
-                if (declaringClass.equals(EJBHome.class) || declaringClass.equals(EJBLocalHome.class)){
-                    args = new Object[]{};
-                }
+                if (!internalRemove) {
+                    // Register the entity managers
+                    registerEntityManagers(instance, callContext);
+
+                    // Register for synchronization callbacks
+                    registerSessionSynchronization(instance, callContext);
+
+                    // Setup for remove invocation
+                    callContext.setCurrentOperation(Operation.REMOVE);
+                    callContext.setCurrentAllowedStates(null);
+                    callContext.setInvokedInterface(callInterface);
+                    runMethod = beanContext.getMatchingBeanMethod(callMethod);
+                    callContext.set(Method.class, runMethod);
+
+                    // Do not pass arguments on home.remove(remote) calls
+                    Class<?> declaringClass = callMethod.getDeclaringClass();
+                    if (declaringClass.equals(EJBHome.class) || declaringClass.equals(EJBLocalHome.class)){
+                        args = new Object[]{};
+                    }
 
-                // Initialize interceptor stack
-                List<InterceptorData> interceptors = beanContext.getMethodInterceptors(runMethod);
-                InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, Operation.REMOVE, interceptors, instance.interceptors);
+                    // Initialize interceptor stack
+                    List<InterceptorData> interceptors = beanContext.getMethodInterceptors(runMethod);
+                    InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, Operation.REMOVE, interceptors, instance.interceptors);
 
-                // Invoke
-                if (args == null){
-                    returnValue = interceptorStack.invoke();
-                } else {
-                    returnValue = interceptorStack.invoke(args);
+                    // Invoke
+                    if (args == null){
+                        returnValue = interceptorStack.invoke();
+                    } else {
+                        returnValue = interceptorStack.invoke(args);
+                    }
                 }
             } catch (InvalidateReferenceException e) {
                 throw e;

Copied: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/ApplicationScopedTest.java (from r1135908, openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/InjectionTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/ApplicationScopedTest.java?p2=openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/ApplicationScopedTest.java&p1=openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/InjectionTest.java&r1=1135908&r2=1137507&rev=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/InjectionTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/ApplicationScopedTest.java Mon Jun 20 06:00:06 2011
@@ -19,51 +19,170 @@ package org.apache.openejb.cdi;
 import junit.framework.TestCase;
 import org.apache.openejb.jee.Beans;
 import org.apache.openejb.jee.SessionBean;
-import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.jee.StatefulBean;
 import org.apache.openejb.junit.ApplicationComposer;
 import org.apache.openejb.junit.Module;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import javax.ejb.EJB;
-import javax.ejb.Singleton;
+import javax.ejb.Local;
+import javax.ejb.Stateful;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
 import javax.inject.Inject;
 
 /**
  * @version $Rev$ $Date$
  */
 @RunWith(ApplicationComposer.class)
-public class InjectionTest extends TestCase {
+public class ApplicationScopedTest extends TestCase {
 
-    @EJB
-    private Orange orange;
+    @Inject
+    private BeanManager beanManager;
 
     @Test
     public void test() throws Exception {
 
+        final Context appContext = beanManager.getContext(ApplicationScoped.class);
+
+
+
+        final Green green = createAndMutate(appContext, Green.class);
+
+        final Blue blue = createAndMutate(appContext, Blue.class);
+
+        assertEquals(green.getMessage(), blue.getGreen().getMessage());
+
+        final BrownLocal brownLocal = createAndMutate(appContext, BrownLocal.class);
+
+        final Green green2 = brownLocal.getGreen();
+        green2.getMessage();
+
+        final Orange orange = createAndMutate(appContext, Orange.class);
         assertNotNull(orange);
         assertNotNull(orange.getBlue());
+        assertNotNull(orange.getBlue().getGreen());
+        assertNotNull(orange.getGreen());
+
+        final Green greenA = orange.getBlue().getGreen();
+        final Green greenB = orange.getGreen();
 
+        assertSame(greenA, greenB);
+    }
+
+    private <T extends Message> T createAndMutate(Context context, Class<T> beanType) {
+
+        final Bean<T> bean = (Bean<T>) beanManager.getBeans(beanType).iterator().next();
+
+        // We haven't created anything yet, so the instance should not exist in the context
+        assertNull(context.get(bean));
+
+
+        final CreationalContext<T> cc1 = beanManager.createCreationalContext(bean);
+
+        // This should create the instance and put it in the context
+        final T instance = context.get(bean, cc1);
+
+
+        // Assert the instance is now in the context and can be generically retrieved
+        assertNotNull(context.get(bean));
+
+
+        final String prefix = beanType.getSimpleName();
+
+        // Mutate the instance...
+        instance.setMessage(prefix + ": hello application");
+
+        // Now check the reference in the context
+        assertEquals(prefix + ": hello application", context.get(bean, cc1).getMessage());
+
+        // Attempt to create a second instance (should not work)
+        final CreationalContext<T> cc2 = beanManager.createCreationalContext(bean);
+
+        // We should still have the same mutated instance as before
+        assertEquals(prefix + ": hello application", context.get(bean, cc2).getMessage());
+
+        // Mutate the instance one more time
+        instance.setMessage(prefix + ": hello again application");
+
+        // And double check that we still just have the single instance in the context
+        assertEquals(prefix + ": hello again application", context.get(bean).getMessage());
+        assertEquals(prefix + ": hello again application", context.get(bean, null).getMessage());
+        assertEquals(prefix + ": hello again application", context.get(bean, cc1).getMessage());
+        assertEquals(prefix + ": hello again application", context.get(bean, cc2).getMessage());
+
+        return instance;
     }
 
     @Module
     public SessionBean getEjbs() {
-        return new SingletonBean(Orange.class);
+        return new StatefulBean(Brown.class);
     }
 
     @Module
     public Beans getBeans() {
         final Beans beans = new Beans();
+        beans.addManagedClass(Orange.class);
         beans.addManagedClass(Blue.class);
         beans.addManagedClass(Green.class);
         return beans;
     }
 
-    @Singleton
-    public static class Orange {
+    @Local
+    public static interface BrownLocal extends Message {
+
+        public Green getGreen();
+    }
+
+    @Stateful
+    @ApplicationScoped
+    public static class Brown implements BrownLocal {
+        private String id;
+
+        @Inject
+        private Green green;
+
+        @Override
+        public String getMessage() {
+            return id;
+        }
 
+        @Override
+        public void setMessage(String id) {
+            this.id = id;
+        }
+
+        @Override
+        public Green getGreen() {
+            return green;
+        }
+    }
+
+    @ApplicationScoped
+    public static class Orange implements Message {
+
+        private String id;
         private Blue blue;
 
+        public Orange() {
+            System.out.println(this.getClass().getName());
+        }
+
+        @Override
+        public String getMessage() {
+            return id;
+        }
+
+        @Override
+        public void setMessage(String id) {
+            this.id = id;
+        }
+        @Inject
+        private Green green;
+
         @Inject
         public void setBlue(Blue blue) {
             this.blue = blue;
@@ -72,15 +191,30 @@ public class InjectionTest extends TestC
         public Blue getBlue() {
             return blue;
         }
+
+        public Green getGreen() {
+            return green;
+        }
     }
 
-    public static class Blue {
+    @ApplicationScoped
+    public static class Blue implements Message {
 
+        private String id;
         private Green green;
 
-        public Blue()
-        {
-            "".length();
+        public Blue() {
+            System.out.println(this.getClass().getName());
+        }
+
+        @Override
+        public String getMessage() {
+            return id;
+        }
+
+        @Override
+        public void setMessage(String id) {
+            this.id = id;
         }
 
         public Green getGreen() {
@@ -93,11 +227,31 @@ public class InjectionTest extends TestC
         }
     }
 
-    public static class Green {
+    @ApplicationScoped
+    public static class Green implements Message {
+
+        private String id;
 
-        public Green()
-        {
+        public Green() {
             "".length();
+            System.out.println(this.getClass().getName());
         }
+
+        @Override
+        public String getMessage() {
+            return id;
+        }
+
+        @Override
+        public void setMessage(String id) {
+            this.id = id;
+        }
+    }
+
+    public static interface Message {
+
+        void setMessage(String id);
+
+        String getMessage();
     }
 }

Copied: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulInternalRemoveTest.java (from r1135908, openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulInternalRemoveTest.java?p2=openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulInternalRemoveTest.java&p1=openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java&r1=1135908&r2=1137507&rev=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulInternalRemoveTest.java Mon Jun 20 06:00:06 2011
@@ -17,236 +17,89 @@
  */
 package org.apache.openejb.core.stateful;
 
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Stack;
-import java.util.ArrayList;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.annotation.Resource;
-import javax.ejb.*;
-import javax.naming.InitialContext;
-import javax.transaction.TransactionManager;
-
 import junit.framework.TestCase;
-import org.apache.openejb.assembler.classic.Assembler;
-import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
-import org.apache.openejb.assembler.classic.SecurityServiceInfo;
-import org.apache.openejb.assembler.classic.StatefulSessionContainerInfo;
-import org.apache.openejb.assembler.classic.TransactionServiceInfo;
-import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.BeanContext;
 import org.apache.openejb.core.ivm.naming.InitContextFactory;
-import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.StatefulBean;
-import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.Local;
+import javax.ejb.LocalBean;
+import javax.ejb.NoSuchEJBException;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.naming.InitialContext;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
 
 /**
  * @version $Revision$ $Date$
  */
-public class StatefulContainerTest extends TestCase {
-    private List<Lifecycle> inTxExpectedLifecycle;
-    private List expectedLifecycle;
 
-    public void testBusinessLocalInterface() throws Exception {
-        testBusinessLocalInterface(expectedLifecycle);
-    }
-    
-    public void testBusinessLocalBeanInterface() throws Exception {
-        List localbeanExpectedLifecycle = new ArrayList();
-        localbeanExpectedLifecycle.addAll(expectedLifecycle);
-        // can't avoid the extra constructor call
-        localbeanExpectedLifecycle.add(4, Lifecycle.CONSTRUCTOR);
+@RunWith(ApplicationComposer.class)
+public class StatefulInternalRemoveTest extends TestCase {
 
-        testBusinessLocalBeanInterface(localbeanExpectedLifecycle);
-    }
+    @Module
+    public StatefulBean beans() {
+        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
 
-    public void testBusinessRemoteInterfaceInTx() throws Exception {
-        TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
-        transactionManager.begin();
-        try {
-            testBusinessRemoteInterface(inTxExpectedLifecycle);
-        } finally {
-            transactionManager.commit();
-        }
+        return new StatefulBean(Widget.class);
     }
 
-    protected void testBusinessLocalInterface(List expectedLifecycle) throws Exception {
-
-        // Do a create...
+    @Test
+    public void testBusinessLocalInterface() throws Exception {
+        Widget.lifecycle.clear();
 
-        InitialContext ctx = new InitialContext();
-        Object object = ctx.lookup("WidgetBeanLocal");
+        final WidgetLocal widgetLocal = (WidgetLocal) new InitialContext().lookup("WidgetLocal");
 
-        assertTrue("instanceof widget", object instanceof Widget);
+        widgetLocal.widget();
 
-        Widget widget = (Widget) object;
+        BeanContext.Removable removable = (BeanContext.Removable) widgetLocal;
 
-        // Do a business method...
-        Stack<Object> actual = widget.getLifecycle();
-        assertNotNull("lifecycle", actual);
+        removable.$$remove();
 
-        // test app exception
         try {
-            widget.throwAppException();
-            fail("Expected application exception");
-        } catch (SQLException e) {
-            assertEquals("test", e.getMessage());
-        }
-
-        // Do another business method...
-        widget.afterAppException();
-
-        // Do a remove...
-        widget.destroy();
-
-        // Check the lifecycle of the bean
-        assertEquals(StatefulContainerTest.join("\n", expectedLifecycle) , join("\n", WidgetBean.lifecycle));
-    }
-
-    protected void testBusinessLocalBeanInterface(List expectedLifecycle) throws Exception {
-
-        // Do a create...
-
-        InitialContext ctx = new InitialContext();
-        Object object = ctx.lookup("WidgetBeanLocalBean");
-
-        assertTrue("instanceof widget", object instanceof WidgetBean);
+            widgetLocal.widget();
 
-        WidgetBean widget = (WidgetBean) object;
-
-        // Do a business method...
-        Stack<Object> actual = widget.getLifecycle();
-        assertNotNull("lifecycle", actual);
-
-        // test app exception
-        try {
-            widget.throwAppException();
-            fail("Expected application exception");
-        } catch (SQLException e) {
-            assertEquals("test", e.getMessage());
+            fail("The bean should have been removed");
+        } catch (NoSuchEJBException e) {
+            // pass
         }
 
-        // Do another business method...
-        widget.afterAppException();
-
-        // Do a remove...
-        widget.destroy();
-
         // Check the lifecycle of the bean
 
-        assertEquals(StatefulContainerTest.join("\n", expectedLifecycle) , join("\n", WidgetBean.lifecycle));
-    }
-
-    public void testBusinessRemoteInterface() throws Exception {
-        testBusinessRemoteInterface(expectedLifecycle);
-    }
+        Lifecycle[] expected = {
+                Lifecycle.CONSTRUCTOR,
+                Lifecycle.POST_CONSTRUCT,
+                Lifecycle.BUSINESS_METHOD,
+                Lifecycle.PRE_DESTROY};
 
-    public void testBusinessLocalInterfaceInTx() throws Exception {
-        TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
-        transactionManager.begin();
-        try {
-            testBusinessLocalInterface(inTxExpectedLifecycle);
-        } finally {
-            transactionManager.commit();
-        }
+        assertEquals(join("\n", Arrays.asList(expected)), join("\n", Widget.lifecycle));
     }
 
-    public void testBusinessLocalBeanInterfaceInTx() throws Exception {
-         List localbeanExpectedLifecycle = new ArrayList();
-        localbeanExpectedLifecycle.addAll(inTxExpectedLifecycle);
-        // can't avoid the extra constructor call
-        localbeanExpectedLifecycle.add(3, Lifecycle.CONSTRUCTOR);
+    public void testBusinessRemoteInterface() throws Exception {
 
-        TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
-        transactionManager.begin();
-        try {
-            testBusinessLocalBeanInterface(localbeanExpectedLifecycle);
-        } finally {
-            transactionManager.commit();
-        }
     }
 
-    protected void testBusinessRemoteInterface(List expectedLifecycle) throws Exception {
-        WidgetBean.lifecycle.clear();
-
-        // Do a create...
-
-        InitialContext ctx = new InitialContext();
-        Object object = ctx.lookup("WidgetBeanRemote");
-
-        assertTrue("instanceof widget", object instanceof RemoteWidget);
-
-        RemoteWidget widget = (RemoteWidget) object;
-
-        // Do a business method...
-        Stack<Object> lifecycle = widget.getLifecycle();
-        assertNotNull("lifecycle",lifecycle);
-        assertNotSame("is copy", lifecycle, WidgetBean.lifecycle);
+    public void testLocalBeanInterface() throws Exception {
 
-        // test app exception
-        try {
-            widget.throwAppException();
-            fail("Expected application exception");
-        } catch (SQLException e) {
-            assertEquals("test", e.getMessage());
-        }
-
-        // Do another business method...
-        widget.afterAppException();
-
-        // Do a remove...
-        widget.destroy();
-
-        try {
-            widget.destroy();
-            fail("Calling a removed bean should not be possible");
-        } catch (Exception e) {
-        }
-
-        // Check the lifecycle of the bean
-        assertEquals(StatefulContainerTest.join("\n", expectedLifecycle) , join("\n", WidgetBean.lifecycle));
     }
 
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
-
-        ConfigurationFactory config = new ConfigurationFactory();
-        Assembler assembler = new Assembler();
-
-        assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
-        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
-        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
-
-        // containers
-        StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class);
-        statefulContainerInfo.properties.setProperty("PoolSize", "0");
-        statefulContainerInfo.properties.setProperty("BulkPassivate", "1");
-        statefulContainerInfo.properties.setProperty("Frequency", "0");
-        assembler.createContainer(statefulContainerInfo);
-
-        // Setup the descriptor information
-
-        EjbJar ejbJar = new EjbJar();
-        ejbJar.addEnterpriseBean(new StatefulBean(WidgetBean.class));
-
-        assembler.createApplication(config.configureApplication(ejbJar));
-
-        WidgetBean.lifecycle.clear();
-
-        expectedLifecycle = Arrays.asList(Lifecycle.values());
-        inTxExpectedLifecycle = new ArrayList<Lifecycle>();
-        for (Lifecycle lifecycle : Lifecycle.values()) {
-            if (!lifecycle.name().startsWith("PRE_PASSIVATE") &&
-                    !lifecycle.name().startsWith("POST_ACTIVATE")) {
-                inTxExpectedLifecycle.add(lifecycle);
-            }
-        }
+    public static enum Lifecycle {
+        CONSTRUCTOR,
+        POST_CONSTRUCT,
+        BUSINESS_METHOD,
+        REMOVE,
+        PRE_DESTROY,
     }
 
-    private static String join(String delimeter, List items){
+    private static String join(String delimeter, List items) {
         StringBuffer sb = new StringBuffer();
         for (Object item : items) {
             sb.append(item.toString()).append(delimeter);
@@ -255,92 +108,43 @@ public class StatefulContainerTest exten
     }
 
     @Local
-    public static interface Widget {
-        Stack<Object> getLifecycle();
-        void throwAppException() throws SQLException;
-        void afterAppException();
+    public static interface WidgetLocal {
         void destroy();
+
+        void widget();
     }
 
     @Remote
-    public static interface RemoteWidget extends Widget {
+    public static interface WidgetRemote extends WidgetLocal {
 
     }
 
-    public static enum Lifecycle {
-        // construction
-        CONSTRUCTOR, INJECTION, POST_CONSTRUCT, PRE_PASSIVATE1,
-        // business method
-        POST_ACTIVATE1, BUSINESS_METHOD, PRE_PASSIVATE2,
-        // throw app exception
-        POST_ACTIVATE2, PRE_PASSIVATE3,
-        // business method after app exception
-        POST_ACTIVATE3, PRE_PASSIVATE4,
-        // remove
-        POST_ACTIVATE4, REMOVE, PRE_DESTROY,
-    }
-
     @LocalBean
-    public static class WidgetBean implements Widget, RemoteWidget {
-        private int activates = 0;
-        private int passivates = 0;
-
-        public static Stack<Object> lifecycle = new Stack<Object>();
+    public static class Widget implements WidgetLocal, WidgetRemote {
 
-        public WidgetBean() {
-            lifecycle.push(Lifecycle.CONSTRUCTOR);
-        }
-
-        public void throwAppException() throws SQLException {
-            throw new SQLException("test");
-        }
-
-        public void afterAppException() {
-        }
-
-        @Resource
-        public void setContext(SessionContext context){
-            lifecycle.push(Lifecycle.INJECTION);
-        }
-
-        public Stack<Object> getLifecycle() {
-            lifecycle.push(Lifecycle.BUSINESS_METHOD);
-            return lifecycle;
-        }
+        public static LinkedList<Object> lifecycle = new LinkedList<Object>();
 
-        @PostActivate
-        public void activate(){
-            String name = "POST_ACTIVATE" + (++activates);
-            try {
-                lifecycle.push(Enum.valueOf(Lifecycle.class, name));
-            } catch (Exception e) {
-                lifecycle.push(name);
-            }
+        public Widget() {
+            lifecycle.add(Lifecycle.CONSTRUCTOR);
         }
 
-        @PrePassivate
-        public void passivate(){
-            String name = "PRE_PASSIVATE" + (++passivates);
-            try {
-                lifecycle.push(Enum.valueOf(Lifecycle.class, name));
-            } catch (Exception e) {
-                lifecycle.push(name);
-            }
+        public void widget() {
+            lifecycle.add(Lifecycle.BUSINESS_METHOD);
         }
 
         @PostConstruct
         public void init() {
-            lifecycle.push(Lifecycle.POST_CONSTRUCT);
+            lifecycle.add(Lifecycle.POST_CONSTRUCT);
         }
 
         @PreDestroy
         public void predestroy() {
-            lifecycle.push(Lifecycle.PRE_DESTROY);
+            lifecycle.add(Lifecycle.PRE_DESTROY);
         }
 
         @Remove
         public void destroy() {
-            lifecycle.push(Lifecycle.REMOVE);
+            lifecycle.add(Lifecycle.REMOVE);
         }
     }
 }

Modified: openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/Report.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/Report.java?rev=1137507&r1=1137506&r2=1137507&view=diff
==============================================================================
--- openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/Report.java (original)
+++ openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/Report.java Mon Jun 20 06:00:06 2011
@@ -23,6 +23,7 @@ import org.xml.sax.helpers.DefaultHandle
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
@@ -45,7 +46,8 @@ public class Report {
     private final LinkedList<TestClass> classes = new LinkedList<TestClass>();
 
     private void main() throws Exception {
-        final File file = new File("/Users/dblevins/work/uber/geronimo-tck-public-trunk/jcdi-tck-runner/target/surefire-reports/testng-results.xml");
+//        final File file = new File("/Users/dblevins/work/uber/geronimo-tck-public-trunk/jcdi-tck-runner/target/surefire-reports/testng-results.xml");
+        final File file = new File("/Users/dblevins/work/uber/openejb/tck/cdi-embedded/target/surefire-reports/testng-results.xml");
 
         final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
 
@@ -65,12 +67,96 @@ public class Report {
 
         Collections.sort(classes);
 
+        textReport(file);
+        passingXml(file);
+        failingXml(file);
+
+    }
+
+    private void textReport(File file) throws FileNotFoundException {
         final File report = new File(file.getParentFile(), file.getName().replaceAll(".xml$", ".txt"));
         final PrintStream out = new PrintStream(new FileOutputStream(report));
         printResults(out);
         out.close();
     }
 
+    private void passingXml(File file) throws FileNotFoundException {
+        final File report = new File(file.getParentFile(), file.getName().replaceAll(".xml$", "-passing.xml"));
+        final PrintStream out = new PrintStream(new FileOutputStream(report));
+
+        out.println("<suite name=\"CDI TCK\" verbose=\"0\">");
+        out.println("  <test name=\"CDI TCK\">");
+        out.println("    <!--<packages>-->\n" +
+                "        <!--<package name=\"org.jboss.jsr299.tck.tests.*\"/>-->\n" +
+                "        <!--<package name=\"org.jboss.jsr299.tck.interceptors.tests.*\"/>-->\n" +
+                "    <!--</packages>-->");
+        out.println("    <classes>");
+
+        for (TestClass testClass : classes) {
+
+            if (!contains(testClass, Status.FAIL)) {
+                out.printf("      <class name=\"%s\"/>\n", testClass.name);
+            } else if (contains(testClass, Status.PASS)) {
+                out.printf("      <class name=\"%s\">\n", testClass.name);
+                out.printf("        <methods>\n");
+
+                for (TestResult result : testClass.getResults()) {
+                    if (result.status == Status.FAIL) {
+                        out.printf("          <exclude name=\"%s\"/>\n", result.name);
+                    }
+                }
+
+                out.printf("        </methods>\n");
+                out.printf("      </class>\n");
+            }
+        }
+        out.println("    </classes>");
+        out.println("  </test>");
+        out.println("</suite>");
+
+        out.close();
+    }
+
+    private void failingXml(File file) throws FileNotFoundException {
+        final File report = new File(file.getParentFile(), file.getName().replaceAll(".xml$", "-failing.xml"));
+        final PrintStream out = new PrintStream(new FileOutputStream(report));
+
+        out.println("<suite name=\"CDI TCK\" verbose=\"0\">");
+        out.println("  <test name=\"CDI TCK\">");
+        out.println("    <!--<packages>-->\n" +
+                "        <!--<package name=\"org.jboss.jsr299.tck.tests.*\"/>-->\n" +
+                "        <!--<package name=\"org.jboss.jsr299.tck.interceptors.tests.*\"/>-->\n" +
+                "    <!--</packages>-->");
+        out.println("    <classes>");
+
+        for (TestClass testClass : classes) {
+
+            if (contains(testClass, Status.FAIL)) {
+                out.printf("      <class name=\"%s\"/>\n", testClass.name);
+            }
+        }
+        out.println("    </classes>");
+        out.println("  </test>");
+        out.println("</suite>");
+
+        out.close();
+    }
+
+    private boolean contains(TestClass testClass, Status status) {
+
+        for (TestResult result : testClass.getResults()) {
+            if (result.name.equals("beforeClass")) continue;
+            if (result.name.equals("afterClass")) continue;
+            if (result.name.equals("afterSuite")) continue;
+            if (result.name.equals("beforeSuite")) continue;
+
+            if (result.status == status)  {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private void printResults(PrintStream out) {
 
         Map<Status, AtomicInteger> totals = new HashMap<Status, AtomicInteger>();

Added: openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml?rev=1137507&view=auto
==============================================================================
--- openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml (added)
+++ openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml Mon Jun 20 06:00:06 2011
@@ -0,0 +1,50 @@
+<suite name="CDI TCK" verbose="0">
+  <test name="CDI TCK">
+    <!--<packages>-->
+        <!--<package name="org.jboss.jsr299.tck.tests.*"/>-->
+        <!--<package name="org.jboss.jsr299.tck.interceptors.tests.*"/>-->
+    <!--</packages>-->
+    <classes>
+      <class name="org.jboss.jsr299.tck.tests.context.application.ApplicationContextTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.conversation.ClientConversationContextTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.conversation.InvalidatingSessionDestroysConversationTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.conversation.LongRunningConversationPropagatedByFacesContextTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.conversation.ManualCidPropagationTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.dependent.DependentContextTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.dependent.ejb.DependentContextEjbTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.passivating.broken.dependentScopedProducerFieldReturnsNonSerializableObjectForInjectionIntoStatefulSessionBean.EnterpriseBeanWithIllegalDependencyTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.passivating.broken.dependentScopedProducerMethodReturnsNonSerializableObjectForInjectionIntoStatefulSessionBean.EnterpriseBeanWithIllegalDependencyTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.request.RequestContextTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.request.ejb.EJBRequestContextTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.session.SessionContextTest"/>
+      <class name="org.jboss.jsr299.tck.tests.definition.stereotype.broken.nonEmptyNamed.NonEmptyNamedTest"/>
+      <class name="org.jboss.jsr299.tck.tests.definition.stereotype.broken.tooManyScopes.TooManyScopeTypesTest"/>
+      <class name="org.jboss.jsr299.tck.tests.deployment.packaging.bundledLibrary.LibraryInEarTest"/>
+      <class name="org.jboss.jsr299.tck.tests.deployment.packaging.bundledLibrary.LibraryInWarTest"/>
+      <class name="org.jboss.jsr299.tck.tests.event.observer.enterprise.EnterpriseEventInheritenceTest"/>
+      <class name="org.jboss.jsr299.tck.tests.implementation.builtin.BuiltInBeansTest"/>
+      <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle.EnterpriseBeanLifecycleTest"/>
+      <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.newBean.NewEnterpriseBeanICTest"/>
+      <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.newBean.NewEnterpriseBeanTest"/>
+      <class name="org.jboss.jsr299.tck.tests.implementation.producer.method.definition.enterprise.EnterpriseProducerMethodDefinitionTest"/>
+      <class name="org.jboss.jsr299.tck.tests.implementation.simple.resource.env.EnvInjectionTest"/>
+      <class name="org.jboss.jsr299.tck.tests.implementation.simple.resource.persistenceContext.PersistenceContextInjectionTest"/>
+      <class name="org.jboss.jsr299.tck.tests.implementation.simple.resource.resource.InjectionOfResourceTest"/>
+      <class name="org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.EnterpriseBeanSpecializationIntegrationTest"/>
+      <class name="org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.EnterpriseBeanSpecializationTest"/>
+      <class name="org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.broken.directlyExtendsNothing.DirectlyExtendsNothingTest"/>
+      <class name="org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.broken.directlyExtendsSimpleBean.DirectlyExtendsSimpleBeanTest"/>
+      <class name="org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.broken.implementInterfaceAndExtendsNothing.ImplementsInterfaceAndExtendsNothingTest"/>
+      <class name="org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.broken.sameName.SameNameTest"/>
+      <class name="org.jboss.jsr299.tck.tests.interceptors.definition.custom.CustomInterceptorTest"/>
+      <class name="org.jboss.jsr299.tck.tests.interceptors.definition.enterprise.nonContextualReference.SessionBeanInterceptorOnNonContextualEjbReferenceTest"/>
+      <class name="org.jboss.jsr299.tck.tests.lookup.clientProxy.incontainer.ClientProxyTest"/>
+      <class name="org.jboss.jsr299.tck.tests.lookup.el.ResolutionByNameTest"/>
+      <class name="org.jboss.jsr299.tck.tests.lookup.el.integration.IntegrationWithUnifiedELTest"/>
+      <class name="org.jboss.jsr299.tck.tests.lookup.injection.non.contextual.InjectionIntoNonContextualComponentTest"/>
+      <class name="org.jboss.jsr299.tck.tests.lookup.injection.non.contextual.ws.InjectionIntoWebServiceEndPointTest"/>
+      <class name="org.jboss.jsr299.tck.tests.lookup.injectionpoint.broken.not.bean.InjectionPointTest"/>
+      <class name="org.jboss.jsr299.tck.tests.lookup.manager.jndi.ManagerTest"/>
+    </classes>
+  </test>
+</suite>