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 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 return _fromOutcome;
43 }
44
45 @Override
46 public Boolean getCondition(FacesContext context)
47 {
48 if (_conditionEL != null)
49 {
50 Object value = _conditionEL.getValue(context.getELContext());
51 if (value instanceof String)
52 {
53 return Boolean.valueOf((String) value);
54 }
55 return (Boolean) value;
56 }
57 return _condition;
58 }
59
60 public void freeze()
61 {
62 _initialized = true;
63 }
64
65 private void checkInitialized() throws IllegalStateException
66 {
67 if (_initialized)
68 {
69 throw new IllegalStateException("Flow is inmutable once initialized");
70 }
71 }
72
73 public void setFromOutcome(String fromOutcome)
74 {
75 checkInitialized();
76 this._fromOutcome = fromOutcome;
77 }
78
79 public void setCondition(Boolean condition)
80 {
81 checkInitialized();
82 this._condition = condition;
83 this._conditionEL = null;
84 }
85
86 public void setCondition(ValueExpression conditionEL)
87 {
88 checkInitialized();
89 this._conditionEL = conditionEL;
90 this._condition = null;
91 }
92 }