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.conversation.jsf;
21
22 import java.util.Iterator;
23
24 import javax.faces.component.UICommand;
25 import javax.faces.component.UIComponent;
26 import javax.faces.context.FacesContext;
27 import javax.faces.el.MethodBinding;
28
29 import org.apache.myfaces.orchestra.conversation.Conversation;
30 import org.apache.myfaces.orchestra.conversation.ConversationManager;
31 import org.apache.myfaces.orchestra.conversation.jsf.components.AbstractConversationComponent;
32 import org.apache.myfaces.orchestra.conversation.jsf.components.UIEndConversation;
33 import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
34
35
36
37
38
39 public class _JsfConversationUtils
40 {
41 private _JsfConversationUtils()
42 {
43 }
44
45
46
47
48 public static UICommand findParentCommand(UIComponent base)
49 {
50 UIComponent parent = base;
51 do
52 {
53 parent = parent.getParent();
54 if (parent instanceof UICommand)
55 {
56 return (UICommand) parent;
57 }
58 }
59 while (parent != null);
60
61 return null;
62 }
63
64
65
66
67 public static AbstractConversationComponent findEndConversationComponent(
68 UIComponent component, String conversationName)
69 {
70 Iterator iterComponents = component.getFacetsAndChildren();
71 while (iterComponents.hasNext())
72 {
73 Object child = iterComponents.next();
74 AbstractConversationComponent conversation;
75
76 if (child instanceof UIEndConversation)
77 {
78 conversation = (AbstractConversationComponent) child;
79 if (conversation.getName().equals(conversationName))
80 {
81 return conversation;
82 }
83 }
84 else if (child instanceof UIComponent)
85 {
86 conversation = findEndConversationComponent((UIComponent) child, conversationName);
87 if (conversation != null)
88 {
89 return conversation;
90 }
91 }
92 }
93
94 return null;
95 }
96
97
98
99
100 public static void endAndRestartConversation(FacesContext context,
101 String conversationName, Boolean restart, MethodBinding restartAction)
102 {
103 ConversationManager conversationManager = ConversationManager.getInstance();
104 Conversation conversation = conversationManager.getConversation(conversationName);
105 if (conversation != null)
106 {
107 conversation.invalidate();
108 }
109
110 if (restart != null && restart.booleanValue())
111 {
112 FrameworkAdapter.getCurrentInstance().getBean(conversationName);
113
114 if (restartAction != null)
115 {
116 restartAction.invoke(context, null);
117 }
118 }
119 }
120 }