You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/08/12 01:54:53 UTC

svn commit: r1513021 [2/3] - in /myfaces/core/trunk: api/src/main/java/javax/faces/component/ impl/src/main/java/org/apache/myfaces/cdi/ impl/src/main/java/org/apache/myfaces/cdi/impl/ impl/src/main/java/org/apache/myfaces/cdi/util/ impl/src/main/java/...

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextualStorage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextualStorage.java?rev=1513021&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextualStorage.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextualStorage.java Sun Aug 11 23:54:52 2013
@@ -0,0 +1,119 @@
+/*
+ * 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.myfaces.cdi.view;
+
+
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.PassivationCapable;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import javax.enterprise.inject.spi.Bean;
+import org.apache.myfaces.cdi.util.ContextualInstanceInfo;
+
+/**
+ * This Storage holds all information needed for storing
+ * View Scope instances in a context.
+ * 
+ * This scope requires passivation and is not concurrent.
+ */
+public class ViewScopeContextualStorage implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    private final Map<Object, ContextualInstanceInfo<?>> contextualInstances;
+    
+    private final Map<String, Object> nameBeanKeyMap;
+    
+    private final BeanManager beanManager;
+
+    /**
+     * @param beanManager is needed for serialisation
+     * @param concurrent whether the ContextualStorage might get accessed concurrently by different threads
+     * @param passivationCapable whether the storage is for passivation capable Scopes
+     */
+    public ViewScopeContextualStorage(BeanManager beanManager)
+    {
+        this.beanManager = beanManager;
+        contextualInstances = new HashMap<Object, ContextualInstanceInfo<?>>();
+        nameBeanKeyMap = new HashMap<String, Object>();
+    }
+
+    /**
+     * @return the underlying storage map.
+     */
+    public Map<Object, ContextualInstanceInfo<?>> getStorage()
+    {
+        return contextualInstances;
+    }
+    
+    public Map<String, Object> getNameBeanKeyMap()
+    {
+        return nameBeanKeyMap;
+    }
+
+    /**
+     *
+     * @param bean
+     * @param creationalContext
+     * @param <T>
+     * @return
+     */
+    public <T> T createContextualInstance(Contextual<T> bean, CreationalContext<T> creationalContext)
+    {
+        Object beanKey = getBeanKey(bean);
+
+        // simply create the contextual instance
+        ContextualInstanceInfo<T> instanceInfo = new ContextualInstanceInfo<T>();
+        instanceInfo.setCreationalContext(creationalContext);
+        instanceInfo.setContextualInstance(bean.create(creationalContext));
+
+        contextualInstances.put(beanKey, instanceInfo);
+        String name = ((Bean<T>) bean).getName();
+        if (name != null)
+        {
+            nameBeanKeyMap.put(name, beanKey);
+        }
+
+        return instanceInfo.getContextualInstance();
+    }
+
+    /**
+     * If the context is a passivating scope then we return
+     * the passivationId of the Bean. Otherwise we use
+     * the Bean directly.
+     * @return the key to use in the context map
+     */
+    public <T> Object getBeanKey(Contextual<T> bean)
+    {
+        return ((PassivationCapable) bean).getId();
+    }
+
+    /**
+     * Restores the Bean from its beanKey.
+     * @see #getBeanKey(javax.enterprise.context.spi.Contextual)
+     */
+    public Contextual<?> getBean(Object beanKey)
+    {
+        return beanManager.getPassivationCapableBean((String) beanKey);
+    }
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextualStorage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/_ContextualKey.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/_ContextualKey.java?rev=1513021&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/_ContextualKey.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/_ContextualKey.java Sun Aug 11 23:54:52 2013
@@ -0,0 +1,73 @@
+/*
+ * 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.myfaces.cdi.view;
+
+import java.io.Serializable;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+class _ContextualKey implements Serializable
+{
+    private String name;
+
+    public _ContextualKey(String name)
+    {
+        this.name = name;
+    }
+    
+    public _ContextualKey()
+    {
+    }
+    /**
+     * @return the name
+     */
+    public String getName()
+    {
+        return name;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0);
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        final _ContextualKey other = (_ContextualKey) obj;
+        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name))
+        {
+            return false;
+        }
+        return true;
+    }
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/_ContextualKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?rev=1513021&r1=1513020&r2=1513021&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java Sun Aug 11 23:54:52 2013
@@ -118,7 +118,7 @@ import org.apache.myfaces.flow.ReturnNod
 import org.apache.myfaces.flow.SwitchCaseImpl;
 import org.apache.myfaces.flow.SwitchNodeImpl;
 import org.apache.myfaces.flow.ViewNodeImpl;
-import org.apache.myfaces.flow.cdi.AnnotatedFlowConfigurator;
+import org.apache.myfaces.flow.impl.AnnotatedFlowConfigurator;
 import org.apache.myfaces.lifecycle.LifecycleFactoryImpl;
 import org.apache.myfaces.renderkit.RenderKitFactoryImpl;
 import org.apache.myfaces.renderkit.html.HtmlRenderKitImpl;

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/FlowHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/FlowHandlerImpl.java?rev=1513021&r1=1513020&r2=1513021&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/FlowHandlerImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/FlowHandlerImpl.java Sun Aug 11 23:54:52 2013
@@ -33,8 +33,8 @@ import javax.faces.flow.FlowCallNode;
 import javax.faces.flow.FlowHandler;
 import javax.faces.flow.Parameter;
 import javax.faces.lifecycle.ClientWindow;
-import org.apache.myfaces.flow.cdi.FlowScopeMap;
-import org.apache.myfaces.flow.cdi.FlowScopedContextImpl;
+import org.apache.myfaces.spi.FacesFlowProvider;
+import org.apache.myfaces.spi.FacesFlowProviderFactory;
 
 /**
  *
@@ -49,11 +49,11 @@ public class FlowHandlerImpl extends Flo
     private final static String FLOW_RETURN_STACK = "oam.flow.RETURN_STACK.";
     private final static String CURRENT_FLOW_REQUEST_STACK = "oam.flow.REQUEST_STACK.";
     
-    private final static String CURRENT_FLOW_SCOPE_MAP = "oam.flow.SCOPE_MAP";
-    
     private Map<String, Map<String, Flow>> _flowMapByDocumentId;
     private Map<String, Flow> _flowMapById;
     
+    private FacesFlowProvider _facesFlowProvider;
+    
     public FlowHandlerImpl()
     {
         _flowMapByDocumentId = new ConcurrentHashMap<String, Map<String, Flow>>();
@@ -304,7 +304,7 @@ public class FlowHandlerImpl extends Flo
     
     private void doAfterEnterFlow(FacesContext context, Flow flow, Map<String, Object> outboundParameters)
     {
-        FlowScopedContextImpl.createCurrentFlowScope(context);
+        getFacesFlowProvider(context).doAfterEnterFlow(context, flow);
         
         if (flow.getInitializer() != null)
         {
@@ -324,9 +324,22 @@ public class FlowHandlerImpl extends Flo
         }
     }
     
+    public FacesFlowProvider getFacesFlowProvider(FacesContext facesContext)
+    {
+        if (_facesFlowProvider == null)
+        {
+            FacesFlowProviderFactory factory = 
+                FacesFlowProviderFactory.getFacesFlowProviderFactory(
+                    facesContext.getExternalContext());
+            _facesFlowProvider = factory.getFacesFlowProvider(
+                    facesContext.getExternalContext());
+        }
+        return _facesFlowProvider;
+    }
+    
     private void doBeforeExitFlow(FacesContext context, Flow flow)
     {
-        FlowScopedContextImpl.destroyCurrentFlowScope(context);
+        getFacesFlowProvider(context).doBeforeExitFlow(context, flow);
         
         if (flow.getFinalizer() != null)
         {
@@ -371,14 +384,7 @@ public class FlowHandlerImpl extends Flo
     public Map<Object, Object> getCurrentFlowScope()
     {
         FacesContext facesContext = FacesContext.getCurrentInstance();
-        Map<Object, Object> map = (Map<Object, Object>) facesContext.getAttributes().get(
-            CURRENT_FLOW_SCOPE_MAP);
-        if (map == null)
-        {
-            map = new FlowScopeMap();
-            facesContext.getAttributes().put(CURRENT_FLOW_SCOPE_MAP, map);
-        }
-        return map;
+        return getFacesFlowProvider(facesContext).getCurrentFlowScope(facesContext);
     }
 
     @Override

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/DefaultCDIFacesFlowProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/DefaultCDIFacesFlowProvider.java?rev=1513021&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/DefaultCDIFacesFlowProvider.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/DefaultCDIFacesFlowProvider.java Sun Aug 11 23:54:52 2013
@@ -0,0 +1,127 @@
+/*
+ * 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.myfaces.flow.cdi;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.context.FacesContext;
+import javax.faces.flow.Flow;
+import org.apache.myfaces.cdi.util.CDIUtils;
+import org.apache.myfaces.spi.FacesFlowProvider;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public class DefaultCDIFacesFlowProvider extends FacesFlowProvider
+{
+    private BeanManager _beanManager;
+    private boolean _initialized;
+    
+    private final static String CURRENT_FLOW_SCOPE_MAP = "oam.flow.SCOPE_MAP";
+    
+    @Override
+    public Iterator<Flow> getAnnotatedFlows(FacesContext facesContext)
+    {
+        BeanManager beanManager = getBeanManager(facesContext);
+        if (beanManager != null)
+        {
+            FlowBuilderFactoryBean bean = CDIUtils.lookup(
+                beanManager, FlowBuilderFactoryBean.class);
+
+            Instance<Flow> instance = bean.getFlowDefinitions();
+            
+            return instance.iterator();
+        }
+        else
+        {
+            Logger.getLogger(DefaultCDIFacesFlowProvider.class.getName()).log(Level.INFO,
+                "CDI BeanManager not found");
+        }
+        return null;
+    }
+    
+    @Override
+    public void doAfterEnterFlow(FacesContext context, Flow flow)
+    {
+        BeanManager beanManager = getBeanManager(context);
+        if (beanManager != null)
+        {
+            FlowScopeBeanHolder beanHolder = CDIUtils.lookup(beanManager, FlowScopeBeanHolder.class);
+            beanHolder.createCurrentFlowScope(context);
+        }
+    }
+    
+    @Override
+    public void doBeforeExitFlow(FacesContext context, Flow flow)
+    {
+        BeanManager beanManager = getBeanManager(context);
+        if (beanManager != null)
+        {
+            FlowScopeBeanHolder beanHolder = CDIUtils.lookup(beanManager, FlowScopeBeanHolder.class);
+            beanHolder.destroyCurrentFlowScope(context);
+        }
+    }
+    
+    public Map<Object, Object> getCurrentFlowScope(FacesContext facesContext)
+    {
+        Flow flow = facesContext.getApplication().getFlowHandler().getCurrentFlow(facesContext);
+        if (flow != null)
+        {
+            Map<Object, Object> map = (Map<Object, Object>) facesContext.getAttributes().get(
+                CURRENT_FLOW_SCOPE_MAP);
+            if (map == null)
+            {
+                map = new FlowScopeMap(getBeanManager(), flow.getClientWindowFlowId(
+                    facesContext.getExternalContext().getClientWindow()));
+                
+                facesContext.getAttributes().put(CURRENT_FLOW_SCOPE_MAP, map);
+            }
+            return map;
+        }
+        return null;
+    }
+    
+    public BeanManager getBeanManager()
+    {
+        if (_beanManager == null && !_initialized)
+        {
+            _beanManager = CDIUtils.getBeanManager(
+                FacesContext.getCurrentInstance().getExternalContext());
+            _initialized = true;
+        }
+        return _beanManager;
+    }
+    
+    public BeanManager getBeanManager(FacesContext facesContext)
+    {
+        if (_beanManager == null && !_initialized)
+        {
+            _beanManager = CDIUtils.getBeanManager(
+                facesContext.getExternalContext());
+            _initialized = true;
+        }
+        return _beanManager;
+    }
+
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/DefaultCDIFacesFlowProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java?rev=1513021&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java Sun Aug 11 23:54:52 2013
@@ -0,0 +1,230 @@
+/*
+ * 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.myfaces.flow.cdi;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.context.FacesContext;
+import javax.faces.flow.Flow;
+import javax.faces.flow.FlowHandler;
+import javax.faces.lifecycle.ClientWindow;
+import org.apache.myfaces.cdi.util.ContextualInstanceInfo;
+import org.apache.myfaces.cdi.util.ContextualStorage;
+
+
+/**
+ *
+ * This holder will store the flow scope active ids and it's beans for the current
+ * HTTP Session. We use standard SessionScoped bean to not need
+ * to treat async-supported and similar headache.
+ * 
+ * @author lu4242
+ */
+@SessionScoped
+public class FlowScopeBeanHolder implements Serializable
+{
+    /**
+     * key: client window id + flow id
+     * value: the {@link ContextualStorage} which holds all the
+     * {@link javax.enterprise.inject.spi.Bean}s.
+     */
+    private Map<String, ContextualStorage> storageMap = new ConcurrentHashMap<String, ContextualStorage>();
+    
+    private Map<String, List<String>> activeFlowMapKeys = new ConcurrentHashMap<String, List<String>>();
+    
+    public static final String CURRENT_FLOW_SCOPE_MAP = "oam.CURRENT_FLOW_SCOPE_MAP";
+
+    public FlowScopeBeanHolder()
+    {
+    }
+        
+    /**
+     * This method will return the ContextualStorage or create a new one
+     * if no one is yet assigned to the current flowClientWindowId.
+     * @param beanManager we need the CDI {@link BeanManager} for serialisation.
+     * @param flowClientWindowId the flowClientWindowId for the current flow.
+     */
+    public ContextualStorage getContextualStorage(BeanManager beanManager, String flowClientWindowId)
+    {
+        ContextualStorage contextualStorage = storageMap.get(flowClientWindowId);
+        if (contextualStorage == null)
+        {
+            synchronized (this)
+            {
+                contextualStorage = storageMap.get(flowClientWindowId);
+                if (contextualStorage == null)
+                {
+                    storageMap.put(flowClientWindowId, new ContextualStorage(beanManager, true, true));
+                }
+            }
+        }
+
+        return contextualStorage;
+    }
+    
+    public ContextualStorage getContextualStorageNoCreate(BeanManager beanManager, String flowClientWindowId)
+    {
+        return storageMap.get(flowClientWindowId);
+    }
+
+    public Map<String, ContextualStorage> getStorageMap()
+    {
+        return storageMap;
+    }
+    
+    public Map<Object, Object> getFlowScopeMap(
+        BeanManager beanManager, String flowClientWindowId, boolean create)
+    {
+        Map<Object, Object> map = null;
+        if (create)
+        {
+            ContextualStorage contextualStorage = getContextualStorage(
+                beanManager, flowClientWindowId);
+            ContextualInstanceInfo info = contextualStorage.getStorage().get(CURRENT_FLOW_SCOPE_MAP);
+            if (info == null)
+            {
+                info = new ContextualInstanceInfo<Object>();
+                contextualStorage.getStorage().put(CURRENT_FLOW_SCOPE_MAP, info);
+            }
+            map = (Map<Object, Object>) info.getContextualInstance();
+            if (map == null)
+            {
+                map = new HashMap<Object,Object>();
+                info.setContextualInstance(map);
+            }
+        }
+        else
+        {
+            ContextualStorage contextualStorage = getContextualStorageNoCreate(
+                beanManager, flowClientWindowId);
+            if (contextualStorage != null)
+            {
+                ContextualInstanceInfo info = contextualStorage.getStorage().get(CURRENT_FLOW_SCOPE_MAP);
+                if (info != null)
+                {
+                    map = (Map<Object, Object>) info.getContextualInstance();
+                }
+            }
+        }
+        return map;
+    }
+
+    /**
+     *
+     * This method will replace the storageMap and with
+     * a new empty one.
+     * This method can be used to properly destroy the WindowBeanHolder beans
+     * without having to sync heavily. Any
+     * {@link javax.enterprise.inject.spi.Bean#destroy(Object, javax.enterprise.context.spi.CreationalContext)}
+     * should be performed on the returned old storage map.
+     * @return the old storageMap.
+     */
+    public Map<String, ContextualStorage> forceNewStorage()
+    {
+        Map<String, ContextualStorage> oldStorageMap = storageMap;
+        storageMap = new ConcurrentHashMap<String, ContextualStorage>();
+        return oldStorageMap;
+    }
+
+    /**
+     * This method properly destroys all current &#064;WindowScoped beans
+     * of the active session and also prepares the storage for new beans.
+     * It will automatically get called when the session context closes
+     * but can also get invoked manually, e.g. if a user likes to get rid
+     * of all it's &#064;WindowScoped beans.
+     */
+    @PreDestroy
+    public void destroyBeans()
+    {
+        // we replace the old windowBeanHolder beans with a new storage Map
+        // an afterwards destroy the old Beans without having to care about any syncs.
+        Map<String, ContextualStorage> oldWindowContextStorages = forceNewStorage();
+
+        for (ContextualStorage contextualStorage : oldWindowContextStorages.values())
+        {
+            FlowScopedContextImpl.destroyAllActive(contextualStorage);
+        }
+    }
+    
+    public List<String> getActiveFlowMapKeys(FacesContext facesContext)
+    {
+        ClientWindow cw = facesContext.getExternalContext().getClientWindow();
+        String baseKey = cw.getId();
+        List<String> activeFlowKeys = activeFlowMapKeys.get(baseKey);
+        if (activeFlowKeys == null)
+        {
+            return Collections.emptyList();
+        }
+        else
+        {
+            return activeFlowKeys;
+        }
+    }
+
+    public void createCurrentFlowScope(FacesContext facesContext)
+    {
+        ClientWindow cw = facesContext.getExternalContext().getClientWindow();
+        String baseKey = cw.getId();
+        
+        FlowHandler flowHandler = facesContext.getApplication().getFlowHandler();
+        Flow flow = flowHandler.getCurrentFlow(facesContext);
+        String flowMapKey = flow.getClientWindowFlowId(
+            facesContext.getExternalContext().getClientWindow());
+
+        List<String> activeFlowKeys = activeFlowMapKeys.get(baseKey);
+        if (activeFlowKeys == null)
+        {
+            activeFlowKeys = new ArrayList<String>();
+            
+        }
+        activeFlowKeys.add(0, flowMapKey);
+        activeFlowMapKeys.put(baseKey, activeFlowKeys);
+    }
+    
+    public void destroyCurrentFlowScope(FacesContext facesContext)
+    {
+        ClientWindow cw = facesContext.getExternalContext().getClientWindow();
+        String baseKey = cw.getId();
+        
+        FlowHandler flowHandler = facesContext.getApplication().getFlowHandler();
+        Flow flow = flowHandler.getCurrentFlow(facesContext);
+        String flowMapKey = flow.getClientWindowFlowId(
+            facesContext.getExternalContext().getClientWindow());
+
+        ContextualStorage contextualStorage = storageMap.get(flowMapKey);
+        if (contextualStorage != null)
+        {
+            FlowScopedContextImpl.destroyAllActive(contextualStorage);
+        }
+        
+        List<String> activeFlowKeys = activeFlowMapKeys.get(baseKey);
+        if (activeFlowKeys != null && !activeFlowKeys.isEmpty())
+        {
+            activeFlowKeys.remove(flowMapKey);
+        }
+    }
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeCDIExtension.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeCDIExtension.java?rev=1513021&r1=1513020&r2=1513021&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeCDIExtension.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeCDIExtension.java Sun Aug 11 23:54:52 2013
@@ -20,8 +20,12 @@ package org.apache.myfaces.flow.cdi;
 
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AfterDeploymentValidation;
+import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.Extension;
+import org.apache.myfaces.cdi.util.BeanProvider;
 
 /**
  *
@@ -29,9 +33,28 @@ import javax.enterprise.inject.spi.Exten
  */
 public class FlowScopeCDIExtension implements Extension
 {
+    private FlowScopedContextImpl flowScopedContext;
     
-    public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager)
+    void beforeBeanDiscovery(
+        @Observes final BeforeBeanDiscovery event, BeanManager beanManager)
     {
-        event.addContext(new FlowScopedContextImpl());
+        // Register FlowBuilderFactoryBean as a bean with CDI annotations, so the system
+        // can take it into account, and use it later when necessary.
+        AnnotatedType bean = beanManager.createAnnotatedType(FlowScopeBeanHolder.class);
+        event.addAnnotatedType(bean);
+    }
+    
+    void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager)
+    {
+        flowScopedContext = new FlowScopedContextImpl(manager);
+        event.addContext(flowScopedContext);
+    }
+    
+    void initializeFlowContexts(@Observes AfterDeploymentValidation adv, BeanManager beanManager)
+    {
+        FlowScopeBeanHolder flowScopeBeanHolder = BeanProvider.getContextualReference(
+            beanManager, FlowScopeBeanHolder.class, false);
+        
+        flowScopedContext.initFlowContext(flowScopeBeanHolder);
     }
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeMap.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeMap.java?rev=1513021&r1=1513020&r2=1513021&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeMap.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeMap.java Sun Aug 11 23:54:52 2013
@@ -18,13 +18,12 @@
  */
 package org.apache.myfaces.flow.cdi;
 
+import org.apache.myfaces.cdi.util.CDIUtils;
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import javax.faces.context.FacesContext;
-import javax.faces.flow.Flow;
-import javax.faces.flow.FlowHandler;
+import javax.enterprise.inject.spi.BeanManager;
+import org.apache.myfaces.cdi.util.BeanProvider;
 
 /**
  * 
@@ -33,137 +32,185 @@ import javax.faces.flow.FlowHandler;
  */
 public class FlowScopeMap implements Map
 {
+    private BeanManager _beanManager;
+    private String _currentClientWindowFlowId;
+    private FlowScopeBeanHolder _flowScopeBeanHolder;
+    private boolean _initOptional = false;
     
-    public FlowScopeMap()
+    public FlowScopeMap(BeanManager beanManager, String currentFlowMapKey)
     {
+        this._beanManager = beanManager;
+        this._currentClientWindowFlowId = currentFlowMapKey;
     }
-
-    public int size()
+    
+    private FlowScopeBeanHolder getFlowScopeBeanHolder(boolean create)
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        int size = 0;
-        List<String> activeFlowMapKeys = FlowScopedContextImpl.getActiveFlowMapKeys(facesContext);
-        for (String flowMapKey : activeFlowMapKeys)
+        if (_flowScopeBeanHolder == null)
         {
-            Map flowScopeMap = FlowScopedContextImpl.getFlowScopedMap(facesContext, flowMapKey);
-            if (flowScopeMap.size() >= 0)
+            if (create)
+            {
+                _flowScopeBeanHolder = CDIUtils.lookup(_beanManager,
+                    FlowScopeBeanHolder.class);
+            }
+            else if (!_initOptional)
             {
-                size += flowScopeMap.size();
+                _flowScopeBeanHolder = BeanProvider.getContextualReference(
+                    _beanManager, FlowScopeBeanHolder.class, true);
+                _initOptional = true;
             }
         }
-        return size;
+        return _flowScopeBeanHolder;
     }
     
-    private Map getCurrentMap()
+    public int size()
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        FlowHandler flowHandler = facesContext.getApplication().getFlowHandler();
-        Flow flow = flowHandler.getCurrentFlow(facesContext);
-        String flowMapKey = flow.getClientWindowFlowId(
-            facesContext.getExternalContext().getClientWindow());
-        return FlowScopedContextImpl.getFlowScopedMap(facesContext, flowMapKey);
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
+        if (flowScopeBeanHolder == null)
+        {
+            return 0;
+        }
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
+            _currentClientWindowFlowId, false);
+        if (map == null)
+        {
+            return 0;
+        }
+        return map.size();
     }
-
+    
     public boolean isEmpty()
     {
-        return size() == 0;
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
+        if (flowScopeBeanHolder == null)
+        {
+            return true;
+        }
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
+            _currentClientWindowFlowId, false);
+        if (map == null)
+        {
+            return true;
+        }
+        return map.isEmpty();
     }
 
     public boolean containsKey(Object key)
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        List<String> activeFlowMapKeys = FlowScopedContextImpl.getActiveFlowMapKeys(facesContext);
-        for (String flowMapKey : activeFlowMapKeys)
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
+        if (flowScopeBeanHolder == null)
         {
-            Map flowScopeMap = FlowScopedContextImpl.getFlowScopedMap(facesContext, flowMapKey);
-            if (flowScopeMap.containsKey(key))
-            {
-                return true;
-            }
+            return false;
         }
-        return false;
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
+            _currentClientWindowFlowId, false);
+        if (map == null)
+        {
+            return false;
+        }
+        return map.containsKey(key);
     }
 
     public boolean containsValue(Object value)
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        List<String> activeFlowMapKeys = FlowScopedContextImpl.getActiveFlowMapKeys(facesContext);
-        for (String flowMapKey : activeFlowMapKeys)
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
+        if (flowScopeBeanHolder == null)
         {
-            Map flowScopeMap = FlowScopedContextImpl.getFlowScopedMap(facesContext, flowMapKey);
-            if (flowScopeMap.containsValue(value))
-            {
-                return true;
-            }
+            return false;
         }
-        return false;
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
+            _currentClientWindowFlowId, false);
+        if (map == null)
+        {
+            return false;
+        }
+        return map.containsValue(value);
     }
 
     public Object get(Object key)
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        List<String> activeFlowMapKeys = FlowScopedContextImpl.getActiveFlowMapKeys(facesContext);
-        for (String flowMapKey : activeFlowMapKeys)
-        {
-            Map flowScopeMap = FlowScopedContextImpl.getFlowScopedMap(facesContext, flowMapKey);
-            
-            if (flowScopeMap.containsKey(key))
-            {
-                return flowScopeMap.get(key);
-            }
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
+        if (flowScopeBeanHolder == null)
+        {
+            return null;
         }
-        return null;
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
+            _currentClientWindowFlowId, false);
+        if (map == null)
+        {
+            return null;
+        }
+        return map.get(key);
     }
 
     public Object put(Object key, Object value)
     {
-        return getCurrentMap().put(key, value);
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
+            _beanManager, _currentClientWindowFlowId, true);
+        return map.put(key, value);
     }
 
     public Object remove(Object key)
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        List<String> activeFlowMapKeys = FlowScopedContextImpl.getActiveFlowMapKeys(facesContext);
-        for (String flowMapKey : activeFlowMapKeys)
-        {
-            Map flowScopeMap = FlowScopedContextImpl.getFlowScopedMap(facesContext, flowMapKey);
-            Object removedValue = flowScopeMap.remove(key);
-            if (removedValue != null)
-            {
-                return removedValue;
-            }
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
+        if (flowScopeBeanHolder == null)
+        {
+            return null;
         }
-        return null;
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
+            _currentClientWindowFlowId, false);
+        if (map == null)
+        {
+            return null;
+        }
+        return map.remove(key);
     }
 
     public void putAll(Map m)
     {
-        getCurrentMap().putAll(m);
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
+            _beanManager, _currentClientWindowFlowId, true);
+        map.putAll(m);
     }
 
     public void clear()
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        List<String> activeFlowMapKeys = FlowScopedContextImpl.getActiveFlowMapKeys(facesContext);
-        for (String flowMapKey : activeFlowMapKeys)
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(false);
+        if (flowScopeBeanHolder == null)
+        {
+            return;
+        }
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(_beanManager,
+            _currentClientWindowFlowId, false);
+        if (map == null)
         {
-            Map flowScopeMap = FlowScopedContextImpl.getFlowScopedMap(facesContext, flowMapKey);
-            flowScopeMap.clear();
+            return;
         }
+        map.clear();
     }
 
     public Set keySet()
     {
-        return getCurrentMap().keySet();
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
+            _beanManager, _currentClientWindowFlowId, true);
+        return map.keySet();
     }
 
     public Collection values()
     {
-        return getCurrentMap().values();
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
+            _beanManager, _currentClientWindowFlowId, true);
+        return map.values();
     }
 
     public Set entrySet()
     {
-        return getCurrentMap().entrySet();
+        FlowScopeBeanHolder flowScopeBeanHolder = getFlowScopeBeanHolder(true);
+        Map<Object, Object> map = flowScopeBeanHolder.getFlowScopeMap(
+            _beanManager, _currentClientWindowFlowId, true);
+        return map.entrySet();
     }
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopedContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopedContextImpl.java?rev=1513021&r1=1513020&r2=1513021&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopedContextImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopedContextImpl.java Sun Aug 11 23:54:52 2013
@@ -19,20 +19,21 @@
 package org.apache.myfaces.flow.cdi;
 
 import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import javax.enterprise.context.ContextNotActiveException;
 import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.faces.context.ExternalContext;
+import javax.enterprise.inject.Typed;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.PassivationCapable;
 import javax.faces.context.FacesContext;
 import javax.faces.flow.Flow;
 import javax.faces.flow.FlowHandler;
 import javax.faces.flow.FlowScoped;
-import javax.faces.lifecycle.ClientWindow;
+import org.apache.myfaces.cdi.util.ContextualInstanceInfo;
+import org.apache.myfaces.cdi.util.ContextualStorage;
 
 /**
  * Minimal implementation of FlowScope.
@@ -48,175 +49,259 @@ import javax.faces.lifecycle.ClientWindo
  *
  * @author Leonardo Uribe
  */
+@Typed()
 public class FlowScopedContextImpl implements Context
 {
-    private static final String FLOW_PREFIX = "oam.FacesFlow";
-    
-    static final String FLOW_SCOPE_MAP = FLOW_PREFIX + ".MAP";
+    /**
+     * Whether the Context is for a passivating scope.
+     */
+    private final boolean passivatingScope;
+
+    /**
+     * needed for serialisation and passivationId
+     */
+    private BeanManager beanManager;
+
+    private FlowScopeBeanHolder flowScopeBeanHolder;
     
-    static final String FLOW_SESSION_MAP_SUBKEY_PREFIX = FLOW_PREFIX + ".SCOPE";
+    public FlowScopedContextImpl(BeanManager beanManager)
+    {
+        this.beanManager = beanManager;
+        passivatingScope = beanManager.isPassivatingScope(getScope());
+    }
     
-    static final String FLOW_ACTIVE_FLOWS = FLOW_PREFIX + ".ACTIVE_FLOWS";
+    public void initFlowContext(FlowScopeBeanHolder flowScopeBeanHolder)
+    {
+        this.flowScopeBeanHolder = flowScopeBeanHolder;
+    }
     
+    public String getCurrentClientWindowFlowId(FacesContext facesContext)
+    {
+        String flowMapKey = null;
+        FlowHandler flowHandler = facesContext.getApplication().getFlowHandler();
+        Flow flow = flowHandler.getCurrentFlow(facesContext);
+        if (flow != null)
+        {
+            flowMapKey = flow.getClientWindowFlowId(
+                facesContext.getExternalContext().getClientWindow());
+        }
+        return flowMapKey;
+    }
+
     /**
-     * Token separator.
+     * An implementation has to return the underlying storage which
+     * contains the items held in the Context.
+     * @param createIfNotExist whether a ContextualStorage shall get created if it doesn't yet exist.
+     * @return the underlying storage
      */
-    static final char SEPARATOR_CHAR = '.';
+    protected ContextualStorage getContextualStorage(boolean createIfNotExist, String clientWindowFlowId)
+    {
+        //FacesContext facesContext = FacesContext.getCurrentInstance();
+        //String clientWindowFlowId = getCurrentClientWindowFlowId(facesContext);
+        if (clientWindowFlowId == null)
+        {
+            throw new ContextNotActiveException("FlowScopedContextImpl: no current active flow");
+        }
+
+        return flowScopeBeanHolder.getContextualStorage(beanManager, clientWindowFlowId);
+    }
 
     public Class<? extends Annotation> getScope()
     {
         return FlowScoped.class;
     }
 
-    public <T> T get(Contextual<T> component, CreationalContext<T> creationalContext)
+    public boolean isActive()
+    {
+        return isActive(FacesContext.getCurrentInstance());
+    }
+
+    public boolean isActive(FacesContext facesContext)
+    {
+        if (facesContext == null)
+        {
+            return false;
+        }
+        Flow flow = facesContext.getApplication().
+            getFlowHandler().getCurrentFlow(facesContext);
+        
+        return flow != null;
+    }
+
+    /**
+     * @return whether the served scope is a passivating scope
+     */
+    public boolean isPassivatingScope()
+    {
+        return passivatingScope;
+    }
+
+    @Override
+    public <T> T get(Contextual<T> bean)
     {
-        Bean<T> bean = (Bean<T>) component;
         FacesContext facesContext = FacesContext.getCurrentInstance();
-        List<String> activeFlowMapKeys = getActiveFlowMapKeys(facesContext);
+
+        checkActive(facesContext);
+
+        
+        List<String> activeFlowMapKeys = flowScopeBeanHolder.getActiveFlowMapKeys(facesContext);
         for (String flowMapKey : activeFlowMapKeys)
         {
-            Map flowScopeMap = getFlowScopedMap(facesContext, flowMapKey);
-            if (flowScopeMap != null)
+            ContextualStorage storage = getContextualStorage(false, flowMapKey);
+            if (storage == null)
             {
-                if(flowScopeMap.containsKey(bean.getName())) 
-                {
-                    return (T) flowScopeMap.get(bean.getName());
-                }
+                //return null;
+                continue;
             }
-        }
-        
-        FlowHandler flowHandler = facesContext.getApplication().getFlowHandler();
-        Flow flow = flowHandler.getCurrentFlow(facesContext);
-        if (flow != null)
-        {
-            String flowMapKey = flow.getClientWindowFlowId(
-                facesContext.getExternalContext().getClientWindow());
-            
-            Map flowScopeMap = getFlowScopedMap(facesContext, flowMapKey);
-            if (flowScopeMap != null)
+
+            Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
+            ContextualInstanceInfo<?> contextualInstanceInfo = contextMap.get(storage.getBeanKey(bean));
+            if (contextualInstanceInfo == null)
             {
-                T t = bean.create(creationalContext);
-                flowScopeMap.put(bean.getName(), t);
-                return t;
+                //return null;
+                continue;
             }
+
+            return (T) contextualInstanceInfo.getContextualInstance();
         }
         return null;
     }
-    
-    static Map getFlowScopedMap(FacesContext facesContext, String flowMapKey)
-    {
-        String baseKey = FLOW_SCOPE_MAP + SEPARATOR_CHAR + flowMapKey;
-        Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
-        Map<String, Object> map = (Map<String, Object>) requestMap.get(baseKey);
-        if (map == null)
-        {
-            String fullToken = FLOW_SESSION_MAP_SUBKEY_PREFIX + SEPARATOR_CHAR + flowMapKey;
-            map =  _createSubKeyMap(facesContext, fullToken);
-            requestMap.put(baseKey, map);
-        }
-        return map;
-    }
-    
-    public static List<String> getActiveFlowMapKeys(FacesContext facesContext)
+
+    @Override
+    public <T> T get(Contextual<T> bean, CreationalContext<T> creationalContext)
     {
-        ClientWindow cw = facesContext.getExternalContext().getClientWindow();
-        String baseKey = FLOW_ACTIVE_FLOWS + SEPARATOR_CHAR + cw.getId();
-        List<String> activeFlowKeys = (List<String>) facesContext.
-            getExternalContext().getSessionMap().get(baseKey);
-        if (activeFlowKeys == null)
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        
+        checkActive(facesContext);
+
+        if (passivatingScope)
         {
-            return Collections.emptyList();
+            if (!(bean instanceof PassivationCapable))
+            {
+                throw new IllegalStateException(bean.toString() +
+                        " doesn't implement " + PassivationCapable.class.getName());
+            }
         }
-        else
+
+        List<String> activeFlowMapKeys = flowScopeBeanHolder.getActiveFlowMapKeys(facesContext);
+        for (String flowMapKey : activeFlowMapKeys)
         {
-            return activeFlowKeys;
+            ContextualStorage storage = getContextualStorage(false, flowMapKey);
+
+            Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
+            ContextualInstanceInfo<?> contextualInstanceInfo = contextMap.get(storage.getBeanKey(bean));
+
+            if (contextualInstanceInfo != null)
+            {
+                @SuppressWarnings("unchecked")
+                final T instance =  (T) contextualInstanceInfo.getContextualInstance();
+
+                if (instance != null)
+                {
+                    return instance;
+                }
+            }
+
         }
-    }
-    
-    public static void createCurrentFlowScope(FacesContext facesContext)
-    {
-        ClientWindow cw = facesContext.getExternalContext().getClientWindow();
-        String baseKey = FLOW_ACTIVE_FLOWS + SEPARATOR_CHAR + cw.getId();
         
-        FlowHandler flowHandler = facesContext.getApplication().getFlowHandler();
-        Flow flow = flowHandler.getCurrentFlow(facesContext);
-        String flowMapKey = flow.getClientWindowFlowId(
-            facesContext.getExternalContext().getClientWindow());
+        ContextualStorage storage = getContextualStorage(true, getCurrentClientWindowFlowId(facesContext));
+        Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
+        ContextualInstanceInfo<?> contextualInstanceInfo = contextMap.get(storage.getBeanKey(bean));
 
-        List<String> activeFlowKeys = (List<String>) facesContext.
-            getExternalContext().getSessionMap().get(baseKey);
-        if (activeFlowKeys == null)
+        if (contextualInstanceInfo != null)
         {
-            activeFlowKeys = new ArrayList<String>();
-            
+            @SuppressWarnings("unchecked")
+            final T instance =  (T) contextualInstanceInfo.getContextualInstance();
+
+            if (instance != null)
+            {
+                return instance;
+            }
         }
-        activeFlowKeys.add(flowMapKey);
-        facesContext.getExternalContext().getSessionMap().put(baseKey, activeFlowKeys);
+            
+        return storage.createContextualInstance(bean, creationalContext);
     }
-    
-    public static void destroyCurrentFlowScope(FacesContext facesContext)
-    {
-        ClientWindow cw = facesContext.getExternalContext().getClientWindow();
-        String baseKey = FLOW_ACTIVE_FLOWS + SEPARATOR_CHAR + cw.getId();
-        
-        FlowHandler flowHandler = facesContext.getApplication().getFlowHandler();
-        Flow flow = flowHandler.getCurrentFlow(facesContext);
-        String flowMapKey = flow.getClientWindowFlowId(
-            facesContext.getExternalContext().getClientWindow());
 
-        Map flowScopeMap = getFlowScopedMap(facesContext, flowMapKey);
-        flowScopeMap.clear();
-        
-        List<String> activeFlowKeys = (List<String>) facesContext.
-            getExternalContext().getSessionMap().get(baseKey);
-        if (activeFlowKeys != null && !activeFlowKeys.isEmpty())
+    /**
+     * Destroy the Contextual Instance of the given Bean.
+     * @param bean dictates which bean shall get cleaned up
+     * @return <code>true</code> if the bean was destroyed, <code>false</code> if there was no such bean.
+     */
+    public boolean destroy(Contextual bean)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        List<String> activeFlowMapKeys = flowScopeBeanHolder.getActiveFlowMapKeys(facesContext);
+        for (String flowMapKey : activeFlowMapKeys)
         {
-            activeFlowKeys.remove(flowMapKey);
+            ContextualStorage storage = getContextualStorage(false, flowMapKey);
+            if (storage == null)
+            {
+                //return false;
+                continue;
+            }
+            ContextualInstanceInfo<?> contextualInstanceInfo = storage.getStorage().get(storage.getBeanKey(bean));
+
+            if (contextualInstanceInfo == null)
+            {
+                //return false;
+                continue;
+            }
+
+            bean.destroy(contextualInstanceInfo.getContextualInstance(), contextualInstanceInfo.getCreationalContext());
+            return true;
         }
+        return false;
     }
-    
+
     /**
-     * Create a new subkey-wrapper of the session map with the given prefix.
-     * This wrapper is used to implement the maps for the flash scope.
-     * For more information see the SubKeyMap doc.
+     * destroys all the Contextual Instances in the Storage returned by
+     * {@link #getContextualStorage(boolean)}.
      */
-    private static Map<String, Object> _createSubKeyMap(FacesContext context, String prefix)
+    /*
+    public void destroyAllActive()
     {
-        ExternalContext external = context.getExternalContext();
-        Map<String, Object> sessionMap = external.getSessionMap();
+        ContextualStorage storage = getContextualStorage(false);
+        if (storage == null)
+        {
+            return;
+        }
 
-        return new SubKeyMap<Object>(sessionMap, prefix);
-    }
+        destroyAllActive(storage);
+    }*/
 
-    public <T> T get(Contextual<T> component)
+    /**
+     * Destroys all the Contextual Instances in the specified ContextualStorage.
+     * This is a static method to allow various holder objects to cleanup
+     * properly in &#064;PreDestroy.
+     */
+    public static void destroyAllActive(ContextualStorage storage)
     {
-        Bean bean = (Bean) component;
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        List<String> activeFlowMapKeys = getActiveFlowMapKeys(facesContext);
-        for (String flowMapKey : activeFlowMapKeys)
+        Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
+        for (Map.Entry<Object, ContextualInstanceInfo<?>> entry : contextMap.entrySet())
         {
-            Map flowScopeMap = getFlowScopedMap(facesContext, flowMapKey);
-            if (flowScopeMap != null)
+            if (!FlowScopeBeanHolder.CURRENT_FLOW_SCOPE_MAP.equals(entry.getKey()))
             {
-                if(flowScopeMap.containsKey(bean.getName()))
-                {
-                    return (T) flowScopeMap.get(bean.getName());
-                }
+                Contextual bean = storage.getBean(entry.getKey());
+
+                ContextualInstanceInfo<?> contextualInstanceInfo = entry.getValue();
+                bean.destroy(contextualInstanceInfo.getContextualInstance(), 
+                    contextualInstanceInfo.getCreationalContext());
             }
         }
-        return null;
     }
 
-    public boolean isActive()
+    /**
+     * Make sure that the Context is really active.
+     * @throws ContextNotActiveException if there is no active
+     *         Context for the current Thread.
+     */
+    protected void checkActive(FacesContext facesContext)
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        if (facesContext == null)
+        if (!isActive(facesContext))
         {
-            return false;
+            throw new ContextNotActiveException("CDI context with scope annotation @"
+                + getScope().getName() + " is not active with respect to the current thread");
         }
-        Flow flow = facesContext.getApplication().
-            getFlowHandler().getCurrentFlow(facesContext);
-        
-        return flow != null;
     }
+
 }

Copied: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/AnnotatedFlowConfigurator.java (from r1509781, myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/AnnotatedFlowConfigurator.java)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/AnnotatedFlowConfigurator.java?p2=myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/AnnotatedFlowConfigurator.java&p1=myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/AnnotatedFlowConfigurator.java&r1=1509781&r2=1513021&rev=1513021&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/AnnotatedFlowConfigurator.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/AnnotatedFlowConfigurator.java Sun Aug 11 23:54:52 2013
@@ -16,17 +16,15 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.myfaces.flow.cdi;
+package org.apache.myfaces.flow.impl;
 
 import java.util.Iterator;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.spi.BeanManager;
 import javax.faces.context.FacesContext;
 import javax.faces.flow.Flow;
 import org.apache.myfaces.config.FacesConfigurator;
 import org.apache.myfaces.flow.FlowImpl;
+import org.apache.myfaces.spi.FacesFlowProvider;
+import org.apache.myfaces.spi.FacesFlowProviderFactory;
 
 /**
  *
@@ -37,15 +35,14 @@ public class AnnotatedFlowConfigurator
     
     public static void configureAnnotatedFlows(FacesContext facesContext)
     {
-        BeanManager beanManager = FacesFlowCDIUtils.getBeanManagerFromJNDI();
-        if (beanManager != null)
+        FacesFlowProviderFactory factory = 
+            FacesFlowProviderFactory.getFacesFlowProviderFactory(facesContext.getExternalContext());
+        FacesFlowProvider provider = factory.getFacesFlowProvider(facesContext.getExternalContext());
+        
+        Iterator<Flow> it = provider.getAnnotatedFlows(facesContext);
+        
+        if (it != null)
         {
-            FlowBuilderFactoryBean bean = FacesFlowCDIUtils.lookup(
-                beanManager, FlowBuilderFactoryBean.class);
-
-            Instance<Flow> instance = bean.getFlowDefinitions();
-            
-            Iterator<Flow> it = instance.iterator();
             if (it.hasNext())
             {
                 FacesConfigurator.enableDefaultWindowMode(facesContext);
@@ -58,14 +55,9 @@ public class AnnotatedFlowConfigurator
                 {
                     ((FlowImpl)flow).freeze();
                 }
-                
+
                 facesContext.getApplication().getFlowHandler().addFlow(facesContext, flow);
             }
         }
-        else
-        {
-            Logger.getLogger(AnnotatedFlowConfigurator.class.getName()).log(Level.INFO,
-                "CDI BeanManager not found");
-        }
     }
 }

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/DefaultFacesFlowProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/DefaultFacesFlowProvider.java?rev=1513021&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/DefaultFacesFlowProvider.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/DefaultFacesFlowProvider.java Sun Aug 11 23:54:52 2013
@@ -0,0 +1,131 @@
+/*
+ * 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.myfaces.flow.impl;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.flow.Flow;
+import org.apache.myfaces.spi.FacesFlowProvider;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public class DefaultFacesFlowProvider extends FacesFlowProvider
+{
+    private static final String FLOW_PREFIX = "oam.flow";
+    
+    static final String FLOW_SESSION_MAP_SUBKEY_PREFIX = FLOW_PREFIX + ".SCOPE";
+    
+    /**
+     * Token separator.
+     */
+    static final char SEPARATOR_CHAR = '.';
+    
+    private final static String CURRENT_FLOW_SCOPE_MAP = "oam.flow.SCOPE_MAP";
+
+    @Override
+    public Iterator<Flow> getAnnotatedFlows(FacesContext facesContext)
+    {
+        //Without CDI there is no @FlowDefinition annotations to scan for
+        return null;
+    }
+
+    @Override
+    public void doAfterEnterFlow(FacesContext facesContext, Flow flow)
+    {
+        // Reset current flow scope map
+        facesContext.getAttributes().remove(CURRENT_FLOW_SCOPE_MAP);
+    }
+
+    @Override
+    public void doBeforeExitFlow(FacesContext facesContext, Flow flow)
+    {
+        String flowMapKey = flow.getClientWindowFlowId(
+            facesContext.getExternalContext().getClientWindow());
+        String fullToken = FLOW_SESSION_MAP_SUBKEY_PREFIX + SEPARATOR_CHAR + flowMapKey;
+
+        Map<Object, Object> map = (Map<Object, Object>) facesContext.getAttributes().get(
+            CURRENT_FLOW_SCOPE_MAP);
+        if (map != null)
+        {
+            map.clear();
+        }
+        else
+        {
+            map = (Map<Object, Object>) facesContext.getExternalContext().
+                getSessionMap().get(fullToken);
+            if (map != null)
+            {
+                map.clear();
+            }
+        }
+        // Remove the map from session
+        facesContext.getExternalContext().getSessionMap().remove(fullToken);
+        
+        // Reset current flow scope map
+        facesContext.getAttributes().remove(CURRENT_FLOW_SCOPE_MAP);
+    }
+
+    @Override
+    public Map<Object, Object> getCurrentFlowScope(FacesContext facesContext)
+    {
+        Map<Object, Object> map = (Map<Object, Object>) facesContext.getAttributes().get(
+            CURRENT_FLOW_SCOPE_MAP);
+        if (map == null)
+        {
+            Flow flow = facesContext.getApplication().getFlowHandler().getCurrentFlow(facesContext);
+            if (flow != null)
+            {
+                String flowMapKey = flow.getClientWindowFlowId(
+                    facesContext.getExternalContext().getClientWindow());
+                
+                map = new FlowScopeMap(this, flowMapKey);
+                //String fullToken = FLOW_SESSION_MAP_SUBKEY_PREFIX + SEPARATOR_CHAR + flowMapKey;
+                //map = createOrRestoreMap(facesContext, fullToken);
+                
+                facesContext.getAttributes().put(CURRENT_FLOW_SCOPE_MAP, map);
+            }
+        }
+        return map;
+    }
+    
+    /**
+     * Create a new subkey-wrapper of the session map with the given prefix.
+     * This wrapper is used to implement the maps for the flash scope.
+     * For more information see the SubKeyMap doc.
+     */
+    Map<Object, Object> createOrRestoreMap(FacesContext context, String prefix,
+        boolean create)
+    {
+        ExternalContext external = context.getExternalContext();
+        Map<String, Object> sessionMap = external.getSessionMap();
+
+        Map<Object, Object> map = (Map<Object, Object>) sessionMap.get(prefix);
+        if (map == null && create)
+        {
+            map = new ConcurrentHashMap<Object, Object>();
+            sessionMap.put(prefix, map);
+        }
+        return map;
+    }
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/DefaultFacesFlowProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/FlowScopeMap.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/FlowScopeMap.java?rev=1513021&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/FlowScopeMap.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/FlowScopeMap.java Sun Aug 11 23:54:52 2013
@@ -0,0 +1,151 @@
+/*
+ * 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.myfaces.flow.impl;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import javax.faces.context.FacesContext;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+class FlowScopeMap implements Map<Object,Object>
+{
+    private DefaultFacesFlowProvider _provider;
+    
+    private String _flowMapKey;
+    
+    private Map<Object,Object> _delegate;
+        
+    public FlowScopeMap(DefaultFacesFlowProvider provider, String flowMapKey)
+    {
+        this._provider = provider;
+        this._flowMapKey = flowMapKey;
+    }
+    
+    private Map<Object,Object> getWrapped(boolean create)
+    {
+        if (_delegate == null)
+        {
+            String fullToken = DefaultFacesFlowProvider.FLOW_SESSION_MAP_SUBKEY_PREFIX + 
+                DefaultFacesFlowProvider.SEPARATOR_CHAR + _flowMapKey;
+            FacesContext context = FacesContext.getCurrentInstance();
+            _delegate = _provider.createOrRestoreMap(context, fullToken, create);
+        }
+        return _delegate;
+    }
+
+    public int size()
+    {
+        Map<Object,Object> map = getWrapped(false);
+        if (map == null)
+        {
+            return 0;
+        }
+        return map.size();
+    }
+
+    public boolean isEmpty()
+    {
+        Map<Object,Object> map = getWrapped(false);
+        if (map == null)
+        {
+            return false;
+        }
+        return map.isEmpty();
+    }
+
+    public boolean containsKey(Object key)
+    {
+        Map<Object,Object> map = getWrapped(false);
+        if (map == null)
+        {
+            return false;
+        }
+        return map.containsKey(key);
+    }
+
+    public boolean containsValue(Object value)
+    {
+        Map<Object,Object> map = getWrapped(false);
+        if (map == null)
+        {
+            return false;
+        }
+        return map.containsValue(value);
+    }
+
+    public Object get(Object key)
+    {
+        Map<Object,Object> map = getWrapped(false);
+        if (map == null)
+        {
+            return null;
+        }
+        return map.get(key);
+    }
+
+    public Object put(Object key, Object value)
+    {
+        return getWrapped(true).put(key, value);
+    }
+
+    public Object remove(Object key)
+    {
+        Map<Object,Object> map = getWrapped(false);
+        if (map == null)
+        {
+            return null;
+        }
+        return map.remove(key);
+    }
+
+    public void putAll(Map<? extends Object, ? extends Object> m)
+    {
+        getWrapped(true).putAll(m);
+    }
+
+    public void clear()
+    {
+        Map<Object,Object> map = getWrapped(false);
+        if (map == null)
+        {
+            return;
+        }
+        map.clear();
+    }
+
+    public Set<Object> keySet()
+    {
+        return getWrapped(true).keySet();
+    }
+
+    public Collection<Object> values()
+    {
+        return getWrapped(true).values();
+    }
+
+    public Set<Entry<Object, Object>> entrySet()
+    {
+        return getWrapped(true).entrySet();
+    }
+    
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/impl/FlowScopeMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesFlowProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesFlowProvider.java?rev=1513021&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesFlowProvider.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesFlowProvider.java Sun Aug 11 23:54:52 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.myfaces.spi;
+
+import java.util.Iterator;
+import java.util.Map;
+import javax.faces.context.FacesContext;
+import javax.faces.flow.Flow;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public abstract class FacesFlowProvider
+{
+    public abstract Iterator<Flow> getAnnotatedFlows(FacesContext facesContext);
+    
+    public abstract void doAfterEnterFlow(FacesContext context, Flow flow);
+    
+    public abstract void doBeforeExitFlow(FacesContext context, Flow flow);
+    
+    public abstract Map<Object, Object> getCurrentFlowScope(FacesContext context);
+    
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesFlowProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesFlowProviderFactory.java (from r1509781, myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationMergerFactory.java)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesFlowProviderFactory.java?p2=myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesFlowProviderFactory.java&p1=myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationMergerFactory.java&r1=1509781&r2=1513021&rev=1513021&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationMergerFactory.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/FacesFlowProviderFactory.java Sun Aug 11 23:54:52 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.myfaces.spi;
 
-import org.apache.myfaces.spi.impl.DefaultFacesConfigurationMergerFactory;
 import org.apache.myfaces.spi.impl.SpiUtils;
 
 import javax.faces.FacesException;
@@ -27,23 +26,24 @@ import java.security.AccessController;
 import java.security.PrivilegedActionException;
 
 /**
- * SPI to provide a FacesConfigurationMergerFactory implementation and thus
- * a custom FacesConfigurationMerger instance.
+ * SPI to provide a FacesFlowProviderFactory implementation and thus
+ * a custom FacesFlowProvider instance.
  *
- * @author Jakob Korherr
- * @since 2.0.3
+ * @author Leonardo Uribe
+ * @since 2.2
  */
-public abstract class FacesConfigurationMergerFactory
+public abstract class FacesFlowProviderFactory
 {
 
-    protected static final String FACTORY_DEFAULT = DefaultFacesConfigurationMergerFactory.class.getName();
+    protected static final String FACTORY_DEFAULT = 
+        "org.apache.myfaces.spi.impl.DefaultFacesFlowProviderFactory";
 
-    private static final String FACTORY_KEY = FacesConfigurationMergerFactory.class.getName();
+    private static final String FACTORY_KEY = FacesFlowProviderFactory.class.getName();
 
-    public static FacesConfigurationMergerFactory getFacesConfigurationMergerFactory(ExternalContext ctx)
+    public static FacesFlowProviderFactory getFacesFlowProviderFactory(ExternalContext ctx)
     {
-        FacesConfigurationMergerFactory factory
-                = (FacesConfigurationMergerFactory) ctx.getApplicationMap().get(FACTORY_KEY);
+        FacesFlowProviderFactory factory
+                = (FacesFlowProviderFactory) ctx.getApplicationMap().get(FACTORY_KEY);
         
         if (factory != null)
         {
@@ -58,21 +58,21 @@ public abstract class FacesConfiguration
             if (System.getSecurityManager() != null)
             {
                 final ExternalContext ectx = ctx;
-                factory = (FacesConfigurationMergerFactory) AccessController.doPrivileged(
+                factory = (FacesFlowProviderFactory) AccessController.doPrivileged(
                         new java.security.PrivilegedExceptionAction<Object>()
                         {
                             public Object run() throws PrivilegedActionException
                             {
                                 return SpiUtils.build(ectx,
-                                        FacesConfigurationMergerFactory.class,
+                                        FacesFlowProviderFactory.class,
                                         FACTORY_DEFAULT);
                             }
                         });
             }
             else
             {
-                factory = (FacesConfigurationMergerFactory) SpiUtils
-                        .build(ctx, FacesConfigurationMergerFactory.class, FACTORY_DEFAULT);
+                factory = (FacesFlowProviderFactory) SpiUtils
+                        .build(ctx, FacesFlowProviderFactory.class, FACTORY_DEFAULT);
             }
         }
         catch (PrivilegedActionException pae)
@@ -83,18 +83,18 @@ public abstract class FacesConfiguration
         if (factory != null)
         {
             // cache instance on ApplicationMap
-            setFacesConfigurationMergerFactory(ctx, factory);
+            setFacesFlowProviderFactory(ctx, factory);
         }
 
         return factory;
     }
 
-    public static void setFacesConfigurationMergerFactory(ExternalContext ctx,
-                                                          FacesConfigurationMergerFactory factory)
+    public static void setFacesFlowProviderFactory(ExternalContext ctx,
+                                                          FacesFlowProviderFactory factory)
     {
         ctx.getApplicationMap().put(FACTORY_KEY, factory);
     }
 
-    public abstract FacesConfigurationMerger getFacesConfigurationMerger(ExternalContext externalContext);
+    public abstract FacesFlowProvider getFacesFlowProvider(ExternalContext externalContext);
 
 }

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProvider.java?rev=1513021&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProvider.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProvider.java Sun Aug 11 23:54:52 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.myfaces.spi;
+
+import java.util.Map;
+import javax.faces.context.FacesContext;
+
+/**
+ * 
+ * 
+ * TODO: (Optional) provide something to cleanup the session when a view
+ * is discarded.
+ * 
+ * @author Leonardo Uribe
+ */
+public abstract class ViewScopeProvider 
+{
+    public abstract void onSessionDestroyed();
+    
+    public abstract String generateViewScopeId(FacesContext facesContext);
+    
+    public abstract Map<String, Object> createViewScopeMap(FacesContext facesContext, String viewScopeId);
+    
+    public abstract Map<String, Object> restoreViewScopeMap(FacesContext facesContext, String viewScopeId);
+
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProviderFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProviderFactory.java?rev=1513021&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProviderFactory.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProviderFactory.java Sun Aug 11 23:54:52 2013
@@ -0,0 +1,97 @@
+/*
+ * 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.myfaces.spi;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import javax.faces.FacesException;
+import javax.faces.FacesWrapper;
+import javax.faces.context.ExternalContext;
+import org.apache.myfaces.spi.impl.SpiUtils;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public abstract class ViewScopeProviderFactory implements FacesWrapper<ViewScopeProviderFactory>
+{
+    protected static final String FACTORY_DEFAULT = 
+        "org.apache.myfaces.spi.impl.DefaultViewScopeProviderFactory";
+    
+    private static final String FACTORY_KEY = ViewScopeProviderFactory.class.getName();
+    
+    public static ViewScopeProviderFactory getViewScopeHandlerFactory(ExternalContext ctx)
+    {
+        ViewScopeProviderFactory instance
+                = (ViewScopeProviderFactory) ctx.getApplicationMap().get(FACTORY_KEY);
+        if (instance != null)
+        {
+            return instance;
+        }
+        ViewScopeProviderFactory lpf = null;
+        try
+        {
+
+            if (System.getSecurityManager() != null)
+            {
+                final ExternalContext ectx = ctx;
+                lpf = (ViewScopeProviderFactory)
+                        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
+                        {
+                            public Object run() throws PrivilegedActionException
+                            {
+                                return SpiUtils.build(ectx,
+                                        ViewScopeProviderFactory.class,
+                                        FACTORY_DEFAULT);
+                            }
+                        });
+            }
+            else
+            {
+                lpf = (ViewScopeProviderFactory)
+                        SpiUtils.build(ctx, ViewScopeProviderFactory.class, FACTORY_DEFAULT);
+            }
+        }
+        catch (PrivilegedActionException pae)
+        {
+            throw new FacesException(pae);
+        }
+        if (lpf != null)
+        {
+            setViewScopeHandlerFactory(ctx, lpf);
+        }
+        return lpf;
+    }
+
+    public static void setViewScopeHandlerFactory(ExternalContext ctx,
+                                                             ViewScopeProviderFactory instance)
+    {
+        ctx.getApplicationMap().put(FACTORY_KEY, instance);
+    }    
+    
+    public abstract ViewScopeProvider getViewScopeHandler(ExternalContext ctx);
+    
+    public ViewScopeProviderFactory getWrapped()
+    {
+        return null;
+    }
+    
+    public abstract void setViewScopeHandler(ExternalContext ctx, ViewScopeProvider viewScopeHandler);
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ViewScopeProviderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesFlowProviderFactory.java (from r1509781, myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesConfigurationMergerFactory.java)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesFlowProviderFactory.java?p2=myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesFlowProviderFactory.java&p1=myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesConfigurationMergerFactory.java&r1=1509781&r2=1513021&rev=1513021&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesConfigurationMergerFactory.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesFlowProviderFactory.java Sun Aug 11 23:54:52 2013
@@ -18,89 +18,39 @@
  */
 package org.apache.myfaces.spi.impl;
 
-import org.apache.myfaces.config.DefaultFacesConfigurationMerger;
-import org.apache.myfaces.shared.util.ClassUtils;
-import org.apache.myfaces.spi.FacesConfigurationMerger;
-import org.apache.myfaces.spi.FacesConfigurationMergerFactory;
-import org.apache.myfaces.spi.ServiceProviderFinderFactory;
-
-import javax.faces.FacesException;
+import org.apache.myfaces.spi.FacesFlowProvider;
+import org.apache.myfaces.spi.FacesFlowProviderFactory;
 import javax.faces.context.ExternalContext;
-import java.lang.reflect.InvocationTargetException;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.apache.myfaces.flow.impl.DefaultFacesFlowProvider;
+import org.apache.myfaces.shared.util.ClassUtils;
+import org.apache.myfaces.util.ExternalSpecifications;
 
 /**
- * @author Jakob Korherr
+ * @author Leonardo Uribe
  */
-public class DefaultFacesConfigurationMergerFactory extends FacesConfigurationMergerFactory
+public class DefaultFacesFlowProviderFactory extends FacesFlowProviderFactory
 {
 
-    public static final String FACES_CONFIGURATION_MERGER = FacesConfigurationMerger.class.getName();
+    public static final String FACES_CONFIGURATION_MERGER = FacesFlowProvider.class.getName();
     public static final String FACES_CONFIGURATION_MERGER_INSTANCE_KEY = FACES_CONFIGURATION_MERGER + ".INSTANCE";
 
     @Override
-    public FacesConfigurationMerger getFacesConfigurationMerger(ExternalContext externalContext)
+    public FacesFlowProvider getFacesFlowProvider(ExternalContext externalContext)
     {
         // check for cached instance
-        FacesConfigurationMerger returnValue = (FacesConfigurationMerger)
+        FacesFlowProvider returnValue = (FacesFlowProvider)
                 externalContext.getApplicationMap().get(FACES_CONFIGURATION_MERGER_INSTANCE_KEY);
 
         if (returnValue == null)
         {
-            final ExternalContext extContext = externalContext;
-            try
-            {
-                if (System.getSecurityManager() != null)
-                {
-                    returnValue = AccessController.doPrivileged(
-                            new java.security.PrivilegedExceptionAction<FacesConfigurationMerger>()
-                            {
-                                public FacesConfigurationMerger run() throws ClassNotFoundException,
-                                        NoClassDefFoundError,
-                                        InstantiationException,
-                                        IllegalAccessException,
-                                        InvocationTargetException,
-                                        PrivilegedActionException
-                                {
-                                    return resolveFacesConfigurationMergerFromService(extContext);
-                                }
-                            });
-                }
-                else
-                {
-                    returnValue = resolveFacesConfigurationMergerFromService(extContext);
-                }
-
-                // cache the result on the ApplicationMap
-                externalContext.getApplicationMap().put(FACES_CONFIGURATION_MERGER_INSTANCE_KEY, returnValue);
-            }
-            catch (ClassNotFoundException e)
-            {
-                // ignore
-            }
-            catch (NoClassDefFoundError e)
-            {
-                // ignore
-            }
-            catch (InstantiationException e)
+            if (ExternalSpecifications.isCDIAvailable(externalContext))
             {
-                getLogger().log(Level.SEVERE, "", e);
+                returnValue = (FacesFlowProvider) ClassUtils.newInstance(
+                    "org.apache.myfaces.flow.cdi.DefaultCDIFacesFlowProvider");
             }
-            catch (IllegalAccessException e)
+            else
             {
-                getLogger().log(Level.SEVERE, "", e);
-            }
-            catch (InvocationTargetException e)
-            {
-                getLogger().log(Level.SEVERE, "", e);
-            }
-            catch (PrivilegedActionException e)
-            {
-                throw new FacesException(e);
+                returnValue = (FacesFlowProvider) new DefaultFacesFlowProvider();
             }
         }
 
@@ -108,26 +58,4 @@ public class DefaultFacesConfigurationMe
         return returnValue;
     }
 
-    private FacesConfigurationMerger resolveFacesConfigurationMergerFromService(ExternalContext externalContext)
-            throws ClassNotFoundException,
-                   NoClassDefFoundError,
-                   InstantiationException,
-                   IllegalAccessException,
-                   InvocationTargetException,
-                   PrivilegedActionException
-    {
-        // get all fitting SPI implementations (no need to cache this since it's only called once per JSF-app)
-        List<String> classList = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext)
-                .getServiceProviderList(FACES_CONFIGURATION_MERGER);
-
-        // create the instance using decorator pattern
-        return ClassUtils.buildApplicationObject(FacesConfigurationMerger.class,
-                classList, new DefaultFacesConfigurationMerger());
-    }
-
-    private Logger getLogger()
-    {
-        return Logger.getLogger(DefaultFacesConfigurationMergerFactory.class.getName());
-    }
-
 }