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/02/24 21:37:38 UTC

svn commit: r511341 - in /myfaces/fusion/trunk/core/src: main/java/org/apache/myfaces/fusion/conversation/jsf/ main/java/org/apache/myfaces/fusion/conversation/spring/ main/java/org/apache/myfaces/fusion/jsf/ main/java/org/apache/myfaces/fusion/lib/ ma...

Author: imario
Date: Sat Feb 24 12:37:36 2007
New Revision: 511341

URL: http://svn.apache.org/viewvc?view=rev&rev=511341
Log:
added viewController stuff

This is much like what shale has, but not that powerful.
It simply forwards the afterRestoreView and preRenderResponse events to a viewController

Later this viewController should be responsible for starting conversations in cases where the automatic did not work, also it should help to issue a navigation if a conversation has timed out in the mid of a wizzard pageflow.

Added:
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/jsf/ConversationPhaseListener.java   (contents, props changed)
      - copied, changed from r511278, myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/jsf/FusionPhaseListener.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerManager.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerNameMapper.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/InterfaceViewControllerExecutor.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ReflectiveViewControllerExecutor.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewController.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerExecutor.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerManager.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerNameMapper.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerPhaseListener.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerUtils.java
    myfaces/fusion/trunk/core/src/test/java/org/
    myfaces/fusion/trunk/core/src/test/java/org/apache/
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBean.java
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBeanInterface.java
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestDefaultViewControllerNameMapper.java
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestInterfaceViewControllerExecutor.java
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestReflectiveViewControllerExecutor.java
Removed:
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/jsf/FusionPhaseListener.java
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/lib/FakeMap.java
Modified:
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/spring/SpringConversationScope.java
    myfaces/fusion/trunk/core/src/main/resources/META-INF/faces-config.xml

Copied: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/jsf/ConversationPhaseListener.java (from r511278, myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/jsf/FusionPhaseListener.java)
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/jsf/ConversationPhaseListener.java?view=diff&rev=511341&p1=myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/jsf/FusionPhaseListener.java&r1=511278&p2=myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/jsf/ConversationPhaseListener.java&r2=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/jsf/FusionPhaseListener.java (original)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/jsf/ConversationPhaseListener.java Sat Feb 24 12:37:36 2007
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.myfaces.fusion.jsf;
+package org.apache.myfaces.fusion.conversation.jsf;
 
 import org.apache.myfaces.fusion.conversation.ConversationManager;
 
@@ -26,9 +26,9 @@
 import javax.faces.event.PhaseListener;
 import java.util.Map;
 
-public class FusionPhaseListener implements PhaseListener
+public class ConversationPhaseListener implements PhaseListener
 {
-	private final static String SYSTEM_INITIALIZED = FusionPhaseListener.class.getName() + ".INITIALIZED";
+	private final static String SYSTEM_INITIALIZED = ConversationPhaseListener.class.getName() + ".INITIALIZED";
 
 	private final static ThreadLocal AUTOMATIC_CONVERSATION_CREATION = new ThreadLocal()
 	{

Propchange: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/jsf/ConversationPhaseListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

Modified: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/spring/SpringConversationScope.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/spring/SpringConversationScope.java?view=diff&rev=511341&r1=511340&r2=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/spring/SpringConversationScope.java (original)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/conversation/spring/SpringConversationScope.java Sat Feb 24 12:37:36 2007
@@ -25,7 +25,7 @@
 import org.apache.myfaces.fusion.conversation.ConversationEndListener;
 import org.apache.myfaces.fusion.conversation.ConversationManager;
 import org.apache.myfaces.fusion.conversation.CurrentConversationAdvice;
-import org.apache.myfaces.fusion.jsf.FusionPhaseListener;
+import org.apache.myfaces.fusion.conversation.jsf.ConversationPhaseListener;
 import org.springframework.aop.framework.ProxyFactory;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanFactory;
@@ -81,7 +81,7 @@
 		// check if we have a conversation
 		if (!manager.hasConversation(name))
 		{
-			if (!FusionPhaseListener.isAutomaticConversationCreation())
+			if (!ConversationPhaseListener.isAutomaticConversationCreation())
 			{
 				return null;
 			}

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerManager.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerManager.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerManager.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerManager.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,56 @@
+/*
+ * 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.fusion.viewController;
+
+import javax.faces.context.FacesContext;
+
+public class DefaultViewControllerManager implements ViewControllerManager
+{
+	ViewControllerNameMapper viewControllerNameMapper = new DefaultViewControllerNameMapper();
+	ViewControllerExecutor viewControllerExecutor = new ReflectiveViewControllerExecutor();
+
+	public DefaultViewControllerManager()
+	{
+	}
+
+	public ViewControllerNameMapper getViewControllerNameMapper()
+	{
+		return viewControllerNameMapper;
+	}
+
+	public ViewControllerExecutor getViewControllerExecutor()
+	{
+		return viewControllerExecutor;
+	}
+
+	public Object getViewController(FacesContext facesContext, String viewId)
+	{
+		ViewControllerNameMapper nameMapper = getViewControllerNameMapper();
+
+		String beanName = nameMapper.mapViewId(viewId);
+		if (beanName == null)
+		{
+			return null;
+		}
+
+		return facesContext.getApplication().getVariableResolver().resolveVariable(facesContext, beanName);
+	}
+}
\ No newline at end of file

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerNameMapper.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerNameMapper.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/DefaultViewControllerNameMapper.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,95 @@
+/*
+ * 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.fusion.viewController;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+
+public class DefaultViewControllerNameMapper implements ViewControllerNameMapper
+{
+	private static Set RESERVED_WORDS = new HashSet(Arrays.asList(
+		new String[]
+			{
+				"applicationScope",
+				"cookie",
+				"facesContext",
+				"header",
+				"headerValues",
+				"initParam",
+				"param",
+				"paramValues",
+				"requestScope",
+				"sessionScope",
+				"view"
+			}
+	));
+
+
+	public String mapViewId(String viewId)
+	{
+		if (viewId == null)
+		{
+			return null;
+		}
+
+		boolean nextUpper=false;
+
+		StringBuffer sb = new StringBuffer(viewId);
+		for (int i = 0; i < sb.length(); i++)
+		{
+			char c = sb.charAt(i);
+			if (c == '/')
+			{
+				if (i > 0)
+				{
+					nextUpper=true;
+				}
+				sb.deleteCharAt(i);
+				i--;
+				continue;
+			}
+			else if (c == '.')
+			{
+				sb.delete(i, sb.length());
+				break;
+			}
+			else if (nextUpper)
+			{
+				sb.setCharAt(i, Character.toUpperCase(c));
+				nextUpper=false;
+			}
+		}
+
+		String beanName = sb.toString();
+		if (RESERVED_WORDS.contains(beanName))
+		{
+			return "_" + beanName;
+		}
+
+		if (beanName.length() > 0 && Character.isDigit(beanName.charAt(0)))
+		{
+			return "_" + beanName;
+		}
+
+		return beanName;
+	}
+}

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/InterfaceViewControllerExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/InterfaceViewControllerExecutor.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/InterfaceViewControllerExecutor.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/InterfaceViewControllerExecutor.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2007, Your Corporation. All Rights Reserved.
+ */
+
+/*
+ * 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.fusion.viewController;
+
+public class InterfaceViewControllerExecutor extends ViewControllerExecutor
+{
+	public void invokeInitView(Object bean)
+	{
+		if (bean instanceof ViewController)
+		{
+			((ViewController) bean).initView();
+		}
+	}
+
+	public void invokePreRenderView(Object bean)
+	{
+		if (bean instanceof ViewController)
+		{
+			((ViewController) bean).preRenderView();
+		}
+	}
+}
\ No newline at end of file

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ReflectiveViewControllerExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ReflectiveViewControllerExecutor.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ReflectiveViewControllerExecutor.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ReflectiveViewControllerExecutor.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,60 @@
+/*
+ * 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.fusion.viewController;
+
+import javax.faces.FacesException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class ReflectiveViewControllerExecutor extends ViewControllerExecutor
+{
+	public void invokeInitView(Object bean)
+	{
+		invokeOnViewController(bean, "initView");
+	}
+
+	public void invokePreRenderView(Object bean)
+	{
+		invokeOnViewController(bean, "preRenderView");
+	}
+
+	protected void invokeOnViewController(Object bean, String methodName)
+	{
+		try
+		{
+			Method method = bean.getClass().getMethod(methodName, null); // NON-NLS
+			method.invoke(bean, null);
+		}
+		catch (NoSuchMethodException e)
+		{
+			// no problem
+			// just ignore it
+		}
+		catch (IllegalAccessException e)
+		{
+			throw new FacesException(e);
+		}
+		catch (InvocationTargetException e)
+		{
+			throw new FacesException(e);
+		}
+	}
+}

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewController.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewController.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewController.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewController.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,28 @@
+/*
+ * 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.fusion.viewController;
+
+public interface ViewController
+{
+	public void initView();
+
+	public void preRenderView();
+}

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerExecutor.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerExecutor.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerExecutor.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.fusion.viewController;
+
+public abstract class ViewControllerExecutor
+{
+	public void invokeInitView(Object bean)
+	{
+	}
+
+	public void invokePreRenderView(Object bean)
+	{
+	}
+}

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerManager.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerManager.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerManager.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerManager.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.fusion.viewController;
+
+import javax.faces.context.FacesContext;
+
+public interface ViewControllerManager
+{
+	public final static String VIEW_CONTROLLER_MANAGER_NAME="fusion_ViewControllerManager";
+
+	public ViewControllerNameMapper getViewControllerNameMapper();
+	public ViewControllerExecutor getViewControllerExecutor();
+	public Object getViewController(FacesContext facesContext, String viewId);
+}

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerNameMapper.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerNameMapper.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerNameMapper.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,26 @@
+/*
+ * 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.fusion.viewController;
+
+public interface ViewControllerNameMapper
+{
+	public String mapViewId(String viewId);
+}

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerPhaseListener.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerPhaseListener.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerPhaseListener.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,103 @@
+/*
+ * 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.fusion.viewController;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.faces.component.UIViewRoot;
+
+public class ViewControllerPhaseListener implements PhaseListener
+{
+	public void beforePhase(PhaseEvent event)
+	{
+		if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId()))
+		{
+			preRenderResponse(event.getFacesContext());
+		}
+	}
+
+	public void afterPhase(PhaseEvent event)
+	{
+		if (PhaseId.RESTORE_VIEW.equals(event.getPhaseId()))
+		{
+			postRestoreView(event.getFacesContext());
+		}
+	}
+
+	public PhaseId getPhaseId()
+	{
+		return PhaseId.ANY_PHASE;
+	}
+
+	protected String getViewId(FacesContext facesContext)
+	{
+		UIViewRoot viewRoot = facesContext.getViewRoot();
+		if (viewRoot == null)
+		{
+			return null;
+		}
+		return viewRoot.getViewId();
+	}
+
+	protected void preRenderResponse(FacesContext facesContext)
+	{
+		ViewControllerManager manager = ViewControllerUtils.getViewControllerManager(facesContext);
+		if (manager == null)
+		{
+			return;
+		}
+
+		String viewId = getViewId(facesContext);
+		if (viewId == null)
+		{
+			return;
+		}
+
+		Object viewController = manager.getViewController(facesContext, viewId);
+		if (viewController != null)
+		{
+			manager.getViewControllerExecutor().invokePreRenderView(viewController);
+		}
+	}
+
+	protected void postRestoreView(FacesContext facesContext)
+	{
+		ViewControllerManager manager = ViewControllerUtils.getViewControllerManager(facesContext);
+		if (manager == null)
+		{
+			return;
+		}
+
+		String viewId = getViewId(facesContext);
+		if (viewId == null)
+		{
+			return;
+		}
+
+		Object viewController = manager.getViewController(facesContext, viewId);
+		if (viewController != null)
+		{
+			manager.getViewControllerExecutor().invokeInitView(viewController);
+		}
+	}
+}

Added: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerUtils.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerUtils.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerUtils.java (added)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/viewController/ViewControllerUtils.java Sat Feb 24 12:37:36 2007
@@ -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.fusion.viewController;
+
+import javax.faces.context.FacesContext;
+
+public final class ViewControllerUtils
+{
+	private final static ViewControllerManager DEFAULT_VCM = new DefaultViewControllerManager();
+
+	private ViewControllerUtils()
+	{
+	}
+
+	public 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/fusion/trunk/core/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/resources/META-INF/faces-config.xml?view=diff&rev=511341&r1=511340&r2=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/fusion/trunk/core/src/main/resources/META-INF/faces-config.xml Sat Feb 24 12:37:36 2007
@@ -40,7 +40,8 @@
 	</component>
 
 	<lifecycle>
-		<phase-listener>org.apache.myfaces.fusion.jsf.FusionPhaseListener</phase-listener>
+		<phase-listener>org.apache.myfaces.fusion.conversation.jsf.ConversationPhaseListener</phase-listener>
+		<phase-listener>org.apache.myfaces.fusion.viewController.ViewControllerPhaseListener</phase-listener>
 	</lifecycle>
 
 </faces-config>

Added: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBean.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBean.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBean.java (added)
+++ myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBean.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.fusion.viewController;
+
+public class TargetBean
+{
+	private String called;
+
+	public void initView()
+	{
+		called="initView";
+	}
+
+	public void preRenderView()
+	{
+		called="preRenderView";
+	}
+
+	public String getCalled()
+	{
+		return called;
+	}
+}

Added: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBeanInterface.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBeanInterface.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBeanInterface.java (added)
+++ myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TargetBeanInterface.java Sat Feb 24 12:37:36 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.fusion.viewController;
+
+public class TargetBeanInterface implements ViewController
+{
+	private String called;
+
+	public void initView()
+	{
+		called = "initView";
+	}
+
+	public void preRenderView()
+	{
+		called = "preRenderView";
+	}
+
+	public String getCalled()
+	{
+		return called;
+	}
+}
\ No newline at end of file

Added: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestDefaultViewControllerNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestDefaultViewControllerNameMapper.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestDefaultViewControllerNameMapper.java (added)
+++ myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestDefaultViewControllerNameMapper.java Sat Feb 24 12:37:36 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.fusion.viewController;
+
+import junit.framework.TestCase;
+
+public class TestDefaultViewControllerNameMapper extends TestCase
+{
+	public void testMapViewId()
+	{
+		DefaultViewControllerNameMapper mapper = new DefaultViewControllerNameMapper();
+
+		assertEquals("mainform", mapper.mapViewId("mainform.jsp"));
+		assertEquals("userDataPassword", mapper.mapViewId("userData/password.jsp"));
+		assertEquals("_requestScope", mapper.mapViewId("requestScope.jsp"));
+		assertEquals("_123set", mapper.mapViewId("123set.jsp"));
+	}
+}

Added: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestInterfaceViewControllerExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestInterfaceViewControllerExecutor.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestInterfaceViewControllerExecutor.java (added)
+++ myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestInterfaceViewControllerExecutor.java Sat Feb 24 12:37:36 2007
@@ -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.fusion.viewController;
+
+import junit.framework.TestCase;
+
+public class TestInterfaceViewControllerExecutor extends TestCase
+{
+
+	public void testInvokes()
+	{
+		TargetBeanInterface targetBean = new TargetBeanInterface();
+
+		InterfaceViewControllerExecutor executor = new InterfaceViewControllerExecutor();
+
+		executor.invokeInitView(targetBean);
+		assertEquals("initView", targetBean.getCalled());
+
+		executor.invokePreRenderView(targetBean);
+		assertEquals("preRenderView", targetBean.getCalled());
+	}
+}
\ No newline at end of file

Added: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestReflectiveViewControllerExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestReflectiveViewControllerExecutor.java?view=auto&rev=511341
==============================================================================
--- myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestReflectiveViewControllerExecutor.java (added)
+++ myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/viewController/TestReflectiveViewControllerExecutor.java Sat Feb 24 12:37:36 2007
@@ -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.fusion.viewController;
+
+import junit.framework.TestCase;
+
+public class TestReflectiveViewControllerExecutor extends TestCase
+{
+
+	public void testInvokes()
+	{
+		TargetBean targetBean = new TargetBean();
+
+		ReflectiveViewControllerExecutor executor = new ReflectiveViewControllerExecutor();
+
+		executor.invokeInitView(targetBean);
+		assertEquals("initView", targetBean.getCalled());
+
+		executor.invokePreRenderView(targetBean);
+		assertEquals("preRenderView", targetBean.getCalled());
+	}
+}
\ No newline at end of file