##### Coverage Report - org.apache.commons.scxml.model.SCXML

Classes in this File | Line Coverage | Branch Coverage | Complexity
SCXML |
100% |
100% |
| 1.0666666666666667;1.067

1 |  |
     /*
2 |  |
      *
3 |  |
      *   Copyright 2005-2006 The Apache Software Foundation.
4 |  |
      *
5 |  |
      *  Licensed under the Apache License, Version 2.0 (the "License");
6 |  |
      *  you may not use this file except in compliance with the License.
7 |  |
      *  You may obtain a copy of the License at
8 |  |
      *
9 |  |
      *      http://www.apache.org/licenses/LICENSE-2.0
10 |  |
      *
11 |  |
      *  Unless required by applicable law or agreed to in writing, software
12 |  |
      *  distributed under the License is distributed on an "AS IS" BASIS,
13 |  |
      *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 |  |
      *  See the License for the specific language governing permissions and
15 |  |
      *  limitations under the License.
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 |  |
      * &lt;scxml&gt; root element, and serves as the &quot;document
28 |  |
      * root&quot;.
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 &lt;smxml&gt; 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 | 41 |
         public SCXML() {
81 | 41 |
             this.states = new HashMap();
82 | 41 |
             this.targets = new HashMap();
83 | 41 |
         }
84 |  |
85 |  |
         /**
86 |  |
          * Get the initial State.
87 |  |
          *
88 |  |
          * @return State Returns the initialstate.
89 |  |
          */
90 |  |
         public final State getInitialState() {
91 | 40 |
             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 | 39 |
             this.initialState = initialState;
101 | 39 |
         }
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 | 44 |
             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 | 4 |
             this.datamodel = datamodel;
119 | 4 |
         }
120 |  |
121 |  |
         /**
122 |  |
          * Get the children states.
123 |  |
          *
124 |  |
          * @return Map Returns map of the child states.
125 |  |
          */
126 |  |
         public final Map getStates() {
127 | 44 |
             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 | 91 |
             states.put(state.getId(), state);
137 | 91 |
         }
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 | 119 |
             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 | 243 |
             String id = target.getId();
156 | 243 |
             if (!SCXMLHelper.isStringEmpty(id)) {
157 |  |
                 // Target is not anonymous, so makes sense to map it
158 | 204 |
                 targets.put(id, target);
159 |  |
             }
160 | 243 |
         }
161 |  |
162 |  |
         /**
163 |  |
          * Get the SCXML document version.
164 |  |
          *
165 |  |
          * @return Returns the version.
166 |  |
          */
167 |  |
         public final String getVersion() {
168 | 4 |
             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 | 41 |
             this.version = version;
178 | 41 |
         }
179 |  |
180 |  |
         /**
181 |  |
          * Get the xmlns of this SCXML document.
182 |  |
          *
183 |  |
          * @return Returns the xmlns.
184 |  |
          */
185 |  |
         public final String getXmlns() {
186 | 4 |
             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 | 1 |
             this.xmlns = xmlns;
196 | 1 |
         }
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 | 44 |
             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 | 41 |
             this.initialstate = initialstate;
216 | 41 |
         }
217 |  |
218 |  |
     }
219 |  |