1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
49
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 }