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 {
47 this._id = switchNodeId;
48 _cases = new ArrayList<SwitchCase>();
49 _unmodifiableCases = Collections.unmodifiableList(_cases);
50 }
51
52 @Override
53 public List<SwitchCase> getCases()
54 {
55 return _unmodifiableCases;
56 }
57
58 public void addCase(SwitchCase switchCase)
59 {
60 checkInitialized();
61 _cases.add(switchCase);
62 }
63
64 @Override
65 public String getDefaultOutcome(FacesContext context)
66 {
67 if (_defaultOutcomeEL != null)
68 {
69 return (String) _defaultOutcomeEL.getValue(context.getELContext());
70 }
71 return _defaultOutcome;
72 }
73
74 @Override
75 public String getId()
76 {
77 return _id;
78 }
79
80 public void freeze()
81 {
82 _initialized = true;
83
84 for (SwitchCase switchCase : _cases)
85 {
86 if (switchCase instanceof Freezable)
87 {
88 ((Freezable)switchCase).freeze();
89 }
90 }
91 }
92
93 private void checkInitialized() throws IllegalStateException
94 {
95 if (_initialized)
96 {
97 throw new IllegalStateException("Flow is inmutable once initialized");
98 }
99 }
100
101 public void setDefaultOutcome(String defaultOutcome)
102 {
103 checkInitialized();
104 this._defaultOutcome = defaultOutcome;
105 this._defaultOutcomeEL = null;
106 }
107
108 public void setDefaultOutcome(ValueExpression defaultOutcome)
109 {
110 checkInitialized();
111 this._defaultOutcomeEL = defaultOutcome;
112 this._defaultOutcome = null;
113 }
114
115 public void setId(String id)
116 {
117 checkInitialized();
118 this._id = id;
119 }
120 }