You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2011/01/03 00:57:27 UTC

svn commit: r1054502 - /myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/

Author: gpetracek
Date: Sun Jan  2 23:57:26 2011
New Revision: 1054502

URL: http://svn.apache.org/viewvc?rev=1054502&view=rev
Log:
EXTCDI-49 evaluation after the rendering process

Added:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationAware.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/RenderingObserver.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java
Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultConversation.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/JsfAwareConversationFactory.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationAware.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationAware.java?rev=1054502&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationAware.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ConversationAware.java Sun Jan  2 23:57:26 2011
@@ -0,0 +1,29 @@
+/*
+ * 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.extensions.cdi.jsf.impl.scope.conversation;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.Conversation;
+
+/**
+ * @author Gerhard Petracek
+ */
+interface ConversationAware
+{
+    void setConversation(Conversation conversation);
+}

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultConversation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultConversation.java?rev=1054502&r1=1054501&r2=1054502&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultConversation.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultConversation.java Sun Jan  2 23:57:26 2011
@@ -61,6 +61,11 @@ public class DefaultConversation impleme
 
         this.closeConversationEventEnable = conversationConfig.isCloseConversationEventEnabled();
         this.restartConversationEventEnable = conversationConfig.isRestartConversationEventEnabled();
+
+        if(this.expirationEvaluator instanceof ConversationAware)
+        {
+            ((ConversationAware)this.expirationEvaluator).setConversation(this);
+        }
     }
 
     //just for a better performance to avoid frequent calls to the {@link #expirationEvaluator}

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/JsfAwareConversationFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/JsfAwareConversationFactory.java?rev=1054502&r1=1054501&r2=1054502&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/JsfAwareConversationFactory.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/JsfAwareConversationFactory.java Sun Jan  2 23:57:26 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation;
 
+import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.ConversationFactory;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.ConversationKey;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.EditableConversation;
@@ -73,7 +74,7 @@ public class JsfAwareConversationFactory
         if(ViewAccessScoped.class.isAssignableFrom(conversationKey.getScope()))
         {
             conversation = new DefaultConversation(conversationKey,
-                                                   new ViewAccessConversationExpirationEvaluator(),
+                                                   createAndRegisterViewAccessConversationEvaluator(),
                                                    configuration,
                                                    this.beanManager);
 
@@ -89,6 +90,15 @@ public class JsfAwareConversationFactory
         return processCreatedConversation(conversation, configuration.isStartConversationEventEnabled());
     }
 
+    private ViewAccessConversationExpirationEvaluator createAndRegisterViewAccessConversationEvaluator()
+    {
+        ViewAccessConversationExpirationEvaluator evaluator = new ViewAccessConversationExpirationEvaluator();
+        CodiUtils.getContextualReferenceByClass(
+                this.beanManager, ViewAccessConversationExpirationEvaluatorRegistry.class)
+                .addViewAccessConversationExpirationEvaluator(evaluator);
+        return evaluator;
+    }
+
     private EditableConversation processCreatedConversation(EditableConversation conversation,
                                                             boolean startConversationEventEnable)
     {

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/RenderingObserver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/RenderingObserver.java?rev=1054502&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/RenderingObserver.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/RenderingObserver.java Sun Jan  2 23:57:26 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.extensions.cdi.jsf.impl.scope.conversation;
+
+import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.AfterPhase;
+import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.JsfPhaseId;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.faces.event.PhaseEvent;
+
+/**
+ * @author Gerhard Petracek
+ */
+@ApplicationScoped
+public class RenderingObserver
+{
+    protected RenderingObserver()
+    {
+    }
+
+    protected void observeRenderedView(@Observes @AfterPhase(JsfPhaseId.RENDER_RESPONSE) PhaseEvent phaseEvent,
+                                       ViewAccessConversationExpirationEvaluatorRegistry registry)
+    {
+        registry.broadcastRenderedViewId(phaseEvent.getFacesContext().getViewRoot().getViewId());
+    }
+}

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java?rev=1054502&r1=1054501&r2=1054502&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluator.java Sun Jan  2 23:57:26 2011
@@ -18,6 +18,8 @@
  */
 package org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation;
 
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.Conversation;
+
 import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils.getOldViewId;
 import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils.getNewViewId;
 
@@ -26,11 +28,26 @@ import javax.faces.context.FacesContext;
 /**
  * @author Gerhard Petracek
  */
-class ViewAccessConversationExpirationEvaluator implements ConversationExpirationEvaluator
+class ViewAccessConversationExpirationEvaluator implements ConversationExpirationEvaluator, ConversationAware
 {
-    private String lastViewId; //for access scope
     private static final long serialVersionUID = 5586717766107967144L;
 
+    private String lastViewId; //for access scope
+
+    private Conversation conversation;
+
+    void observeRenderedView(String viewId)
+    {
+        if(!viewId.equals(this.lastViewId))
+        {
+            if(this.conversation != null)
+            {
+                this.conversation.close();
+            }
+            expire();
+        }
+    }
+
     public boolean isExpired()
     {
         if(this.lastViewId == null)
@@ -55,10 +72,16 @@ class ViewAccessConversationExpirationEv
     public void expire()
     {
         this.lastViewId = null;
+        this.conversation = null;
     }
 
     private String getCurrentViewId()
     {
         return FacesContext.getCurrentInstance().getViewRoot().getViewId();
     }
+
+    public void setConversation(Conversation conversation)
+    {
+        this.conversation = conversation;
+    }
 }
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java?rev=1054502&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ViewAccessConversationExpirationEvaluatorRegistry.java Sun Jan  2 23:57:26 2011
@@ -0,0 +1,59 @@
+/*
+ * 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.extensions.cdi.jsf.impl.scope.conversation;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.WindowScoped;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * @author Gerhard Petracek
+ */
+@WindowScoped
+public class ViewAccessConversationExpirationEvaluatorRegistry implements Serializable
+{
+    private static final long serialVersionUID = -1783266839383634211L;
+
+    protected ViewAccessConversationExpirationEvaluatorRegistry()
+    {
+    }
+
+    private List<ViewAccessConversationExpirationEvaluator> viewAccessConversationExpirationEvaluatorList
+            = new CopyOnWriteArrayList<ViewAccessConversationExpirationEvaluator>();
+
+    void addViewAccessConversationExpirationEvaluator(ViewAccessConversationExpirationEvaluator evaluator)
+    {
+        this.viewAccessConversationExpirationEvaluatorList.add(evaluator);
+    }
+
+    void broadcastRenderedViewId(String viewId)
+    {
+        for(ViewAccessConversationExpirationEvaluator evaluator : this.viewAccessConversationExpirationEvaluatorList)
+        {
+            evaluator.observeRenderedView(viewId);
+
+            if(evaluator.isExpired())
+            {
+                this.viewAccessConversationExpirationEvaluatorList.remove(evaluator);
+            }
+        }
+    }
+}