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