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