You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by gp...@apache.org on 2011/04/11 11:44:33 UTC

svn commit: r1090992 - /openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java

Author: gpetracek
Date: Mon Apr 11 09:44:32 2011
New Revision: 1090992

URL: http://svn.apache.org/viewvc?rev=1090992&view=rev
Log:
OWB-564 CdiTestOpenWebBeansContainer - check if a std.-context is active before destroying it

Modified:
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java

Modified: openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java?rev=1090992&r1=1090991&r2=1090992&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java (original)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java Mon Apr 11 09:44:32 2011
@@ -21,13 +21,21 @@ package org.apache.webbeans.cditest.owb;
 import java.lang.annotation.Annotation;
 import java.util.Set;
 
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.context.spi.Context;
 import javax.enterprise.inject.ResolutionException;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Singleton;
 
 import org.apache.webbeans.cditest.CdiTestContainer;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.context.type.ContextTypes;
+import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.spi.ContainerLifecycle;
 import static org.apache.webbeans.util.InjectionExceptionUtils.*;
 
@@ -36,6 +44,7 @@ import static org.apache.webbeans.util.I
  */
 public class CdiTestOpenWebBeansContainer implements CdiTestContainer 
 {
+    private static final WebBeansLogger logger = WebBeansLogger.getLogger(CdiTestOpenWebBeansContainer.class);
 
     private ContainerLifecycle  lifecycle = null;
     private MockServletContext  servletContext = null;
@@ -120,11 +129,23 @@ public class CdiTestOpenWebBeansContaine
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
         ContextFactory contextFactory = webBeansContext.getContextFactory();
 
-        contextFactory.destroyRequestContext(null);
-        contextFactory.destroyConversationContext();
-        contextFactory.destroySessionContext(session);
-        contextFactory.destroyApplicationContext(servletContext);
-        contextFactory.destroySingletonContext(servletContext);
+        stopSessionScope();
+        stopConversationScope();
+        stopRequestScope();
+        stopApplicationScope();
+
+        Context context = contextFactory.getStandardContext(ContextTypes.SINGLETON);
+        if(context != null && context.isActive())
+        {
+            contextFactory.destroySingletonContext(servletContext);
+        }
+        else
+        {
+            if(logger.wblWillLogWarn())
+            {
+                logger.warn("destroy was called for an inactive context (" + Singleton.class.getName() + ")");
+            }
+        }
 
         //Comment out for OWB-502
         //ContextFactory.cleanUpContextFactory();
@@ -136,7 +157,18 @@ public class CdiTestOpenWebBeansContaine
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
         ContextFactory contextFactory = webBeansContext.getContextFactory();
 
-        contextFactory.destroyApplicationContext(servletContext);
+        Context context = contextFactory.getStandardContext(ContextTypes.APPLICATION);
+        if(context != null && context.isActive())
+        {
+            contextFactory.destroyApplicationContext(servletContext);
+        }
+        else
+        {
+            if(logger.wblWillLogWarn())
+            {
+                logger.warn("destroy was called for an inactive context (" + ApplicationScoped.class.getName() + ")");
+            }
+        }
     }
 
     @Override
@@ -145,7 +177,18 @@ public class CdiTestOpenWebBeansContaine
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
         ContextFactory contextFactory = webBeansContext.getContextFactory();
 
-        contextFactory.destroyConversationContext();
+        Context context = contextFactory.getStandardContext(ContextTypes.CONVERSATION);
+        if(context != null && context.isActive())
+        {
+            contextFactory.destroyConversationContext();
+        }
+        else
+        {
+            if(logger.wblWillLogWarn())
+            {
+                logger.warn("destroy was called for an inactive context (" + ConversationScoped.class.getName() + ")");
+            }
+        }
     }
 
     @Override
@@ -160,7 +203,18 @@ public class CdiTestOpenWebBeansContaine
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
         ContextFactory contextFactory = webBeansContext.getContextFactory();
 
-        contextFactory.destroyRequestContext(null);
+        Context context = contextFactory.getStandardContext(ContextTypes.REQUEST);
+        if(context != null && context.isActive())
+        {
+            contextFactory.destroyRequestContext(null);
+        }
+        else
+        {
+            if(logger.wblWillLogWarn())
+            {
+                logger.warn("destroy was called for an inactive context (" + RequestScoped.class.getName() + ")");
+            }
+        }
     }
 
     @Override
@@ -169,7 +223,18 @@ public class CdiTestOpenWebBeansContaine
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
         ContextFactory contextFactory = webBeansContext.getContextFactory();
 
-        contextFactory.destroySessionContext(session);
+        Context context = contextFactory.getStandardContext(ContextTypes.SESSION);
+        if(context != null && context.isActive())
+        {
+            contextFactory.destroySessionContext(session);
+        }
+        else
+        {
+            if(logger.wblWillLogWarn())
+            {
+                logger.warn("destroy was called for an inactive context (" + SessionScoped.class.getName() + ")");
+            }
+        }
     }
     
     public  BeanManager getBeanManager()