| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| SCXML |
|
| 1.0666666666666667;1.067 |
| 1 | /* |
|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
|
| 4 | * this work for additional information regarding copyright ownership. |
|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
| 6 | * (the "License"); you may not use this file except in compliance with |
|
| 7 | * the License. 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 | 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 | 55 | public SCXML() { |
| 86 | 55 | this.states = new HashMap(); |
| 87 | 55 | this.targets = new HashMap(); |
| 88 | 55 | } |
| 89 | ||
| 90 | /** |
|
| 91 | * Get the initial State. |
|
| 92 | * |
|
| 93 | * @return State Returns the initialstate. |
|
| 94 | */ |
|
| 95 | public final State getInitialState() { |
|
| 96 | 51 | 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 | 51 | this.initialState = initialState; |
| 106 | 51 | } |
| 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 | 58 | 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 | 8 | this.datamodel = datamodel; |
| 124 | 8 | } |
| 125 | ||
| 126 | /** |
|
| 127 | * Get the children states. |
|
| 128 | * |
|
| 129 | * @return Map Returns map of the child states. |
|
| 130 | */ |
|
| 131 | public final Map getStates() { |
|
| 132 | 59 | 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 | 142 | states.put(state.getId(), state); |
| 142 | 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 | 154 | 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 | 294 | String id = target.getId(); |
| 161 | 294 | if (!SCXMLHelper.isStringEmpty(id)) { |
| 162 | // Target is not anonymous, so makes sense to map it |
|
| 163 | 255 | targets.put(id, target); |
| 164 | } |
|
| 165 | 294 | } |
| 166 | ||
| 167 | /** |
|
| 168 | * Get the SCXML document version. |
|
| 169 | * |
|
| 170 | * @return Returns the version. |
|
| 171 | */ |
|
| 172 | public final String getVersion() { |
|
| 173 | 5 | 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 | 55 | this.version = version; |
| 183 | 55 | } |
| 184 | ||
| 185 | /** |
|
| 186 | * Get the xmlns of this SCXML document. |
|
| 187 | * |
|
| 188 | * @return Returns the xmlns. |
|
| 189 | */ |
|
| 190 | public final String getXmlns() { |
|
| 191 | 5 | 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 | 1 | this.xmlns = xmlns; |
| 201 | 1 | } |
| 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 | 59 | 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 | 55 | this.initialstate = initialstate; |
| 221 | 55 | } |
| 222 | ||
| 223 | } |
|
| 224 |