001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.scxml.model;
018:
019: import java.io.Serializable;
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import org.apache.commons.scxml.SCXMLHelper;
024:
025: /**
026: * The class in this SCXML object model that corresponds to the
027: * <scxml> root element, and serves as the "document
028: * root".
029: *
030: */
031: public class SCXML implements Serializable {
032:
033: /**
034: * Serial version UID.
035: */
036: private static final long serialVersionUID = 1L;
037:
038: /**
039: * The SCXML XMLNS.
040: */
041: public static final String XMLNS = "http://www.w3.org/2005/07/scxml";
042:
043: /**
044: * The xmlns attribute on the root <smxml> element.
045: * This must match XMLNS above.
046: */
047: private String xmlns;
048:
049: /**
050: * The SCXML version of this document.
051: */
052: private String version;
053:
054: /**
055: * The initial State for the SCXML executor.
056: */
057: private State initialState;
058:
059: /**
060: * The initial state ID (used by XML Digester only).
061: */
062: private String initialstate;
063:
064: /**
065: * Optional property holding the data model for this SCXML document.
066: * This gets merged with the root context and potentially hides any
067: * (namesake) variables in the root context.
068: */
069: private Datamodel datamodel;
070:
071: /**
072: * The immediate child states of this SCXML document root.
073: */
074: private Map states;
075:
076: /**
077: * A global map of all States and Parallels associated with this
078: * state machine, keyed by their id.
079: */
080: private Map targets;
081:
082: /**
083: * Constructor.
084: */
085: public SCXML() {
086: this .states = new HashMap();
087: this .targets = new HashMap();
088: }
089:
090: /**
091: * Get the initial State.
092: *
093: * @return State Returns the initialstate.
094: */
095: public final State getInitialState() {
096: return initialState;
097: }
098:
099: /**
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: // Target is not anonymous, so makes sense to map it
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: }
|