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 javax.el.ValueExpression; |
22 | |
import javax.faces.context.FacesContext; |
23 | |
import javax.faces.flow.SwitchCase; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | public class SwitchCaseImpl extends SwitchCase implements Freezable |
31 | |
{ |
32 | |
private String _fromOutcome; |
33 | |
|
34 | |
private Boolean _condition; |
35 | |
private ValueExpression _conditionEL; |
36 | |
|
37 | |
private boolean _initialized; |
38 | |
|
39 | |
@Override |
40 | |
public String getFromOutcome() |
41 | |
{ |
42 | 0 | return _fromOutcome; |
43 | |
} |
44 | |
|
45 | |
@Override |
46 | |
public Boolean getCondition(FacesContext context) |
47 | |
{ |
48 | 0 | if (_conditionEL != null) |
49 | |
{ |
50 | 0 | Object value = _conditionEL.getValue(context.getELContext()); |
51 | 0 | if (value instanceof String) |
52 | |
{ |
53 | 0 | return Boolean.valueOf((String) value); |
54 | |
} |
55 | 0 | return (Boolean) value; |
56 | |
} |
57 | 0 | return _condition; |
58 | |
} |
59 | |
|
60 | |
public void freeze() |
61 | |
{ |
62 | 0 | _initialized = true; |
63 | 0 | } |
64 | |
|
65 | |
private void checkInitialized() throws IllegalStateException |
66 | |
{ |
67 | 0 | if (_initialized) |
68 | |
{ |
69 | 0 | throw new IllegalStateException("Flow is inmutable once initialized"); |
70 | |
} |
71 | 0 | } |
72 | |
|
73 | |
public void setFromOutcome(String fromOutcome) |
74 | |
{ |
75 | 0 | checkInitialized(); |
76 | 0 | this._fromOutcome = fromOutcome; |
77 | 0 | } |
78 | |
|
79 | |
public void setCondition(Boolean condition) |
80 | |
{ |
81 | 0 | checkInitialized(); |
82 | 0 | this._condition = condition; |
83 | 0 | this._conditionEL = null; |
84 | 0 | } |
85 | |
|
86 | |
public void setCondition(ValueExpression conditionEL) |
87 | |
{ |
88 | 0 | checkInitialized(); |
89 | 0 | this._conditionEL = conditionEL; |
90 | 0 | this._condition = null; |
91 | 0 | } |
92 | |
} |