1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml.model;
18
19 import java.io.Serializable;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.apache.commons.scxml.SCXMLHelper;
24
25 /***
26 * The class in this SCXML object model that corresponds to the
27 * <scxml> root element, and serves as the "document
28 * root".
29 *
30 */
31 public class SCXML implements Serializable {
32
33 /***
34 * Serial version UID.
35 */
36 private static final long serialVersionUID = 1L;
37
38 /***
39 * The SCXML XMLNS.
40 */
41 public static final String XMLNS = "http://www.w3.org/2005/07/scxml";
42
43 /***
44 * The xmlns attribute on the root <smxml> element.
45 * This must match XMLNS above.
46 */
47 private String xmlns;
48
49 /***
50 * The SCXML version of this document.
51 */
52 private String version;
53
54 /***
55 * The initial State for the SCXML executor.
56 */
57 private State initialState;
58
59 /***
60 * The initial state ID (used by XML Digester only).
61 */
62 private String initialstate;
63
64 /***
65 * Optional property holding the data model for this SCXML document.
66 * This gets merged with the root context and potentially hides any
67 * (namesake) variables in the root context.
68 */
69 private Datamodel datamodel;
70
71 /***
72 * The immediate child states of this SCXML document root.
73 */
74 private Map states;
75
76 /***
77 * A global map of all States and Parallels associated with this
78 * state machine, keyed by their id.
79 */
80 private Map targets;
81
82 /***
83 * Constructor.
84 */
85 public SCXML() {
86 this.states = new HashMap();
87 this.targets = new HashMap();
88 }
89
90 /***
91 * Get the initial State.
92 *
93 * @return State Returns the initialstate.
94 */
95 public final State getInitialState() {
96 return initialState;
97 }
98
99 /***
100 * Set the initial State.
101 *
102 * @param initialState The initialstate to set.
103 */
104 public final void setInitialState(final State initialState) {
105 this.initialState = initialState;
106 }
107
108 /***
109 * Get the data model placed at document root.
110 *
111 * @return Returns the data model.
112 */
113 public final Datamodel getDatamodel() {
114 return datamodel;
115 }
116
117 /***
118 * Set the data model at document root.
119 *
120 * @param datamodel The Datamodel to set.
121 */
122 public final void setDatamodel(final Datamodel datamodel) {
123 this.datamodel = datamodel;
124 }
125
126 /***
127 * Get the children states.
128 *
129 * @return Map Returns map of the child states.
130 */
131 public final Map getStates() {
132 return states;
133 }
134
135 /***
136 * Add a child state.
137 *
138 * @param state The state to be added to the states Map.
139 */
140 public final void addState(final State state) {
141 states.put(state.getId(), state);
142 }
143
144 /***
145 * Get the targets map, whichis a Map of all States and Parallels
146 * associated with this state machine, keyed by their id.
147 *
148 * @return Map Returns the targets.
149 */
150 public final Map getTargets() {
151 return targets;
152 }
153
154 /***
155 * Add a target to this SCXML document.
156 *
157 * @param target The target to be added to the targets Map.
158 */
159 public final void addTarget(final TransitionTarget target) {
160 String id = target.getId();
161 if (!SCXMLHelper.isStringEmpty(id)) {
162
163 targets.put(id, target);
164 }
165 }
166
167 /***
168 * Get the SCXML document version.
169 *
170 * @return Returns the version.
171 */
172 public final String getVersion() {
173 return version;
174 }
175
176 /***
177 * Set the SCXML document version.
178 *
179 * @param version The version to set.
180 */
181 public final void setVersion(final String version) {
182 this.version = version;
183 }
184
185 /***
186 * Get the xmlns of this SCXML document.
187 *
188 * @return Returns the xmlns.
189 */
190 public final String getXmlns() {
191 return xmlns;
192 }
193
194 /***
195 * Set the xmlns of this SCXML document.
196 *
197 * @param xmlns The xmlns to set.
198 */
199 public final void setXmlns(final String xmlns) {
200 this.xmlns = xmlns;
201 }
202
203 /***
204 * Get the ID of the initial state.
205 *
206 * @return String Returns the initial state ID (used by XML Digester only).
207 * @see #getInitialState()
208 */
209 public final String getInitialstate() {
210 return initialstate;
211 }
212
213 /***
214 * Set the ID of the initial state.
215 *
216 * @param initialstate The initial state ID (used by XML Digester only).
217 * @see #setInitialState(State)
218 */
219 public final void setInitialstate(final String initialstate) {
220 this.initialstate = initialstate;
221 }
222
223 }
224