1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.conversation;
20
21 import org.apache.myfaces.shared_tomahawk.util.StringUtils;
22
23 import javax.faces.component.UICommand;
24 import javax.faces.context.FacesContext;
25 import javax.faces.el.MethodBinding;
26 import javax.faces.el.ValueBinding;
27 import java.io.IOException;
28 import java.util.Arrays;
29 import java.util.Collection;
30
31
32
33
34
35
36
37
38
39
40 public class UIEndConversation extends AbstractConversationComponent
41 {
42 public static final String COMPONENT_TYPE = "org.apache.myfaces.EndConversation";
43
44 private String onOutcome;
45 private String errorOutcome;
46 private Boolean restart;
47 private MethodBinding restartAction;
48
49 private boolean inited = false;
50
51
52
53
54
55
56
57
58
59
60
61 public void encodeBegin(FacesContext context) throws IOException
62 {
63 super.encodeBegin(context);
64
65 UICommand command = ConversationUtils.findParentCommand(this);
66 if (command != null)
67 {
68 if (!inited)
69 {
70
71
72
73
74
75 MethodBinding original = command.getAction();
76 command.setAction(new EndConversationMethodBindingFacade(
77 getName(),
78 getOnOutcomes(),
79 original,
80 getErrorOutcome(),
81 getRestart(),
82 getRestartAction()));
83 inited = true;
84 }
85 }
86 else
87 {
88 ConversationUtils.endAndRestartConversation(context,
89 getName(),
90 getRestart(),
91 getRestartAction());
92 }
93 }
94
95 private Collection getOnOutcomes()
96 {
97 String onOutcome = getOnOutcome();
98 if (onOutcome == null || onOutcome.trim().length() < 1)
99 {
100 return null;
101 }
102
103 return Arrays.asList(StringUtils.trim(StringUtils.splitShortString(onOutcome, ',')));
104 }
105
106 public void restoreState(FacesContext context, Object state)
107 {
108 Object[] states = (Object[]) state;
109 super.restoreState(context, states[0]);
110 inited = ((Boolean) states[1]).booleanValue();
111 onOutcome = (String) states[2];
112 errorOutcome = (String) states[3];
113 restart = (Boolean) states[4];
114 restartAction = (MethodBinding) restoreAttachedState(context, states[5]);
115 }
116
117 public Object saveState(FacesContext context)
118 {
119 return new Object[]
120 {
121 super.saveState(context),
122 inited ? Boolean.TRUE : Boolean.FALSE,
123 onOutcome,
124 errorOutcome,
125 restart,
126 saveAttachedState(context, restartAction)
127 };
128 }
129
130
131
132
133
134
135
136
137
138 public String getOnOutcome()
139 {
140 if (onOutcome != null)
141 {
142 return onOutcome;
143 }
144 ValueBinding vb = getValueBinding("onOutcome");
145 if (vb == null)
146 {
147 return null;
148 }
149 return (String) vb.getValue(getFacesContext());
150 }
151
152 public void setOnOutcome(String onOutcome)
153 {
154 this.onOutcome = onOutcome;
155 }
156
157
158
159
160
161
162
163 public String getErrorOutcome()
164 {
165 if (errorOutcome != null)
166 {
167 return errorOutcome;
168 }
169 ValueBinding vb = getValueBinding("errorOutcome");
170 if (vb == null)
171 {
172 return null;
173 }
174 return (String) vb.getValue(getFacesContext());
175 }
176
177 public void setErrorOutcome(String errorOutcome)
178 {
179 this.errorOutcome = errorOutcome;
180 }
181
182
183
184
185
186
187
188 public Boolean getRestart()
189 {
190 if (restart != null)
191 {
192 return restart;
193 }
194 ValueBinding vb = getValueBinding("restart");
195 if (vb == null)
196 {
197 return null;
198 }
199 return (Boolean) vb.getValue(getFacesContext());
200 }
201
202 public void setRestart(Boolean restart)
203 {
204 this.restart = restart;
205 }
206
207
208
209
210
211
212
213
214
215
216 public MethodBinding getRestartAction()
217 {
218 return restartAction;
219 }
220
221 public void setRestartAction(MethodBinding restartAction)
222 {
223 this.restartAction = restartAction;
224 }
225 }