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