1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml2;
18
19 import java.io.Serializable;
20 import java.util.Collections;
21 import java.util.HashSet;
22 import java.util.Set;
23
24 import org.apache.commons.scxml2.model.EnterableState;
25
26
27
28
29 public class StateConfiguration implements Serializable {
30
31
32
33 private static final long serialVersionUID = 1L;
34
35
36
37
38 private final Set<EnterableState> activeStates = new HashSet<EnterableState>();
39 private final Set<EnterableState> activeStatesSet = Collections.unmodifiableSet(activeStates);
40
41
42
43
44 private final Set<EnterableState> atomicStates = new HashSet<EnterableState>();
45 private final Set<EnterableState> atomicStatesSet = Collections.unmodifiableSet(atomicStates);
46
47
48
49
50
51
52
53 public Set<EnterableState> getActiveStates() {
54 return activeStatesSet;
55 }
56
57
58
59
60
61
62 public Set<EnterableState> getStates() {
63 return atomicStatesSet;
64 }
65
66
67
68
69
70
71 public void enterState(final EnterableState state) {
72 if (!activeStates.add(state)) {
73 throw new IllegalStateException("State "+state.getId()+" already added.");
74 }
75 if (state.isAtomicState()) {
76 if (!atomicStates.add(state)) {
77 throw new IllegalStateException("Atomic state "+state.getId()+" already added.");
78 }
79 }
80 }
81
82
83
84
85
86
87 public void exitState(final EnterableState state) {
88 if (!activeStates.remove(state)) {
89 throw new IllegalStateException("State "+state.getId()+" not active.");
90 }
91 atomicStates.remove(state);
92 }
93
94
95
96
97 public void clear() {
98 activeStates.clear();
99 atomicStates.clear();
100 }
101 }