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.ArrayList; |
22 | |
import java.util.Collections; |
23 | |
import java.util.List; |
24 | |
import javax.el.ValueExpression; |
25 | |
import javax.faces.context.FacesContext; |
26 | |
import javax.faces.flow.SwitchCase; |
27 | |
import javax.faces.flow.SwitchNode; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class SwitchNodeImpl extends SwitchNode implements Freezable |
35 | |
{ |
36 | |
private String _defaultOutcome; |
37 | |
private ValueExpression _defaultOutcomeEL; |
38 | |
private String _id; |
39 | |
|
40 | |
private List<SwitchCase> _cases; |
41 | |
private List<SwitchCase> _unmodifiableCases; |
42 | |
|
43 | |
private boolean _initialized; |
44 | |
|
45 | |
public SwitchNodeImpl(String switchNodeId) |
46 | 0 | { |
47 | 0 | this._id = switchNodeId; |
48 | 0 | _cases = new ArrayList<SwitchCase>(); |
49 | 0 | _unmodifiableCases = Collections.unmodifiableList(_cases); |
50 | 0 | } |
51 | |
|
52 | |
@Override |
53 | |
public List<SwitchCase> getCases() |
54 | |
{ |
55 | 0 | return _unmodifiableCases; |
56 | |
} |
57 | |
|
58 | |
public void addCase(SwitchCase switchCase) |
59 | |
{ |
60 | 0 | checkInitialized(); |
61 | 0 | _cases.add(switchCase); |
62 | 0 | } |
63 | |
|
64 | |
@Override |
65 | |
public String getDefaultOutcome(FacesContext context) |
66 | |
{ |
67 | 0 | if (_defaultOutcomeEL != null) |
68 | |
{ |
69 | 0 | return (String) _defaultOutcomeEL.getValue(context.getELContext()); |
70 | |
} |
71 | 0 | return _defaultOutcome; |
72 | |
} |
73 | |
|
74 | |
@Override |
75 | |
public String getId() |
76 | |
{ |
77 | 0 | return _id; |
78 | |
} |
79 | |
|
80 | |
public void freeze() |
81 | |
{ |
82 | 0 | _initialized = true; |
83 | |
|
84 | 0 | for (SwitchCase switchCase : _cases) |
85 | |
{ |
86 | 0 | if (switchCase instanceof Freezable) |
87 | |
{ |
88 | 0 | ((Freezable)switchCase).freeze(); |
89 | |
} |
90 | 0 | } |
91 | 0 | } |
92 | |
|
93 | |
private void checkInitialized() throws IllegalStateException |
94 | |
{ |
95 | 0 | if (_initialized) |
96 | |
{ |
97 | 0 | throw new IllegalStateException("Flow is inmutable once initialized"); |
98 | |
} |
99 | 0 | } |
100 | |
|
101 | |
public void setDefaultOutcome(String defaultOutcome) |
102 | |
{ |
103 | 0 | checkInitialized(); |
104 | 0 | this._defaultOutcome = defaultOutcome; |
105 | 0 | this._defaultOutcomeEL = null; |
106 | 0 | } |
107 | |
|
108 | |
public void setDefaultOutcome(ValueExpression defaultOutcome) |
109 | |
{ |
110 | 0 | checkInitialized(); |
111 | 0 | this._defaultOutcomeEL = defaultOutcome; |
112 | 0 | this._defaultOutcome = null; |
113 | 0 | } |
114 | |
|
115 | |
public void setId(String id) |
116 | |
{ |
117 | 0 | checkInitialized(); |
118 | 0 | this._id = id; |
119 | 0 | } |
120 | |
} |