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.util.Map;
20
21 /***
22 * The class in this SCXML object model that corresponds to the
23 * <transition> SCXML element. Transition rules are triggered
24 * by "events" and conditionalized via
25 * "guard-conditions".
26 *
27 */
28 public class Transition extends Executable
29 implements NamespacePrefixesHolder {
30
31 /***
32 * Serial version UID.
33 */
34 private static final long serialVersionUID = 1L;
35
36 /***
37 * Property that specifies the trigger for this transition.
38 */
39 private String event;
40
41 /***
42 * Optional guard condition.
43 */
44 private String cond;
45
46 /***
47 * Optional property that specifies the new state or parallel
48 * element to transition to. May be specified by reference or in-line.
49 */
50 private TransitionTarget target;
51
52 /***
53 * The transition target ID (used by XML Digester only).
54 */
55 private String next;
56
57 /***
58 * The path for this transition.
59 * @see Path
60 */
61 private Path path;
62
63 /***
64 * The current XML namespaces in the SCXML document for this action node,
65 * preserved for deferred XPath evaluation.
66 */
67 private Map namespaces;
68
69 /***
70 * Constructor.
71 */
72 public Transition() {
73 super();
74 this.target = null;
75 this.path = null;
76 }
77
78 /***
79 * Get the guard condition (may be null).
80 *
81 * @return Returns the cond.
82 */
83 public final String getCond() {
84 return cond;
85 }
86
87 /***
88 * Set the guard condition.
89 *
90 * @param cond The cond to set.
91 */
92 public final void setCond(final String cond) {
93 this.cond = cond;
94 }
95
96 /***
97 * Get the event that will trigger this transition (pending
98 * evaluation of the guard condition in favor).
99 *
100 * @return Returns the event.
101 */
102 public final String getEvent() {
103 return event;
104 }
105
106 /***
107 * Set the event that will trigger this transition (pending
108 * evaluation of the guard condition in favor).
109 *
110 * @param event The event to set.
111 */
112 public final void setEvent(final String event) {
113 this.event = event;
114 }
115
116 /***
117 * Get the XML namespaces at this action node in the SCXML document.
118 *
119 * @return Returns the map of namespaces.
120 */
121 public final Map getNamespaces() {
122 return namespaces;
123 }
124
125 /***
126 * Set the XML namespaces at this action node in the SCXML document.
127 *
128 * @param namespaces The document namespaces.
129 */
130 public final void setNamespaces(final Map namespaces) {
131 this.namespaces = namespaces;
132 }
133
134 /***
135 * Get the transition target (may be null).
136 *
137 * @return Returns the target as specified in SCXML markup.
138 * <p>Remarks: Is <code>null</code> for "stay" transitions.
139 * Returns parent (the source node) for "self" transitions.</p>
140 */
141 public final TransitionTarget getTarget() {
142 return target;
143 }
144
145 /***
146 * Get the runtime transition target, which always resolves to
147 * a TransitionTarget instance.
148 *
149 * @return Returns the actual target of a transition at runtime.
150 * <p>Remarks: For both the "stay" and "self"
151 * transitions it returns parent (the source node). This method should
152 * never return <code>null</code>.</p>
153 */
154 public final TransitionTarget getRuntimeTarget() {
155 if (target != null) {
156 return target;
157 }
158 return getParent();
159 }
160
161
162 /***
163 * Set the transition target.
164 *
165 * @param target The target to set.
166 */
167 public final void setTarget(final TransitionTarget target) {
168 this.target = target;
169 }
170
171 /***
172 * Get the ID of the transition target (may be null, if, for example,
173 * the target is specified inline).
174 *
175 * @return String Returns the transition target ID
176 * (used by SCXML Digester only).
177 * @see #getTarget()
178 */
179 public final String getNext() {
180 return next;
181 }
182
183 /***
184 * Set the transition target by specifying its ID.
185 *
186 * @param next The the transition target ID (used by SCXML Digester only).
187 * @see #setTarget(TransitionTarget)
188 */
189 public final void setNext(final String next) {
190 this.next = next;
191 }
192
193 /***
194 * Get the path of this transiton.
195 *
196 * @see Path
197 * @return Path returns the transition path
198 */
199 public final Path getPath() {
200 if (path == null) {
201 path = new Path(getParent(), getTarget());
202 }
203 return path;
204 }
205
206 }
207