You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2007/08/29 15:55:08 UTC

svn commit: r570815 - in /myfaces/orchestra/trunk/core/src/main: java/org/apache/myfaces/orchestra/conversation/ java/org/apache/myfaces/orchestra/conversation/jsf/ java/org/apache/myfaces/orchestra/conversation/spring/ resources/META-INF/

Author: imario
Date: Wed Aug 29 06:55:07 2007
New Revision: 570815

URL: http://svn.apache.org/viewvc?rev=570815&view=rev
Log:
added ability to avoid invalidating conversations in flash scope for given view-ids (Thanks to Simon Kitching for the idea) or using the FlashScopeManager API

Added:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManager.java   (contents, props changed)
      - copied, changed from r570796, myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashManager.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManagerConfiguration.java   (with props)
    myfaces/orchestra/trunk/core/src/main/resources/META-INF/spring-orchestra-init.xml
      - copied, changed from r570796, myfaces/orchestra/trunk/core15/src/main/resources/META-INF/spring-orchestra-init.xml
Modified:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/ConversationPhaseListener.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringFlashScope.java

Copied: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManager.java (from r570796, myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashManager.java)
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManager.java?p2=myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManager.java&p1=myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashManager.java&r1=570796&r2=570815&rev=570815&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashManager.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManager.java Wed Aug 29 06:55:07 2007
@@ -20,37 +20,71 @@
 
 import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
 
+import java.util.HashSet;
 import java.util.Set;
-import java.util.TreeSet;
 
 /**
  * manager to deal with page scoped beans
  */
-public class FlashManager
+public final class FlashScopeManager
 {
 	private final static String FLASH_MANAGER_KEY = "org.apache.myfaces.FlashManager";
 
-	private Set accessedConversations = new TreeSet();
+	private FlashScopeManagerConfiguration flashScopeManagerConfiguration;
 
-	public static FlashManager getInstance()
+	private Set accessedConversations = new HashSet();
+	private boolean ignoreRequest;
+
+	public static FlashScopeManager getInstance()
+	{
+		FlashScopeManager manager = (FlashScopeManager) FrameworkAdapter.getInstance().getBean(FlashScopeManager.class.getName());
+		if (manager == null)
+		{
+			throw new IllegalArgumentException("no FlashScopeManager found. Propably you forgot to add <import resource=\"classpath*:/META-INF/spring-orchestra-init.xml\" /> to your spring configuration.");
+		}
+
+		return manager;
+	}
+
+	public FlashScopeManagerConfiguration getFlashScopeManagerConfiguration()
+	{
+		return flashScopeManagerConfiguration;
+	}
+
+	public void setFlashScopeManagerConfiguration(FlashScopeManagerConfiguration flashScopeManagerConfiguration)
 	{
-		FlashManager flashManager = (FlashManager) FrameworkAdapter.getInstance().getRequestAttribute(FLASH_MANAGER_KEY);
-		if (flashManager == null)
+		this.flashScopeManagerConfiguration = flashScopeManagerConfiguration;
+	}
+
+	/**
+	 * add a conversation to the list of accessed conversations. <br />
+	 * Notice: this method is final for performance reasons.
+	 */
+	public final void addConversationAccess(String conversationName)
+	{
+		if (!ignoreRequest && !accessedConversations.contains(conversationName))
 		{
-			flashManager = new FlashManager();
-			FrameworkAdapter.getInstance().setRequestAttribute(FLASH_MANAGER_KEY, flashManager);
+			accessedConversations.add(conversationName);
 		}
+	}
 
-		return flashManager;
+	public boolean isIgnoreRequest()
+	{
+		return ignoreRequest;
 	}
 
-	public void addConversationAccess(String beanName)
+	public void setIgnoreRequest()
 	{
-		accessedConversations.add(beanName);
+		this.ignoreRequest = true;
 	}
 
 	public boolean isConversationAccessed(String name)
 	{
+		if (ignoreRequest)
+		{
+			throw new IllegalStateException();
+		}
+
 		return accessedConversations.contains(name);
 	}
 }

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManagerConfiguration.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManagerConfiguration.java?rev=570815&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManagerConfiguration.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManagerConfiguration.java Wed Aug 29 06:55:07 2007
@@ -0,0 +1,36 @@
+/*
+ * 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.orchestra.conversation;
+
+import java.util.Set;
+
+public class FlashScopeManagerConfiguration
+{
+	private Set ignoreViewIds;
+
+	public Set getIgnoreViewIds()
+	{
+		return ignoreViewIds;
+	}
+
+	public void setIgnoreViewIds(Set ignoreViewIds)
+	{
+		this.ignoreViewIds = ignoreViewIds;
+	}
+}

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManagerConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManagerConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManagerConfiguration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/ConversationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/ConversationPhaseListener.java?rev=570815&r1=570814&r2=570815&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/ConversationPhaseListener.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/ConversationPhaseListener.java Wed Aug 29 06:55:07 2007
@@ -19,16 +19,17 @@
 
 package org.apache.myfaces.orchestra.conversation.jsf;
 
-import org.apache.myfaces.orchestra.conversation.ConversationManager;
 import org.apache.myfaces.orchestra.conversation.Conversation;
-import org.apache.myfaces.orchestra.conversation.FlashManager;
+import org.apache.myfaces.orchestra.conversation.ConversationManager;
+import org.apache.myfaces.orchestra.conversation.FlashScopeManager;
 import org.apache.myfaces.orchestra.conversation.spring.ConversationPolicy;
 
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
-import java.util.Map;
 import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * Ensure that Orchestra is initialised for the current user, and handle Flash conversations.
@@ -47,16 +48,29 @@
 	{
 		if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId()))
 		{
-			invalidateFlashConversations();
+			invalidateFlashConversations(event.getFacesContext().getViewRoot().getViewId());
 		}
 	}
 
 	/**
 	 * invalidates any conversation with policy {@link org.apache.myfaces.orchestra.conversation.spring.ConversationPolicy#FLASH}
 	 * not accessed during a http request
+	 * @param viewId
 	 */
-	protected void invalidateFlashConversations()
+	protected void invalidateFlashConversations(String viewId)
 	{
+		FlashScopeManager flashManager = FlashScopeManager.getInstance();
+		if (flashManager.isIgnoreRequest())
+		{
+			return;
+		}
+
+		Set ignoredViewIds = flashManager.getFlashScopeManagerConfiguration().getIgnoreViewIds();
+		if (ignoredViewIds.contains(viewId))
+		{
+			return;
+		}
+
 		ConversationManager conversationManager = ConversationManager.getInstance();
 		if (conversationManager == null)
 		{
@@ -69,7 +83,6 @@
 			return;
 		}
 
-		FlashManager flashManager = FlashManager.getInstance();
 		while (iterConversations.hasNext())
 		{
 			Conversation conversation = (Conversation) iterConversations.next();

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringFlashScope.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringFlashScope.java?rev=570815&r1=570814&r2=570815&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringFlashScope.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringFlashScope.java Wed Aug 29 06:55:07 2007
@@ -20,7 +20,7 @@
 package org.apache.myfaces.orchestra.conversation.spring;
 
 import org.apache.myfaces.orchestra.conversation.Conversation;
-import org.apache.myfaces.orchestra.conversation.FlashManager;
+import org.apache.myfaces.orchestra.conversation.FlashScopeManager;
 
 /**
  * provides a flash scope, that is, a bean will be discarded as soon as it is no longer referenced
@@ -39,6 +39,6 @@
 
 	protected void notifyAccessConversation(Conversation conversation)
 	{
-		FlashManager.getInstance().addConversationAccess(conversation.getName());
+		FlashScopeManager.getInstance().addConversationAccess(conversation.getName());
 	}
 }

Copied: myfaces/orchestra/trunk/core/src/main/resources/META-INF/spring-orchestra-init.xml (from r570796, myfaces/orchestra/trunk/core15/src/main/resources/META-INF/spring-orchestra-init.xml)
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/resources/META-INF/spring-orchestra-init.xml?p2=myfaces/orchestra/trunk/core/src/main/resources/META-INF/spring-orchestra-init.xml&p1=myfaces/orchestra/trunk/core15/src/main/resources/META-INF/spring-orchestra-init.xml&r1=570796&r2=570815&rev=570815&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core15/src/main/resources/META-INF/spring-orchestra-init.xml (original)
+++ myfaces/orchestra/trunk/core/src/main/resources/META-INF/spring-orchestra-init.xml Wed Aug 29 06:55:07 2007
@@ -26,30 +26,13 @@
 			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
 
 	<bean
-		name="org.apache.myfaces.orchestra.annotation.AnnotationInfoManager"
-		class="org.apache.myfaces.orchestra.annotation.AnnotationInfoManager"
-		scope="singleton" />
-
-	<bean
-		class="org.apache.myfaces.orchestra.annotation.spring.AnnotationsInfoInitializer"
-		scope="singleton">
+		name="org.apache.myfaces.orchestra.conversation.FlashScopeManager"
+		class="org.apache.myfaces.orchestra.conversation.FlashScopeManager"
+		scope="request">
 
 		<property
-			name="annotationInfoManager"
-			ref="org.apache.myfaces.orchestra.annotation.AnnotationInfoManager"/>
-
-	</bean>
-
-	<bean
-		name="org$apache$myfaces$orchestra$viewController$ViewControllerManager"
-		class="org.apache.myfaces.orchestra.viewController.AnnotationsViewControllerManager"
-		init-method="initManager"
-		scope="singleton">
-		
-		<property
-			name="annotationInfoManager"
-			ref="org.apache.myfaces.orchestra.annotation.AnnotationInfoManager"/>
-
+			name="flashScopeManagerConfiguration"
+			ref="org.apache.myfaces.orchestra.conversation.FlashScopeManagerConfiguration" />
 	</bean>
 
 </beans>