[maven-release-plugin]  copy for tag openwebbeans-1.5.0

git-svn-id: https://svn.apache.org/repos/asf/openwebbeans/tags/openwebbeans-1.5.0@1673927 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/readme/README.txt b/readme/README.txt
index 68f05fa..ef117f1 100644
--- a/readme/README.txt
+++ b/readme/README.txt
@@ -145,13 +145,13 @@
     [OWB-1041] - Session id changes in tomcat integration are not propagated to session context manager
     [OWB-1042] - dependent producer resolution needs to consider raw types
     [OWB-1045] - WebContextsService#destroySession
+    [OWB-1046] - Starting transient conversation fails with jetty
 
 Improvement
 
     [OWB-652] - Introduce HierarchicBeanManager
     [OWB-755] - Move the instance creation into Producer.produce
     [OWB-763] - move our remaining tests from TestContext to AbstractUnitTest
-    [OWB-798] - expensive check in EventUtil#checkEventBindings
     [OWB-820] - cleanup of el resolvers
     [OWB-932] - skip validation of the cdi-api
     [OWB-937] - unify startup detection
diff --git a/webbeans-el22/src/test/java/org/apache/webbeans/el/test/ELPerformanceTest.java b/webbeans-el22/src/test/java/org/apache/webbeans/el/test/ELPerformanceTest.java
index c7900f2..c1d69bf 100644
--- a/webbeans-el22/src/test/java/org/apache/webbeans/el/test/ELPerformanceTest.java
+++ b/webbeans-el22/src/test/java/org/apache/webbeans/el/test/ELPerformanceTest.java
@@ -28,10 +28,13 @@
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.el22.WebBeansELResolver;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.spi.ContextsService;
 import org.junit.Assert;
 import org.junit.Test;
 
 import javax.el.ELContext;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
 
 public class ELPerformanceTest extends AbstractUnitTest
 {
@@ -94,8 +97,9 @@
         @Override
         public void run()
         {
-            WebBeansContext.currentInstance().getContextFactory().initRequestContext(null);
-            WebBeansContext.currentInstance().getContextFactory().initSessionContext(null);
+            ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
+            contextsService.startContext(RequestScoped.class, null);
+            contextsService.startContext(SessionScoped.class, null);
 
             try
             {
@@ -114,8 +118,8 @@
             }
             finally
             {
-                WebBeansContext.currentInstance().getContextFactory().destroyRequestContext(null);
-                WebBeansContext.currentInstance().getContextFactory().destroySessionContext(null);
+                contextsService.endContext(RequestScoped.class, null);
+                contextsService.endContext(SessionScoped.class, null);
             }
         }
     }
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java b/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
index 89368cc..d0a7dee 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
@@ -28,7 +28,6 @@
 import org.apache.webbeans.annotation.AnnotationManager;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.SerializableBeanVault;
-import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.context.creational.CreationalContextFactory;
 import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.decorator.DecoratorsManager;
@@ -69,7 +68,6 @@
     private final Map<Class<?>, Object> serviceMap = new HashMap<Class<?>, Object>();
 
     private final WebBeansUtil webBeansUtil = new WebBeansUtil(this);
-    private final ContextFactory contextFactory = new ContextFactory(this);
     private final AlternativesManager alternativesManager = new AlternativesManager(this);
     private final AnnotatedElementFactory annotatedElementFactory = new AnnotatedElementFactory(this);
     private final BeanManagerImpl beanManagerImpl = new BeanManagerImpl(this);
@@ -243,12 +241,6 @@
         return webBeansUtil;
     }
 
-    @Deprecated
-    public ContextFactory getContextFactory()
-    {
-        return contextFactory;
-    }
-
     public AnnotationManager getAnnotationManager()
     {
         return annotationManager;
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java b/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
index 372c0bd..3281a45 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
@@ -38,6 +38,7 @@
 import javax.enterprise.context.ContextNotActiveException;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.NormalScope;
+import javax.enterprise.context.spi.AlterableContext;
 import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
@@ -73,6 +74,8 @@
 import org.apache.webbeans.component.third.PassivationCapableThirdpartyBeanImpl;
 import org.apache.webbeans.component.third.ThirdpartyBeanImpl;
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.CustomAlterablePassivatingContextImpl;
+import org.apache.webbeans.context.CustomPassivatingContextImpl;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.decorator.DecoratorComparator;
 import org.apache.webbeans.event.EventMetadataImpl;
@@ -416,13 +419,35 @@
 
     public BeanManager addContext(Context context)
     {
-        addContext(context.getScope(), webBeansContext.getContextFactory().getCustomContext(context));
+        addContext(context.getScope(), wrapCustomContext(context));
 
         return this;
 
     }
 
     /**
+     * If the context is passivating then we need to wrap it into a version which
+     * uses the {@link SerializableBeanVault }
+     */
+    public Context wrapCustomContext(Context context)
+    {
+        if (isPassivatingScope(context.getScope()))
+        {
+            if (context instanceof AlterableContext)
+            {
+                return new CustomAlterablePassivatingContextImpl(webBeansContext.getSerializableBeanVault(), (AlterableContext) context);
+            }
+            else
+            {
+                return new CustomPassivatingContextImpl(webBeansContext.getSerializableBeanVault(), context);
+            }
+        }
+
+        return context;
+    }
+
+
+    /**
      * {@inheritDoc}
      */
     @Override
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java b/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java
deleted file mode 100644
index 57f4928..0000000
--- a/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * 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.webbeans.context;
-
-import java.lang.annotation.Annotation;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-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.AlterableContext;
-import javax.enterprise.context.spi.Context;
-import javax.inject.Singleton;
-import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.webbeans.spi.ContextsService;
-import org.apache.webbeans.config.WebBeansContext;
-
-/**
- * JSR-299 based standard context
- * related operations.
- * @deprecated user should use the ContextsService directly.
- */
-public final class ContextFactory
-{
-    /**Logger instance*/
-    private static final Logger logger = WebBeansLoggerFacade.getLogger(ContextFactory.class);
-    private final WebBeansContext webBeansContext;
-
-    private ContextsService contextsService = null;
-
-    public ContextFactory(WebBeansContext webBeansContext)
-    {
-        this.webBeansContext = webBeansContext;
-    }
-
-    /**
-     * @return the ContextService for the current ClassLoader
-     */
-    private ContextsService getContextsService()
-    {
-        if (contextsService == null)
-        {
-            contextsService = webBeansContext.getService(ContextsService.class);
-        }
-        return contextsService;
-    }
-
-    public void initRequestContext(Object request)
-    {
-        try
-        {
-            ContextsService contextService = getContextsService();
-            contextService.startContext(RequestScoped.class, request);
-        }
-        catch (Exception e)
-        {
-            logger.log(Level.SEVERE, e.getMessage(), e);
-        }
-    }
-
-    public Context getCustomContext(Context context)
-    {
-        if (webBeansContext.getBeanManagerImpl().isPassivatingScope(context.getScope()))
-        {
-            if (context instanceof AlterableContext)
-            {
-                return new CustomAlterablePassivatingContextImpl(webBeansContext.getSerializableBeanVault(), (AlterableContext) context);
-            }
-            else
-            {
-                return new CustomPassivatingContextImpl(webBeansContext.getSerializableBeanVault(), context);
-            }
-        }
-
-        return context;
-    }
-
-    public void destroyRequestContext(Object request)
-    {
-        ContextsService contextService = getContextsService();
-        contextService.endContext(RequestScoped.class, request);
-    }
-
-    public void initSessionContext(Object session)
-    {
-        try
-        {
-            ContextsService contextService = getContextsService();
-            contextService.startContext(SessionScoped.class, session);
-        }
-        catch (Exception e)
-        {
-            logger.log(Level.SEVERE, e.getMessage(), e);
-        }
-    }
-
-    public void destroySessionContext(Object session)
-    {
-        ContextsService contextService = getContextsService();
-        contextService.endContext(SessionScoped.class, session);
-    }
-
-    public void initApplicationContext(Object parameter)
-    {
-        try
-        {
-            ContextsService contextService = getContextsService();
-            contextService.startContext(ApplicationScoped.class, parameter);
-        }
-        catch (Exception e)
-        {
-            logger.log(Level.SEVERE, e.getMessage(), e);
-        }
-    }
-
-    /**
-     * Destroys the application context and all of its components at the end of
-     * the application.
-     *
-     * @param parameter parameter object
-     */
-    public void destroyApplicationContext(Object parameter)
-    {
-        ContextsService contextService = getContextsService();
-        contextService.endContext(ApplicationScoped.class, parameter);
-    }
-
-    public void initSingletonContext(Object parameter)
-    {
-        try
-        {
-            ContextsService contextService = getContextsService();
-            contextService.startContext(Singleton.class, parameter);
-        }
-        catch (Exception e)
-        {
-            logger.log(Level.SEVERE, e.getMessage(), e);
-        }
-    }
-
-    public void destroySingletonContext(Object parameter)
-    {
-        ContextsService contextService = getContextsService();
-        contextService.endContext(Singleton.class, parameter);
-    }
-
-    public void initConversationContext(Object context)
-    {
-        try
-        {
-            ContextsService contextService = getContextsService();
-            contextService.startContext(ConversationScoped.class, context);
-        }
-        catch (Exception e)
-        {
-            logger.log(Level.SEVERE, e.getMessage(), e);
-        }
-    }
-
-    public void destroyConversationContext()
-    {
-        ContextsService contextService = getContextsService();
-        contextService.endContext(ConversationScoped.class, null);
-    }
-
-    /**
-     * Gets the standard context with given scope type.
-     *
-     * @return the current context, or <code>null</code> if no standard context exists for the given scopeType
-     */
-    public Context getStandardContext(Class<? extends Annotation> scopeType)
-    {
-        ContextsService contextService = getContextsService();
-
-        return contextService.getCurrentContext(scopeType);
-    }
-
-
-}
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomAlterablePassivatingContextImpl.java b/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomAlterablePassivatingContextImpl.java
index 0cb873c..a2e12e4 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomAlterablePassivatingContextImpl.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomAlterablePassivatingContextImpl.java
@@ -28,7 +28,7 @@
  */
 public class CustomAlterablePassivatingContextImpl extends CustomPassivatingContextImpl implements AlterableContext
 {
-    CustomAlterablePassivatingContextImpl(SerializableBeanVault sbv, AlterableContext context)
+    public CustomAlterablePassivatingContextImpl(SerializableBeanVault sbv, AlterableContext context)
     {
         super(sbv, context);
     }
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java b/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java
index 2f48c0b..b104c05 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java
@@ -34,7 +34,7 @@
     protected final Context context;
 
 
-    CustomPassivatingContextImpl(SerializableBeanVault sbv, Context context)
+    public CustomPassivatingContextImpl(SerializableBeanVault sbv, Context context)
     {
         this.sbv = sbv;
         this.context = context;
diff --git a/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/SerializationTest.java b/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/SerializationTest.java
index 05c24a2..e7478f9 100644
--- a/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/SerializationTest.java
+++ b/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/SerializationTest.java
@@ -141,7 +141,7 @@
         
         // first we need to actually create a few instances
 
-        Context sessionContext = webBeansContext.getContextFactory().getStandardContext(SessionScoped.class);
+        Context sessionContext = webBeansContext.getBeanManagerImpl().getContext(SessionScoped.class);
         Assert.assertNotNull(sessionContext);
         byte[] ba = serializeObject(sessionContext);
         Assert.assertNotNull(ba);
diff --git a/webbeans-impl/src/test/java/org/apache/webbeans/test/decorators/tests/DecoratorAndInterceptorStackTests.java b/webbeans-impl/src/test/java/org/apache/webbeans/test/decorators/tests/DecoratorAndInterceptorStackTests.java
index 8bd1a46..bc17b9d 100644
--- a/webbeans-impl/src/test/java/org/apache/webbeans/test/decorators/tests/DecoratorAndInterceptorStackTests.java
+++ b/webbeans-impl/src/test/java/org/apache/webbeans/test/decorators/tests/DecoratorAndInterceptorStackTests.java
@@ -23,6 +23,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.enterprise.context.RequestScoped;
 import javax.enterprise.inject.Default;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.util.AnnotationLiteral;
@@ -30,6 +31,7 @@
 import junit.framework.Assert;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContextsService;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.apache.webbeans.test.decorators.multiple.Decorator1;
 import org.apache.webbeans.test.decorators.multiple.Decorator2;
@@ -132,10 +134,11 @@
         @Override
         public void run()
         {
+            ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
             try
             {
                 // this starts the RequestContext for this very thread
-                WebBeansContext.currentInstance().getContextFactory().initRequestContext(null);
+                contextsService.startContext(RequestScoped.class, null);
 
                 for (int i=0; i < 10; i++)
                 {
@@ -147,6 +150,7 @@
                 log.log(Level.SEVERE, "Error while executing Decorators in parallel!", e);
                 failed = true;
             }
+            contextsService.endContext(RequestScoped.class, null);
         }
 
         public boolean isFailed()
diff --git a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/DependingInterceptorTest.java b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/DependingInterceptorTest.java
index dd4673a..672f9f6 100644
--- a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/DependingInterceptorTest.java
+++ b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/DependingInterceptorTest.java
@@ -22,12 +22,13 @@
 import java.util.Collection;
 import java.util.Set;
 
+import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 
 import junit.framework.Assert;
 
-import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContextsService;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.apache.webbeans.test.interceptors.beans.ApplicationScopedBean;
 import org.apache.webbeans.test.interceptors.beans.DependentScopedBean;
@@ -80,9 +81,9 @@
 
         TransactionInterceptor.ECHO = false;
 
-        WebBeansContext webBeansContext = WebBeansContext.getInstance();
-        webBeansContext.getContextFactory().destroyRequestContext(null);
-        webBeansContext.getContextFactory().initRequestContext(null);
+        ContextsService contextsService = getWebBeansContext().getContextsService();
+        contextsService.endContext(RequestScoped.class, null);
+        contextsService.startContext(RequestScoped.class, null);
 
         CreationalContext<RequestScopedBean> ctx2 = getBeanManager().createCreationalContext(bean);
         Object reference2 = getBeanManager().getReference(bean, RequestScopedBean.class, ctx2);
diff --git a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/InterceptorPerformanceTest.java b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/InterceptorPerformanceTest.java
index 578331f..d8cfe6c 100644
--- a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/InterceptorPerformanceTest.java
+++ b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/InterceptorPerformanceTest.java
@@ -21,6 +21,7 @@
 import junit.framework.Assert;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.spi.ContextsService;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.apache.webbeans.test.interceptors.beans.ApplicationScopedBean;
 import org.apache.webbeans.test.interceptors.beans.DependentScopedBean;
@@ -28,6 +29,7 @@
 import org.apache.webbeans.test.interceptors.common.TransactionInterceptor;
 import org.junit.Test;
 
+import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import java.util.ArrayList;
@@ -119,9 +121,10 @@
         {
             try
             {
+                ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
                 for (int req = 0; req < 5; req++)
                 {
-                    WebBeansContext.currentInstance().getContextFactory().initRequestContext(null);
+                    contextsService.startContext(RequestScoped.class, null);
 
                     Set<Bean<?>> beans = getBeanManager().getBeans(RequestScopedBean.class);
                     Assert.assertNotNull(beans);
@@ -146,7 +149,7 @@
                         beanInstance1.getMyService().getJ();
                     }
 
-                    WebBeansContext.currentInstance().getContextFactory().destroyRequestContext(null);
+                    contextsService.endContext(RequestScoped.class, null);
                 }
             }
             catch (Exception e)
diff --git a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/WithInheritedBindingTypeTest.java b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/WithInheritedBindingTypeTest.java
index d568b3c..0d7b480 100644
--- a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/WithInheritedBindingTypeTest.java
+++ b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/business/tests/WithInheritedBindingTypeTest.java
@@ -22,12 +22,14 @@
 import java.util.Collection;
 import java.util.Set;
 
+import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 
 import junit.framework.Assert;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContextsService;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.apache.webbeans.test.interceptors.business.common.WithInheritedBindingTypeBean;
 import org.apache.webbeans.test.interceptors.common.SecureInterceptor;
@@ -73,9 +75,9 @@
         Assert.assertTrue(TransactionInterceptor.ECHO);
         Assert.assertTrue(SecureInterceptor.ECHO);
 
-        WebBeansContext webBeansContext = WebBeansContext.getInstance();
-        webBeansContext.getContextFactory().destroyRequestContext(null);
-        webBeansContext.getContextFactory().initRequestContext(null);
+        ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
+        contextsService.endContext(RequestScoped.class, null);
+        contextsService.startContext(RequestScoped.class, null);
 
         reference = getBeanManager().getReference(bean, WithInheritedBindingTypeBean.class, ctx);
         beanInstance = (WithInheritedBindingTypeBean)reference;
diff --git a/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/ExtensionTest.java b/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/ExtensionTest.java
index b6f7ce9..2ce7cdd 100644
--- a/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/ExtensionTest.java
+++ b/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/ExtensionTest.java
@@ -20,6 +20,7 @@
 
 import java.util.Set;
 
+import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.PassivationCapable;
 
@@ -66,7 +67,7 @@
         startContainer(ExternalTestScopedBean.class);
 
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
-        webBeansContext.getContextFactory().initApplicationContext(null);
+        webBeansContext.getContextsService().startContext(ApplicationScoped.class, null);
 
         @SuppressWarnings("unchecked")
         Bean<ExternalTestScopedBean> bean = (Bean<ExternalTestScopedBean>) getBeanManager().getBeans(ExternalTestScopedBean.class, 
@@ -82,7 +83,7 @@
         //Fire shut down
         BeanManagerImpl.class.cast(getBeanManager()).fireEvent(new BeforeShutdownImpl(), true);
 
-        webBeansContext.getContextFactory().destroyApplicationContext(null);
+        webBeansContext.getContextsService().endContext(ApplicationScoped.class, null);
 
         shutDownContainer();
     }
diff --git a/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java b/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java
index 4443ae9..07537e3 100644
--- a/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java
+++ b/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/WebBeansPhaseListener.java
@@ -20,6 +20,7 @@
 
 import javax.enterprise.context.BusyConversationException;
 import javax.enterprise.context.Conversation;
+import javax.enterprise.context.ConversationScoped;
 import javax.enterprise.context.NonexistentConversationException;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
@@ -28,11 +29,11 @@
 import javax.faces.event.PhaseListener;
 
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.context.ConversationContext;
 import org.apache.webbeans.conversation.ConversationImpl;
 import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.spi.ContextsService;
 
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -52,6 +53,11 @@
 
     private Boolean owbApplication = null;
 
+    private WebBeansContext webBeansContext = WebBeansContext.getInstance();
+    private ConversationManager conversationManager = webBeansContext.getConversationManager();
+    private ContextsService contextsService = webBeansContext.getContextsService();
+
+
     /**
      * {@inheritDoc}
      */
@@ -66,7 +72,6 @@
                 return;
             }
 
-            WebBeansContext webBeansContext = WebBeansContext.getInstance();
             ConversationManager conversationManager = webBeansContext.getConversationManager();
             Conversation conversation = conversationManager.getConversationBeanReference();
 
@@ -76,8 +81,7 @@
                 {
                     logger.log(Level.FINE, "Destroying the conversation context with cid : [{0}]", conversation.getId());
                 }
-                ContextFactory contextFactory = webBeansContext.getContextFactory();
-                contextFactory.destroyConversationContext();
+                contextsService.endContext(ConversationScoped.class, null);
             }
             else
             {
@@ -101,17 +105,14 @@
             //It looks for cid parameter in the JSF request.
             //If request contains cid, then it must restore conversation
             //Otherwise create NonexistentException
-            WebBeansContext webBeansContext = WebBeansContext.getInstance();
-            ConversationManager conversationManager = webBeansContext.getConversationManager();
             Conversation conversation = conversationManager.getConversationBeanReference();
-            ContextFactory contextFactory = webBeansContext.getContextFactory();
 
             String propagation = JSFUtil.getConversationPropagation();
             boolean createNew = "none".equals(propagation);
 
             if (createNew)
             {
-                contextFactory.initConversationContext(getRequest(phaseEvent));
+                contextsService.startContext(ConversationScoped.class, getRequest(phaseEvent));
             }
             else if (conversation.isTransient())
             {
@@ -119,7 +120,7 @@
                 {
                     logger.log(Level.FINE, "Creating a new transitional conversation with cid : [{0}]", conversation.getId());
                 }
-                contextFactory.initConversationContext(getRequest(phaseEvent));
+                contextsService.startContext(ConversationScoped.class, getRequest(phaseEvent));
 
                 //Not restore, throw exception
                 String cid = JSFUtil.getConversationId();
@@ -139,7 +140,7 @@
                 ConversationImpl owbConversation = (ConversationImpl)conversation;
                 if(owbConversation.iUseIt() > 1)
                 {
-                    contextFactory.initConversationContext(getRequest(phaseEvent));
+                    contextsService.startContext(ConversationScoped.class, getRequest(phaseEvent));
                     //Throw Busy exception
                     throw new BusyConversationException(
                             "Propogated conversation with cid=" + JSFUtil.getConversationId() + " is used by other request. It creates a new transient conversation");
@@ -147,7 +148,7 @@
                 else
                 {
                     ConversationContext conversationContext = conversationManager.getConversationContext(conversation);
-                    contextFactory.initConversationContext(conversationContext);
+                    contextsService.startContext(ConversationScoped.class, conversationContext);
                 }
             }
         }
diff --git a/webbeans-jsf12/src/main/java/org/apache/webbeans/jsf12/WebBeansPhaseListener.java b/webbeans-jsf12/src/main/java/org/apache/webbeans/jsf12/WebBeansPhaseListener.java
index d1d2289..2286ad6 100644
--- a/webbeans-jsf12/src/main/java/org/apache/webbeans/jsf12/WebBeansPhaseListener.java
+++ b/webbeans-jsf12/src/main/java/org/apache/webbeans/jsf12/WebBeansPhaseListener.java
@@ -20,17 +20,18 @@
 
 import javax.enterprise.context.BusyConversationException;
 import javax.enterprise.context.Conversation;
+import javax.enterprise.context.ConversationScoped;
 import javax.enterprise.context.NonexistentConversationException;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
 
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.context.ConversationContext;
 import org.apache.webbeans.conversation.ConversationImpl;
 import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.spi.ContextsService;
 
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -50,6 +51,10 @@
 
     private Boolean owbApplication = null;
 
+    private WebBeansContext webBeansContext = WebBeansContext.getInstance();
+    private ConversationManager conversationManager = webBeansContext.getConversationManager();
+    private ContextsService contextsService = webBeansContext.getContextsService();
+
     /**
      * {@inheritDoc}
      */
@@ -64,10 +69,7 @@
         if (phaseEvent.getPhaseId().equals(PhaseId.RENDER_RESPONSE) ||
                 phaseEvent.getFacesContext().getResponseComplete())
         {
-            WebBeansContext webBeansContext = WebBeansContext.getInstance();
-            ConversationManager conversationManager = webBeansContext.getConversationManager();
             Conversation conversation = conversationManager.getConversationBeanReference();
-            ContextFactory contextFactory = webBeansContext.getContextFactory();
 
             if (conversation.isTransient())
             {
@@ -75,7 +77,7 @@
                 {
                     logger.log(Level.FINE, "Destroying the conversation context with cid : [{0}]", conversation.getId());
                 }
-                contextFactory.destroyConversationContext();
+                contextsService.endContext(ConversationScoped.class, null);
             }
             else
             {
@@ -108,7 +110,6 @@
             ConversationManager conversationManager = webBeansContext.getConversationManager();
             Conversation conversation = conversationManager.getConversationBeanReference();
             String cid = JSFUtil.getConversationId();
-            ContextFactory contextFactory = webBeansContext.getContextFactory();
 
             if (conversation.isTransient())
             {
@@ -116,7 +117,7 @@
                 {
                     logger.log(Level.FINE, "Creating a new transitional conversation with cid : [{0}]", conversation.getId());
                 }
-                contextFactory.initConversationContext(null);
+                contextsService.startContext(ConversationScoped.class, null);
 
                 //Not restore, throw exception
                 if(cid != null && !cid.equals(""))
@@ -135,14 +136,14 @@
                 ConversationImpl owbConversation = (ConversationImpl)conversation;
                 if(owbConversation.iUseIt() > 1)
                 {
-                    contextFactory.initConversationContext(null);
+                    contextsService.startContext(ConversationScoped.class, null);
                     //Throw Busy exception
                     throw new BusyConversationException("Propogated conversation with cid=" + cid + " is used by other request. It creates a new transient conversation");
                 }
                 else
                 {
                     ConversationContext conversationContext = conversationManager.getConversationContext(conversation);
-                    contextFactory.initConversationContext(conversationContext);
+                    contextsService.startContext(ConversationScoped.class, conversationContext);
                 }
             }
         }
diff --git a/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/ContextsImpl.java b/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/ContextsImpl.java
index d8ee33c..0939e69 100644
--- a/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/ContextsImpl.java
+++ b/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/ContextsImpl.java
@@ -23,7 +23,6 @@
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.AbstractContext;
-import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.context.RequestContext;
 import org.jboss.cdi.tck.spi.Contexts;
 
@@ -34,16 +33,16 @@
     public AbstractContext getRequestContext()
     {
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
-        ContextFactory contextFactory = webBeansContext.getContextFactory();
 
-        RequestContext ctx =  (RequestContext)contextFactory.getStandardContext(RequestScoped.class);
+        RequestContext ctx =  (RequestContext)webBeansContext.getBeanManagerImpl().getContext(RequestScoped.class);
         
         if(ctx == null)
         {
-            contextFactory.initRequestContext(null);
+            webBeansContext.getContextsService().startContext(RequestScoped.class, null);
+            ctx =  (RequestContext)webBeansContext.getBeanManagerImpl().getContext(RequestScoped.class);
         }
         
-        return (AbstractContext) contextFactory.getStandardContext(RequestScoped.class);
+        return ctx;
     }
 
     @Override
@@ -63,9 +62,8 @@
     public AbstractContext getDependentContext()
     {
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
-        ContextFactory contextFactory = webBeansContext.getContextFactory();
 
-        return (AbstractContext) contextFactory.getStandardContext(Dependent.class);
+        return (AbstractContext) webBeansContext.getBeanManagerImpl().getContext(Dependent.class);
     }
 
     @Override
diff --git a/webbeans-spi/src/main/java/org/apache/webbeans/spi/FailOverService.java b/webbeans-spi/src/main/java/org/apache/webbeans/spi/FailOverService.java
index 0de42e2..d6536ea 100644
--- a/webbeans-spi/src/main/java/org/apache/webbeans/spi/FailOverService.java
+++ b/webbeans-spi/src/main/java/org/apache/webbeans/spi/FailOverService.java
@@ -30,6 +30,7 @@
 

 /**

  * Container provided failover and passivation service.

+ * @deprecated in the future we will simply store all SessionScoped stuff in the native http session. This will render this service useless.

  */

 public interface FailOverService

 {

diff --git a/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java b/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
index 3e0085c..d16718a 100644
--- a/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
+++ b/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
@@ -288,23 +288,23 @@
     @Override
     public void startContext(Class<? extends Annotation> scopeType, Object startParameter) throws ContextException
     {
-        if(scopeType.equals(RequestScoped.class))
+        if (scopeType.equals(RequestScoped.class))
         {
             initRequestContext((ServletRequestEvent)startParameter);
         }
-        else if(scopeType.equals(SessionScoped.class))
+        else if (scopeType.equals(SessionScoped.class))
         {
             initSessionContext((HttpSession)startParameter);
         }
-        else if(scopeType.equals(ApplicationScoped.class))
+        else if (scopeType.equals(ApplicationScoped.class))
         {
             initApplicationContext((ServletContext)startParameter);
         }
-        else if(supportsConversation && scopeType.equals(ConversationScoped.class))
+        else if (supportsConversation && scopeType.equals(ConversationScoped.class))
         {
-            initConversationContext((ConversationContext)startParameter);
+            initConversationContext(startParameter);
         }
-        else if(scopeType.equals(Dependent.class))
+        else if (scopeType.equals(Dependent.class))
         {
             //Do nothing
         }
@@ -320,12 +320,12 @@
     @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) ||
-                (scopeType.equals(ConversationScoped.class) && supportsConversation))
+        if (scopeType.equals(RequestScoped.class) ||
+            scopeType.equals(SessionScoped.class) ||
+            scopeType.equals(ApplicationScoped.class) ||
+            scopeType.equals(Dependent.class) ||
+            scopeType.equals(Singleton.class) ||
+            (scopeType.equals(ConversationScoped.class) && supportsConversation))
         {
             return true;
         }
@@ -366,6 +366,8 @@
                 //Init thread local singleton context
                 initSingletonContext(event.getServletContext());
 
+                initConversationContext(request);
+
                 webBeansContext.getBeanManagerImpl().fireEvent(request, InitializedLiteral.INSTANCE_REQUEST_SCOPED);
             }
         }
@@ -725,15 +727,24 @@
 
     /**
      * Initialize conversation context.
-     * @param context context
+     * @param startObject either a ServletRequest or a ConversationContext
      */
-    private void initConversationContext(ConversationContext context)
+    private void initConversationContext(Object startObject)
     {
-        if (context == null)
+
+        if (startObject != null && startObject instanceof ConversationContext)
+        {
+            ConversationContext context = (ConversationContext) startObject;
+            context.setActive(true);
+            conversationContexts.set(context);
+        }
+        else
         {
             if(conversationContexts.get() == null)
             {
                 ConversationContext newContext = new ConversationContext();
+                webBeansContext.getBeanManagerImpl().fireEvent(new Object(), InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
+
                 newContext.setActive(true);
                 
                 conversationContexts.set(newContext);
@@ -742,13 +753,6 @@
             {
                 conversationContexts.get().setActive(true);
             }
-
-            webBeansContext.getBeanManagerImpl().fireEvent(new Object(), InitializedLiteral.INSTANCE_SINGLETON_SCOPED);
-        }
-        else
-        {
-            context.setActive(true);
-            conversationContexts.set(context);
         }
     }
 
diff --git a/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/test/EnterpriseTestLifeCycle.java b/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/test/EnterpriseTestLifeCycle.java
index 8305b7f..caebab8 100644
--- a/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/test/EnterpriseTestLifeCycle.java
+++ b/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/test/EnterpriseTestLifeCycle.java
@@ -18,13 +18,17 @@
  */
 package org.apache.webbeans.web.lifecycle.test;
 
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
 import java.util.Properties;
 
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.corespi.se.DefaultScannerService;
 import org.apache.webbeans.el.ELContextStore;
 import org.apache.webbeans.lifecycle.StandaloneLifeCycle;
+import org.apache.webbeans.spi.ContextsService;
 
 /**
  * Ease the writing of the tests. Simulates container
@@ -49,11 +53,11 @@
         this.mockHttpSession = new MockHttpSession();
         this.servletContextEvent = new MockServletContextEvent();
         WebBeansContext webBeansContext = getWebBeansContext();
-        ContextFactory contextFactory = webBeansContext.getContextFactory();
-        contextFactory.initRequestContext(null);
-        contextFactory.initSessionContext(mockHttpSession);
-        contextFactory.initConversationContext(null);
-        contextFactory.initApplicationContext(this.servletContextEvent.getServletContext());
+        ContextsService contextsService = webBeansContext.getContextsService();
+        contextsService.startContext(RequestScoped.class, null);
+        contextsService.startContext(SessionScoped.class, mockHttpSession);
+        contextsService.startContext(ConversationScoped.class, null);
+        contextsService.startContext(ApplicationScoped.class, this.servletContextEvent.getServletContext());
     }
     
     @Override
@@ -66,11 +70,11 @@
     public void beforeStopApplication(Object endObject)
     {
         WebBeansContext webBeansContext = getWebBeansContext();
-        ContextFactory contextFactory = webBeansContext.getContextFactory();
-        contextFactory.destroyRequestContext(null);
-        contextFactory.destroySessionContext(this.mockHttpSession);
-        contextFactory.destroyConversationContext();
-        contextFactory.destroyApplicationContext(this.servletContextEvent.getServletContext());
+        ContextsService contextsService = webBeansContext.getContextsService();
+        contextsService.endContext(RequestScoped.class, null);
+        contextsService.endContext(SessionScoped.class, this.mockHttpSession);
+        contextsService.endContext(ConversationScoped.class, null);
+        contextsService.endContext(ApplicationScoped.class, this.servletContextEvent.getServletContext());
 
         //Comment out for OWB-502
         //ContextFactory.cleanUpContextFactory();