You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/01/29 11:07:08 UTC

svn commit: r616232 - 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: skitching
Date: Tue Jan 29 02:07:06 2008
New Revision: 616232

URL: http://svn.apache.org/viewvc?rev=616232&view=rev
Log:
Rename flash scope to access scope

Added:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManager.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManagerConfiguration.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationAccessLifetimeAspect.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/AccessScopePhaseListener.java
      - copied, changed from r615916, myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/FlashScopePhaseListener.java
Removed:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationFlashLifetimeAspect.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManager.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/FlashScopeManagerConfiguration.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/FlashScopePhaseListener.java
Modified:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.java
    myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManager.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManager.java?rev=616232&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManager.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManager.java Tue Jan 29 02:07:06 2008
@@ -0,0 +1,126 @@
+/*
+ * 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 org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Manager to deal with page scoped beans.
+ * <p>
+ * Instances of this type are expected to be request-scoped, ie a new instance is used for
+ * each request. The AccessedScopeManagerConfiguration object that it references can be
+ * of application scope.
+ * 
+ * @since 1.1
+ */
+public final class AccessScopeManager
+{
+	private AccessScopeManagerConfiguration accessScopeManagerConfiguration;
+
+	private Set accessedConversations = new HashSet();
+	private boolean ignoreRequest;
+
+	public static AccessScopeManager getInstance()
+	{
+		// Get the instance by looking up a variable whose name is this class name, using the normal
+		// managed bean lookup process. When an IOC framework like Spring is being used to extend
+		// the standard JSF managed bean declaration facilities, then the bean may be retrieved
+		// from there.
+		//
+		// Using a lookup of a managed bean allows the user to set configuration properties on the
+		// manager class and its properties.
+		AccessScopeManager manager = (AccessScopeManager) FrameworkAdapter.getCurrentInstance().getBean(AccessScopeManager.class.getName());
+		if (manager == null)
+		{
+			// backwards compatibility hack
+			FlashScopeManager fm = (FlashScopeManager) FrameworkAdapter.getCurrentInstance().getBean(FlashScopeManager.class.getName());
+			if (fm != null)
+			{
+				manager = fm.getAccessScopeManager();
+			}
+			else
+			{
+				// TODO: Make this error message less spring-specific. Spring is not the only IOC container
+				// that Orchestra can be used with.
+				throw new IllegalArgumentException("no AccessScopeManager found. Propably you forgot to add <import resource=\"classpath*:/META-INF/spring-orchestra-init.xml\" /> to your spring configuration.");
+			}
+		}
+
+		return manager;
+	}
+
+	public AccessScopeManagerConfiguration getAccessedScopeManagerConfiguration()
+	{
+		return accessScopeManagerConfiguration;
+	}
+
+	public void setAccessScopeManagerConfiguration(AccessScopeManagerConfiguration accessScopeManagerConfiguration)
+	{
+		this.accessScopeManagerConfiguration = accessScopeManagerConfiguration;
+	}
+
+	/**
+	 * Add a conversation to the list of accessed conversations.
+	 * <p>
+	 * Notice: this method is final for performance reasons.
+	 * <p>
+	 * This method is expected to be called via AOP proxies wrapped around each conversation-scoped
+	 * bean; any invocation of a method on such a bean causes the conversation associated with that
+	 * bean to be added to the accessed list here.
+	 */
+	public final void addConversationAccess(String conversationName)
+	{
+		// Don't bother tracking accessed conversations if we will never use the data.
+		// Otherwise, add this conversation name to the list of accessed conversations.
+		if (!ignoreRequest && !accessedConversations.contains(conversationName))
+		{
+			accessedConversations.add(conversationName);
+		}
+	}
+
+	public boolean isIgnoreRequest()
+	{
+		return ignoreRequest;
+	}
+
+	/**
+	 * Suppress accessed scope for the current request, ie do not terminate conversations that are
+	 * not accessed by this request.
+	 * <p>
+	 * This can come in useful occasionally, particularly when handling AJAX requests which
+	 * only access some of the beans associated with the current view.
+	 */
+	public void setIgnoreRequest()
+	{
+		this.ignoreRequest = true;
+	}
+
+	public boolean isConversationAccessed(String name)
+	{
+		if (ignoreRequest)
+		{
+			throw new IllegalStateException();
+		}
+
+		return accessedConversations.contains(name);
+	}
+}

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManagerConfiguration.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManagerConfiguration.java?rev=616232&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManagerConfiguration.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/AccessScopeManagerConfiguration.java Tue Jan 29 02:07:06 2008
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+/**
+ * Provides configuration information to a AccessScopeManager instance.
+ * <p>
+ * While an AccessScopeManager object is expected to be request-scoped, an instance
+ * of this type is usually application-scoped (aka singleton scoped).
+ * 
+ * @since 1.1
+ */
+public class AccessScopeManagerConfiguration
+{
+	private Set ignoreViewIds;
+
+	public Set getIgnoreViewIds()
+	{
+		return ignoreViewIds;
+	}
+
+	/**
+	 * Do not terminate any "unaccessed conversations" after handling a request to
+	 * any of the specified views.
+	 * 
+	 * Special "ignored views" are useful when dealing with things like nested
+	 * frames within a page that periodically refresh themselves while the "main"
+	 * part of the page remains unsubmitted.
+	 */
+	public void setIgnoreViewIds(Set ignoreViewIds)
+	{
+		this.ignoreViewIds = ignoreViewIds;
+	}
+}

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationAccessLifetimeAspect.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationAccessLifetimeAspect.java?rev=616232&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationAccessLifetimeAspect.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationAccessLifetimeAspect.java Tue Jan 29 02:07:06 2008
@@ -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.orchestra.conversation;
+
+/**
+ * Connect the conversation to the FlashScopeManager
+ * 
+ * @since 1.1
+ */
+public class ConversationAccessLifetimeAspect extends ConversationAspect
+{
+	public ConversationAccessLifetimeAspect(Conversation conversation)
+	{
+		super(conversation);
+	}
+
+	public void markAsAccessed()
+	{
+		AccessScopeManager.getInstance().addConversationAccess(getConversation().getName());
+	}
+
+	public boolean isAccessed()
+	{
+		return AccessScopeManager.getInstance().isConversationAccessed(getConversation().getName());
+	}
+}

Copied: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/AccessScopePhaseListener.java (from r615916, myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/FlashScopePhaseListener.java)
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/AccessScopePhaseListener.java?p2=myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/AccessScopePhaseListener.java&p1=myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/FlashScopePhaseListener.java&r1=615916&r2=616232&rev=616232&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/FlashScopePhaseListener.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/AccessScopePhaseListener.java Tue Jan 29 02:07:06 2008
@@ -19,24 +19,27 @@
 
 package org.apache.myfaces.orchestra.conversation.jsf;
 
-import org.apache.myfaces.orchestra.conversation.Conversation;
-import org.apache.myfaces.orchestra.conversation.ConversationFlashLifetimeAspect;
-import org.apache.myfaces.orchestra.conversation.ConversationManager;
-import org.apache.myfaces.orchestra.conversation.FlashScopeManager;
+import java.util.Iterator;
+import java.util.Set;
 
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
-import java.util.Iterator;
-import java.util.Set;
+
+import org.apache.myfaces.orchestra.conversation.AccessScopeManager;
+import org.apache.myfaces.orchestra.conversation.Conversation;
+import org.apache.myfaces.orchestra.conversation.ConversationAccessLifetimeAspect;
+import org.apache.myfaces.orchestra.conversation.ConversationManager;
 
 /**
  * Handle Flash conversations.
  * <p>
  * At the end of request processing, delete any flash-scope conversations for which no
  * bean in that scope has been accessed during the request.
+ * 
+ * @since 1.1
  */
-public class FlashScopePhaseListener implements PhaseListener
+public class AccessScopePhaseListener implements PhaseListener
 {
 	private static final long serialVersionUID = 1L;
 
@@ -44,7 +47,7 @@
 	{
 		if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId()))
 		{
-			invalidateFlashConversations(event.getFacesContext().getViewRoot().getViewId());
+			invalidateAccessScopedConversations(event.getFacesContext().getViewRoot().getViewId());
 		}
 	}
 
@@ -56,17 +59,17 @@
 	 * Invalidates any conversation with aspect {@link ConversationFlashLifetimeAspect}
 	 * which has not been accessed during a http request
 	 */
-	protected void invalidateFlashConversations(String viewId)
+	protected void invalidateAccessScopedConversations(String viewId)
 	{
-		FlashScopeManager flashManager = FlashScopeManager.getInstance();
-		if (flashManager.isIgnoreRequest())
+		AccessScopeManager accessedManager = AccessScopeManager.getInstance();
+		if (accessedManager.isIgnoreRequest())
 		{
 			return;
 		}
 
-		if (flashManager.getFlashScopeManagerConfiguration() != null)
+		if (accessedManager.getAccessedScopeManagerConfiguration() != null)
 		{
-			Set ignoredViewIds = flashManager.getFlashScopeManagerConfiguration().getIgnoreViewIds();
+			Set ignoredViewIds = accessedManager.getAccessedScopeManagerConfiguration().getIgnoreViewIds();
 			if (ignoredViewIds != null && ignoredViewIds.contains(viewId))
 			{
 				// The flash configuration has explicitly stated that no conversations should be
@@ -93,9 +96,9 @@
 			// This conversation has "flash" scope if it has an attached Aspect
 			// of type ConversationFlashLifetimeAspect. All other conversations
 			// are not flash-scoped and should be ignored here.
-			ConversationFlashLifetimeAspect aspect =
-				(ConversationFlashLifetimeAspect)
-					conversation.getAspect(ConversationFlashLifetimeAspect.class);
+			ConversationAccessLifetimeAspect aspect =
+				(ConversationAccessLifetimeAspect)
+					conversation.getAspect(ConversationAccessLifetimeAspect.class);
 
 			if (aspect != null && !aspect.isAccessed())
 			{

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.java?rev=616232&r1=616231&r2=616232&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.java Tue Jan 29 02:07:06 2008
@@ -20,9 +20,9 @@
 package org.apache.myfaces.orchestra.conversation.spring;
 
 import org.apache.myfaces.orchestra.conversation.Conversation;
+import org.apache.myfaces.orchestra.conversation.ConversationAccessLifetimeAspect;
 import org.apache.myfaces.orchestra.conversation.ConversationAspect;
 import org.apache.myfaces.orchestra.conversation.ConversationContext;
-import org.apache.myfaces.orchestra.conversation.ConversationFlashLifetimeAspect;
 import org.apache.myfaces.orchestra.conversation.ConversationTimeoutableAspect;
 
 /**
@@ -77,7 +77,10 @@
  */
 public class SpringConversationScope extends AbstractSpringOrchestraScope
 {
+	/** @deprecated Use LIFETIME_ACCESS instead. */
 	public static final String LIFETIME_FLASH = "flash";
+
+	public static final String LIFETIME_ACCESS = "access";
 	public static final String LIFETIME_MANUAL = "manual";
 
 	private Integer timeout;
@@ -109,7 +112,7 @@
 	}
 
 	/**
-	 * Must be one of "flash" or "manual".
+	 * Must be one of "manual", "access" or "flash".
 	 * <p>
 	 * Defaults to "manual".
 	 */
@@ -119,7 +122,11 @@
 		// rather than when the first bean in this scope is created.
 		if (LIFETIME_FLASH.equals(lifetime))
 		{
-			this.lifetime = LIFETIME_FLASH;
+			this.lifetime = LIFETIME_ACCESS;
+		}
+		else if (LIFETIME_ACCESS.equals(lifetime))
+		{
+			this.lifetime = LIFETIME_ACCESS;
 		}
 		else if (LIFETIME_MANUAL.equals(lifetime))
 		{
@@ -162,9 +169,9 @@
 		}
 
 		// conversation lifetime
-		if (LIFETIME_FLASH == lifetime)
+		if (LIFETIME_ACCESS == lifetime)
 		{
-			ConversationAspect aspect = new ConversationFlashLifetimeAspect(conversation);
+			ConversationAspect aspect = new ConversationAccessLifetimeAspect(conversation);
 			conversation.addAspect(aspect);
 		}
 	}
@@ -178,7 +185,7 @@
 	{
 		super.notifyAccessConversation(conversation);
 
-		ConversationFlashLifetimeAspect aspect = (ConversationFlashLifetimeAspect) conversation.getAspect(ConversationFlashLifetimeAspect.class);
+		ConversationAccessLifetimeAspect aspect = (ConversationAccessLifetimeAspect) conversation.getAspect(ConversationAccessLifetimeAspect.class);
 		if (aspect != null)
 		{
 			aspect.markAsAccessed();

Modified: myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml?rev=616232&r1=616231&r2=616232&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml Tue Jan 29 02:07:06 2008
@@ -40,7 +40,7 @@
 
 	<lifecycle>
 		<phase-listener>org.apache.myfaces.orchestra.lib.jsf.OrchestraInitializationPhaseListener</phase-listener>
-		<phase-listener>org.apache.myfaces.orchestra.conversation.jsf.FlashScopePhaseListener</phase-listener>
+		<phase-listener>org.apache.myfaces.orchestra.conversation.jsf.AccessScopePhaseListener</phase-listener>
 		<phase-listener>org.apache.myfaces.orchestra.viewController.jsf.ViewControllerPhaseListener</phase-listener>
 	</lifecycle>