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 2007/11/06 22:47:18 UTC

svn commit: r592565 - in /myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController: _ViewControllerUtils.java jsf/ViewControllerPhaseListener.java jsf/ViewControllerVariableResolver.java spring/SpringViewControllerScope.java

Author: skitching
Date: Tue Nov  6 13:47:18 2007
New Revision: 592565

URL: http://svn.apache.org/viewvc?rev=592565&view=rev
Log:
Remove jsf-specific class _ViewControllerUtils from the non-jsf package.
The code has been moved into the two subclasses that need it for the moment.

Removed:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/_ViewControllerUtils.java
Modified:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerPhaseListener.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerVariableResolver.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/spring/SpringViewControllerScope.java

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerPhaseListener.java?rev=592565&r1=592564&r2=592565&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerPhaseListener.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerPhaseListener.java Tue Nov  6 13:47:18 2007
@@ -20,22 +20,34 @@
 
 package org.apache.myfaces.orchestra.viewController.jsf;
 
-import org.apache.myfaces.orchestra.viewController.ViewControllerManager;
-import org.apache.myfaces.orchestra.viewController._ViewControllerUtils;
+import java.util.Set;
+import java.util.TreeSet;
 
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
-import java.util.Set;
-import java.util.TreeSet;
+
+import org.apache.myfaces.orchestra.viewController.ViewControllerManager;
 
 /**
  * Causes lifecycle methods to be invoked on backing beans that are associated with
  * the current view.
  * <p>
+ * Method executeInitView is invoked on the configured ViewControllerManager when ...
+ * <p>
+ * 
+ * <p>
  * See the javadoc for class ViewControllerManager on how to configure this.
+ * <p>
+ * Note that at the moment this does not supprt a ViewController bean for subviews
+ * (ie f:subView tags), which the Shale ViewController framework does provide.
+ * <p>
+ * It also might not invoke all the callbacks if exceptions are thrown by actionlisteners,
+ * etc (which again Shale guarantees). This is particularly important for an "endView"
+ * callback, where resources allocated on initView (such as database connections) might
+ * be released.
  */
 public class ViewControllerPhaseListener implements PhaseListener
 {
@@ -63,6 +75,8 @@
 			}
 		}
 
+		// Try to init the view in every phase, just so we are sure to never miss it.
+		// This skips the actual call if init has already happened.
 		executeInitView(event.getFacesContext());
 		
 		if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId()))
@@ -114,7 +128,7 @@
 	 */
 	protected void assertConversationState(FacesContext facesContext)
 	{
-		ViewControllerManager manager = _ViewControllerUtils.getViewControllerManager(facesContext);
+		ViewControllerManager manager = ViewControllerVariableResolver.getViewControllerManager(facesContext);
 		if (manager == null)
 		{
 			return;
@@ -134,7 +148,7 @@
 	 */
 	protected void preRenderResponse(FacesContext facesContext)
 	{
-		ViewControllerManager manager = _ViewControllerUtils.getViewControllerManager(facesContext);
+		ViewControllerManager manager = ViewControllerVariableResolver.getViewControllerManager(facesContext);
 		if (manager == null)
 		{
 			return;
@@ -162,7 +176,7 @@
 	 */
 	protected void postRestoreView(FacesContext facesContext)
 	{
-		ViewControllerManager manager = _ViewControllerUtils.getViewControllerManager(facesContext);
+		ViewControllerManager manager = ViewControllerVariableResolver.getViewControllerManager(facesContext);
 		if (manager == null)
 		{
 			return;
@@ -202,7 +216,7 @@
 	 */
 	protected void preInvokeApplication(FacesContext facesContext)
 	{
-		ViewControllerManager manager = _ViewControllerUtils.getViewControllerManager(facesContext);
+		ViewControllerManager manager = ViewControllerVariableResolver.getViewControllerManager(facesContext);
 		if (manager == null)
 		{
 			return;

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerVariableResolver.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerVariableResolver.java?rev=592565&r1=592564&r2=592565&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerVariableResolver.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/jsf/ViewControllerVariableResolver.java Tue Nov  6 13:47:18 2007
@@ -18,13 +18,13 @@
  */
 package org.apache.myfaces.orchestra.viewController.jsf;
 
-import org.apache.myfaces.orchestra.viewController.ViewControllerManager;
-import org.apache.myfaces.orchestra.viewController._ViewControllerUtils;
-
 import javax.faces.context.FacesContext;
 import javax.faces.el.EvaluationException;
 import javax.faces.el.VariableResolver;
 
+import org.apache.myfaces.orchestra.viewController.DefaultViewControllerManager;
+import org.apache.myfaces.orchestra.viewController.ViewControllerManager;
+
 /**
  * Provides a way to access the viewController through the JSF expression language (EL)
  * using the special variable name <code>oxViewController</code>.
@@ -32,6 +32,7 @@
 public class ViewControllerVariableResolver extends VariableResolver
 {
 	private final static String VIEW_CONTROLLER_VARIABLE = "oxViewController";
+	private final static ViewControllerManager DEFAULT_VCM = new DefaultViewControllerManager();
 
 	private final VariableResolver original;
 
@@ -44,10 +45,21 @@
 	{
 		if (VIEW_CONTROLLER_VARIABLE.equals(variableName))
 		{
-			ViewControllerManager manager = _ViewControllerUtils.getViewControllerManager(facesContext);
+			ViewControllerManager manager = getViewControllerManager(facesContext);
 			return manager.getViewController(facesContext.getViewRoot().getViewId());
 		}
 
 		return original.resolveVariable(facesContext, variableName);
+	}
+
+	static ViewControllerManager getViewControllerManager(FacesContext context)
+	{
+		ViewControllerManager manager = (ViewControllerManager) context.getApplication().getVariableResolver().resolveVariable(context, ViewControllerManager.VIEW_CONTROLLER_MANAGER_NAME);
+		if (manager != null)
+		{
+			return manager;
+		}
+
+		return DEFAULT_VCM;
 	}
 }

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/spring/SpringViewControllerScope.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/spring/SpringViewControllerScope.java?rev=592565&r1=592564&r2=592565&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/spring/SpringViewControllerScope.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/viewController/spring/SpringViewControllerScope.java Tue Nov  6 13:47:18 2007
@@ -19,21 +19,25 @@
 
 package org.apache.myfaces.orchestra.viewController.spring;
 
+import javax.faces.context.FacesContext;
+
 import org.apache.myfaces.orchestra.conversation.Conversation;
 import org.apache.myfaces.orchestra.conversation.ConversationContext;
 import org.apache.myfaces.orchestra.conversation.spring.AbstractSpringOrchestraScope;
 import org.apache.myfaces.orchestra.lib.OrchestraException;
+import org.apache.myfaces.orchestra.viewController.DefaultViewControllerManager;
 import org.apache.myfaces.orchestra.viewController.ViewControllerManager;
-import org.apache.myfaces.orchestra.viewController._ViewControllerUtils;
-
-import javax.faces.context.FacesContext;
 
 /**
- * provides a dummy scope which will place a bean configured for into the same conversation as the
- * viewController.
+ * This hooks into the Spring2.x scope-handling mechanism to provide a dummy scope which
+ * will place a bean configured for into the same conversation as the viewController.
+ * <p>
+ * TODO: why is this useful?
  */
 public class SpringViewControllerScope extends AbstractSpringOrchestraScope
 {
+	private final static ViewControllerManager DEFAULT_VCM = new DefaultViewControllerManager();
+
 	public SpringViewControllerScope()
 	{
 	}
@@ -49,11 +53,21 @@
         // if this scope uses the same conversationFactory
     }
 
+    /**
+     * Find the conversation-controller bean for the current view, then return the conversation that
+     * is configured for that controller bean.
+     * <p>
+     * The parameter is completely ignored; the conversation-name returned is that associated with the
+     * controller bean, not the specified bean at all.
+     */
     protected String getConversationNameForBean(String beanName)
 	{
+    	// TODO: this is JSF-specific. Remove it.
 		FacesContext facesContext = FacesContext.getCurrentInstance();
 
-		ViewControllerManager viewControllerManager = _ViewControllerUtils.getViewControllerManager(facesContext);
+		// TODO: avoid using the _ViewControllerUtils class here. That is JSF-specific which this class is
+		// not supposed to be.
+		ViewControllerManager viewControllerManager = getViewControllerManager(facesContext);
 		String viewControllerName = viewControllerManager.getViewControllerName(facesContext.getViewRoot().getViewId());
 		if (viewControllerName == null)
 		{
@@ -67,5 +81,19 @@
 		}
 
 		return conversationName;
+	}
+
+    private ViewControllerManager getViewControllerManager(FacesContext context)
+	{
+    	// todo: use Spring here, not JSF resolver. That does mean that ViewControllers defined in the 
+    	// managedBean file rather than the spring-config will no longer be found. But it does properly
+    	// isolate this class from JSF.
+		ViewControllerManager manager = (ViewControllerManager) context.getApplication().getVariableResolver().resolveVariable(context, ViewControllerManager.VIEW_CONTROLLER_MANAGER_NAME);
+		if (manager != null)
+		{
+			return manager;
+		}
+
+		return DEFAULT_VCM;
 	}
 }