1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.flow; |
20 | |
|
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
import javax.el.ExpressionFactory; |
24 | |
import javax.el.ValueExpression; |
25 | |
import javax.faces.application.NavigationCase; |
26 | |
import javax.faces.context.FacesContext; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class NavigationCaseImpl extends NavigationCase implements Freezable |
33 | |
{ |
34 | |
|
35 | |
private String _condition; |
36 | |
private String _fromAction; |
37 | |
private String _fromOutcome; |
38 | |
private String _fromViewId; |
39 | |
private String _toViewId; |
40 | |
private String _toFlowDocumentId; |
41 | |
private boolean _includeViewParams; |
42 | |
private boolean _redirect; |
43 | |
private Map<String, List<String>> _parameters; |
44 | |
private ValueExpression _conditionExpression; |
45 | |
private ValueExpression _toViewIdExpression; |
46 | |
|
47 | |
private boolean _initialized; |
48 | |
|
49 | |
public NavigationCaseImpl() |
50 | |
{ |
51 | 0 | super(null, null, null, null, null, null, false, false); |
52 | 0 | } |
53 | |
|
54 | |
public NavigationCaseImpl(String fromViewId, String fromAction, String fromOutcome, String condition, |
55 | |
String toViewId, |
56 | |
Map<String, List<String>> parameters, boolean redirect, boolean includeViewParams) |
57 | |
{ |
58 | 0 | super(fromViewId, fromAction, fromOutcome, condition, toViewId, parameters, redirect, includeViewParams); |
59 | 0 | _condition = condition; |
60 | 0 | _fromViewId = fromViewId; |
61 | 0 | _fromAction = fromAction; |
62 | 0 | _fromOutcome = fromOutcome; |
63 | 0 | _toViewId = toViewId; |
64 | 0 | _toFlowDocumentId = null; |
65 | 0 | _redirect = redirect; |
66 | 0 | _includeViewParams = includeViewParams; |
67 | 0 | _parameters = parameters; |
68 | 0 | } |
69 | |
|
70 | |
public NavigationCaseImpl(String fromViewId, String fromAction, String fromOutcome, String condition, |
71 | |
String toViewId, |
72 | |
String toFlowDocumentId, Map<String, List<String>> parameters, boolean redirect, |
73 | |
boolean includeViewParams) |
74 | |
{ |
75 | 0 | super(fromViewId, fromAction, fromOutcome, condition, toViewId, toFlowDocumentId, parameters, redirect, |
76 | |
includeViewParams); |
77 | 0 | _condition = condition; |
78 | 0 | _fromViewId = fromViewId; |
79 | 0 | _fromAction = fromAction; |
80 | 0 | _fromOutcome = fromOutcome; |
81 | 0 | _toViewId = toViewId; |
82 | 0 | _toFlowDocumentId = toFlowDocumentId; |
83 | 0 | _redirect = redirect; |
84 | 0 | _includeViewParams = includeViewParams; |
85 | 0 | _parameters = parameters; |
86 | |
|
87 | 0 | } |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public String getCondition() |
93 | |
{ |
94 | 0 | return _condition; |
95 | |
} |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public void setCondition(String condition) |
101 | |
{ |
102 | 0 | checkInitialized(); |
103 | 0 | this._condition = condition; |
104 | 0 | } |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public String getFromAction() |
110 | |
{ |
111 | 0 | return _fromAction; |
112 | |
} |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public void setFromAction(String fromAction) |
118 | |
{ |
119 | 0 | checkInitialized(); |
120 | 0 | this._fromAction = fromAction; |
121 | 0 | } |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
public String getFromOutcome() |
127 | |
{ |
128 | 0 | return _fromOutcome; |
129 | |
} |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
public void setFromOutcome(String fromOutcome) |
135 | |
{ |
136 | 0 | checkInitialized(); |
137 | 0 | this._fromOutcome = fromOutcome; |
138 | 0 | } |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
public String getFromViewId() |
144 | |
{ |
145 | 0 | return _fromViewId; |
146 | |
} |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public void setFromViewId(String fromViewId) |
152 | |
{ |
153 | 0 | checkInitialized(); |
154 | 0 | this._fromViewId = fromViewId; |
155 | 0 | } |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
public String getToViewId() |
161 | |
{ |
162 | 0 | return _toViewId; |
163 | |
} |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public void setToViewId(String toViewId) |
169 | |
{ |
170 | 0 | checkInitialized(); |
171 | 0 | this._toViewId = toViewId; |
172 | 0 | } |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
public String getToFlowDocumentId() |
178 | |
{ |
179 | 0 | return _toFlowDocumentId; |
180 | |
} |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
public void setToFlowDocumentId(String toFlowDocumentId) |
186 | |
{ |
187 | 0 | checkInitialized(); |
188 | 0 | this._toFlowDocumentId = toFlowDocumentId; |
189 | 0 | } |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
public boolean isIncludeViewParams() |
195 | |
{ |
196 | 0 | return _includeViewParams; |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
public void setIncludeViewParams(boolean includeViewParams) |
203 | |
{ |
204 | 0 | checkInitialized(); |
205 | 0 | this._includeViewParams = includeViewParams; |
206 | 0 | } |
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
public boolean isRedirect() |
212 | |
{ |
213 | 0 | return _redirect; |
214 | |
} |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
public void setRedirect(boolean redirect) |
220 | |
{ |
221 | 0 | checkInitialized(); |
222 | 0 | this._redirect = redirect; |
223 | 0 | } |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
public Map<String, List<String>> getParameters() |
229 | |
{ |
230 | 0 | return _parameters; |
231 | |
} |
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
public void setParameters(Map<String, List<String>> parameters) |
237 | |
{ |
238 | 0 | checkInitialized(); |
239 | 0 | this._parameters = parameters; |
240 | 0 | } |
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
public ValueExpression getConditionExpression() |
246 | |
{ |
247 | 0 | return _conditionExpression; |
248 | |
} |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
public void setConditionExpression(ValueExpression conditionExpression) |
254 | |
{ |
255 | 0 | checkInitialized(); |
256 | 0 | this._conditionExpression = conditionExpression; |
257 | 0 | } |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
public ValueExpression getToViewIdExpression() |
263 | |
{ |
264 | 0 | return _toViewIdExpression; |
265 | |
} |
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
public void setToViewIdExpression(ValueExpression toViewIdExpression) |
271 | |
{ |
272 | 0 | checkInitialized(); |
273 | 0 | this._toViewIdExpression = toViewIdExpression; |
274 | 0 | } |
275 | |
|
276 | |
public Boolean getCondition(FacesContext context) |
277 | |
{ |
278 | 0 | if (_condition == null) |
279 | |
{ |
280 | 0 | return null; |
281 | |
} |
282 | |
|
283 | 0 | ValueExpression expression = _getConditionExpression(context); |
284 | |
|
285 | 0 | return Boolean.TRUE.equals(expression.getValue(context.getELContext())); |
286 | |
} |
287 | |
|
288 | |
private ValueExpression _getConditionExpression(FacesContext context) |
289 | |
{ |
290 | 0 | assert _condition != null; |
291 | |
|
292 | 0 | if (_conditionExpression == null) |
293 | |
{ |
294 | 0 | ExpressionFactory factory = context.getApplication().getExpressionFactory(); |
295 | 0 | _conditionExpression = factory.createValueExpression(context.getELContext(), _condition, Boolean.class); |
296 | |
} |
297 | |
|
298 | 0 | return _conditionExpression; |
299 | |
} |
300 | |
|
301 | |
public String getToViewId(FacesContext context) |
302 | |
{ |
303 | 0 | if (_toViewId == null) |
304 | |
{ |
305 | 0 | return null; |
306 | |
} |
307 | |
|
308 | 0 | ValueExpression expression = _getToViewIdExpression(context); |
309 | |
|
310 | 0 | return (String) ((expression.isLiteralText()) |
311 | |
? expression.getExpressionString() : expression.getValue(context.getELContext())); |
312 | |
} |
313 | |
|
314 | |
private ValueExpression _getToViewIdExpression(FacesContext context) |
315 | |
{ |
316 | 0 | assert _toViewId != null; |
317 | |
|
318 | 0 | if (_toViewIdExpression == null) |
319 | |
{ |
320 | 0 | ExpressionFactory factory = context.getApplication().getExpressionFactory(); |
321 | 0 | _toViewIdExpression = factory.createValueExpression(context.getELContext(), _toViewId, String.class); |
322 | |
} |
323 | |
|
324 | 0 | return _toViewIdExpression; |
325 | |
} |
326 | |
|
327 | |
public boolean hasCondition() |
328 | |
{ |
329 | 0 | return _condition != null && _condition.length() > 0; |
330 | |
} |
331 | |
|
332 | |
@Override |
333 | |
public int hashCode() |
334 | |
{ |
335 | 0 | int hash = 5; |
336 | 0 | hash = 47 * hash + (this._condition != null ? this._condition.hashCode() : 0); |
337 | 0 | hash = 47 * hash + (this._fromAction != null ? this._fromAction.hashCode() : 0); |
338 | 0 | hash = 47 * hash + (this._fromOutcome != null ? this._fromOutcome.hashCode() : 0); |
339 | 0 | hash = 47 * hash + (this._fromViewId != null ? this._fromViewId.hashCode() : 0); |
340 | 0 | hash = 47 * hash + (this._toViewId != null ? this._toViewId.hashCode() : 0); |
341 | 0 | hash = 47 * hash + (this._toFlowDocumentId != null ? this._toFlowDocumentId.hashCode() : 0); |
342 | 0 | hash = 47 * hash + (this._includeViewParams ? 1 : 0); |
343 | 0 | hash = 47 * hash + (this._redirect ? 1 : 0); |
344 | 0 | hash = 47 * hash + (this._parameters != null ? this._parameters.hashCode() : 0); |
345 | 0 | hash = 47 * hash + (this._conditionExpression != null ? this._conditionExpression.hashCode() : 0); |
346 | 0 | hash = 47 * hash + (this._toViewIdExpression != null ? this._toViewIdExpression.hashCode() : 0); |
347 | 0 | return hash; |
348 | |
} |
349 | |
|
350 | |
@Override |
351 | |
public boolean equals(Object obj) |
352 | |
{ |
353 | 0 | if (obj == null) |
354 | |
{ |
355 | 0 | return false; |
356 | |
} |
357 | 0 | if (getClass() != obj.getClass()) |
358 | |
{ |
359 | 0 | return false; |
360 | |
} |
361 | 0 | final NavigationCaseImpl other = (NavigationCaseImpl) obj; |
362 | 0 | if ((this._condition == null) ? (other._condition != null) : !this._condition.equals(other._condition)) |
363 | |
{ |
364 | 0 | return false; |
365 | |
} |
366 | 0 | if ((this._fromAction == null) ? (other._fromAction != null) : !this._fromAction.equals(other._fromAction)) |
367 | |
{ |
368 | 0 | return false; |
369 | |
} |
370 | 0 | if ((this._fromOutcome == null) ? (other._fromOutcome != null) : |
371 | |
!this._fromOutcome.equals(other._fromOutcome)) |
372 | |
{ |
373 | 0 | return false; |
374 | |
} |
375 | 0 | if ((this._fromViewId == null) ? (other._fromViewId != null) : !this._fromViewId.equals(other._fromViewId)) |
376 | |
{ |
377 | 0 | return false; |
378 | |
} |
379 | 0 | if ((this._toViewId == null) ? (other._toViewId != null) : !this._toViewId.equals(other._toViewId)) |
380 | |
{ |
381 | 0 | return false; |
382 | |
} |
383 | 0 | if ((this._toFlowDocumentId == null) ? (other._toFlowDocumentId != null) : |
384 | |
!this._toFlowDocumentId.equals(other._toFlowDocumentId)) |
385 | |
{ |
386 | 0 | return false; |
387 | |
} |
388 | 0 | if (this._includeViewParams != other._includeViewParams) |
389 | |
{ |
390 | 0 | return false; |
391 | |
} |
392 | 0 | if (this._redirect != other._redirect) |
393 | |
{ |
394 | 0 | return false; |
395 | |
} |
396 | 0 | if (this._parameters != other._parameters && (this._parameters == null || |
397 | |
!this._parameters.equals(other._parameters))) |
398 | |
{ |
399 | 0 | return false; |
400 | |
} |
401 | 0 | if (this._conditionExpression != other._conditionExpression && (this._conditionExpression == null || |
402 | |
!this._conditionExpression.equals(other._conditionExpression))) |
403 | |
{ |
404 | 0 | return false; |
405 | |
} |
406 | 0 | if (this._toViewIdExpression != other._toViewIdExpression && (this._toViewIdExpression == null || |
407 | |
!this._toViewIdExpression.equals(other._toViewIdExpression))) |
408 | |
{ |
409 | 0 | return false; |
410 | |
} |
411 | 0 | return true; |
412 | |
} |
413 | |
|
414 | |
public void freeze() |
415 | |
{ |
416 | 0 | _initialized = true; |
417 | 0 | } |
418 | |
|
419 | |
private void checkInitialized() throws IllegalStateException |
420 | |
{ |
421 | 0 | if (_initialized) |
422 | |
{ |
423 | 0 | throw new IllegalStateException("Flow is inmutable once initialized"); |
424 | |
} |
425 | 0 | } |
426 | |
} |