View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.orchestra.viewController.spring;
21  
22  import org.apache.myfaces.orchestra.conversation.Conversation;
23  import org.apache.myfaces.orchestra.conversation.ConversationContext;
24  import org.apache.myfaces.orchestra.conversation.spring.AbstractSpringOrchestraScope;
25  import org.apache.myfaces.orchestra.lib.OrchestraException;
26  import org.apache.myfaces.orchestra.viewController.ViewControllerManager;
27  import org.apache.myfaces.orchestra.viewController._ViewControllerUtils;
28  
29  import javax.faces.context.FacesContext;
30  
31  /***
32   * provides a dummy scope which will place a bean configured for into the same conversation as the
33   * viewController.
34   */
35  public class SpringViewControllerScope extends AbstractSpringOrchestraScope
36  {
37  	public SpringViewControllerScope()
38  	{
39  	}
40  
41  	public Conversation createConversation(ConversationContext context, String conversationName)
42  	{
43  		throw new IllegalStateException("the viewController scope is not supposed to start a conversation on its own. conversation to start: " + conversationName);
44  	}
45  
46      protected void assertSameScope(String beanName, Conversation conversation)
47      {
48          // since we do not start any conversation, there is no need to check
49          // if this scope uses the same conversationFactory
50      }
51  
52      protected String getConversationNameForBean(String beanName)
53  	{
54  		FacesContext facesContext = FacesContext.getCurrentInstance();
55  
56  		ViewControllerManager viewControllerManager = _ViewControllerUtils.getViewControllerManager(facesContext);
57  		String viewControllerName = viewControllerManager.getViewControllerName(facesContext.getViewRoot().getViewId());
58  		if (viewControllerName == null)
59  		{
60  			throw new OrchestraException("no view controller name found for view " + facesContext.getViewRoot().getViewId());
61  		}
62  
63  		String conversationName = super.getConversationNameForBean(viewControllerName);
64  		if (conversationName == null)
65  		{
66  			throw new OrchestraException("no view controller definition found for view " + facesContext.getViewRoot().getViewId());
67  		}
68  
69  		return conversationName;
70  	}
71  }