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.util.Map;
020:
021: /**
022: * The class in this SCXML object model that corresponds to the
023: * <transition> SCXML element. Transition rules are triggered
024: * by "events" and conditionalized via
025: * "guard-conditions".
026: *
027: */
028: public class Transition extends Executable implements
029: NamespacePrefixesHolder {
030:
031: /**
032: * Serial version UID.
033: */
034: private static final long serialVersionUID = 1L;
035:
036: /**
037: * Property that specifies the trigger for this transition.
038: */
039: private String event;
040:
041: /**
042: * Optional guard condition.
043: */
044: private String cond;
045:
046: /**
047: * Optional property that specifies the new state or parallel
048: * element to transition to. May be specified by reference or in-line.
049: */
050: private TransitionTarget target;
051:
052: /**
053: * The transition target ID (used by XML Digester only).
054: */
055: private String next;
056:
057: /**
058: * The path for this transition.
059: * @see Path
060: */
061: private Path path;
062:
063: /**
064: * The current XML namespaces in the SCXML document for this action node,
065: * preserved for deferred XPath evaluation.
066: */
067: private Map namespaces;
068:
069: /**
070: * Constructor.
071: */
072: public Transition() {
073: super ();
074: this .target = null;
075: this .path = null;
076: }
077:
078: /**
079: * Get the guard condition (may be null).
080: *
081: * @return Returns the cond.
082: */
083: public final String getCond() {
084: return cond;
085: }
086:
087: /**
088: * Set the guard condition.
089: *
090: * @param cond The cond to set.
091: */
092: public final void setCond(final String cond) {
093: this .cond = cond;
094: }
095:
096: /**
097: * Get the event that will trigger this transition (pending
098: * evaluation of the guard condition in favor).
099: *
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: * Set the transition target.
163: *
164: * @param target The target to set.
165: */
166: public final void setTarget(final TransitionTarget target) {
167: this .target = target;
168: }
169:
170: /**
171: * Get the ID of the transition target (may be null, if, for example,
172: * the target is specified inline).
173: *
174: * @return String Returns the transition target ID
175: * (used by SCXML Digester only).
176: * @see #getTarget()
177: */
178: public final String getNext() {
179: return next;
180: }
181:
182: /**
183: * Set the transition target by specifying its ID.
184: *
185: * @param next The the transition target ID (used by SCXML Digester only).
186: * @see #setTarget(TransitionTarget)
187: */
188: public final void setNext(final String next) {
189: this .next = next;
190: }
191:
192: /**
193: * Get the path of this transiton.
194: *
195: * @see Path
196: * @return Path returns the transition path
197: */
198: public final Path getPath() {
199: if (path == null) {
200: path = new Path(getParent(), getTarget());
201: }
202: return path;
203: }
204:
205: }
|