1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.scxml;
19
20 import java.util.ArrayList;
21 import java.util.HashSet;
22 import java.util.Iterator;
23 import java.util.Set;
24 import java.util.Collection;
25
26 import org.apache.commons.scxml.model.State;
27
28 /***
29 * The encapsulation of the current state of a state machine.
30 *
31 */
32 public class Status {
33
34 /***
35 * The states that are currently active.
36 */
37 private Set states;
38
39 /***
40 * The events that are currently queued.
41 */
42 private Collection events;
43
44 /***
45 * Have we reached a final configuration for this state machine.
46 *
47 * True - if all the states are final and there are not events
48 * pending from the last step. False - otherwise.
49 *
50 * @return Whether a final configuration has been reached.
51 */
52 public boolean isFinal() {
53 boolean rslt = true;
54 for (Iterator i = states.iterator(); i.hasNext();) {
55 State s = (State) i.next();
56 if (!s.getIsFinal()) {
57 rslt = false;
58 break;
59 }
60
61 if (s.getParent() != null) {
62 rslt = false;
63 break;
64 }
65 }
66 if (!events.isEmpty()) {
67 rslt = false;
68 }
69 return rslt;
70 }
71
72 /***
73 * Constructor.
74 */
75 public Status() {
76 states = new HashSet();
77 events = new ArrayList();
78 }
79
80 /***
81 * Get the states configuration (leaf only).
82 *
83 * @return Returns the states configuration - simple (leaf) states only.
84 */
85 public Set getStates() {
86 return states;
87 }
88
89 /***
90 * Get the events that are currently queued.
91 *
92 * @return The events that are currently queued.
93 */
94 public Collection getEvents() {
95 return events;
96 }
97
98 /***
99 * Get the complete states configuration.
100 *
101 * @return complete states configuration including simple states and their
102 * complex ancestors up to the root.
103 */
104 public Set getAllStates() {
105 return SCXMLHelper.getAncestorClosure(states, null);
106 }
107
108 }
109