1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.scxml.model;
19
20 import java.util.Collection;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.scxml.ErrorReporter;
24 import org.apache.commons.scxml.EventDispatcher;
25 import org.apache.commons.scxml.SCInstance;
26 import org.apache.commons.scxml.SCXMLExpressionException;
27
28 /***
29 * An abstract base class for executable elements in SCXML,
30 * such as <assign>, <log> etc.
31 *
32 */
33 public abstract class Action {
34
35 /***
36 * Link to its parent or container.
37 */
38 private Executable parent;
39
40 /***
41 * Constructor.
42 */
43 public Action() {
44 super();
45 this.parent = null;
46 }
47
48 /***
49 * Get the Executable parent.
50 *
51 * @return Returns the parent.
52 */
53 public final Executable getParent() {
54 return parent;
55 }
56
57 /***
58 * Set the Executable parent.
59 *
60 * @param parent The parent to set.
61 */
62 public final void setParent(final Executable parent) {
63 this.parent = parent;
64 }
65
66 /***
67 * Return the parent state.
68 *
69 * @return The parent State
70 * @throws ModelException For an unknown TransitionTarget subclass
71 */
72 public final State getParentState() throws ModelException {
73 TransitionTarget tt = parent.getParent();
74 if (tt instanceof State) {
75 State st = (State) tt;
76 return st;
77 } else if (tt instanceof Parallel || tt instanceof History) {
78 State st = (State) tt.getParent();
79 return st;
80 } else {
81 throw new ModelException("Unknown TransitionTarget subclass:"
82 + tt.getClass().getName());
83 }
84 }
85
86 /***
87 * Execute this action instance.
88 *
89 * @param evtDispatcher The EventDispatcher for this execution instance
90 * @param errRep The ErrorReporter to broadcast any errors
91 * during execution.
92 * @param scInstance The state machine execution instance information.
93 * @param appLog The application Log.
94 * @param derivedEvents The collection to which any internal events
95 * arising from the execution of this action
96 * must be added.
97 *
98 * @throws ModelException If the execution causes the model to enter
99 * a non-deterministic state.
100 * @throws SCXMLExpressionException If the execution involves trying
101 * to evaluate an expression which is malformed.
102 */
103 public abstract void execute(final EventDispatcher evtDispatcher,
104 final ErrorReporter errRep, final SCInstance scInstance,
105 final Log appLog, final Collection derivedEvents)
106 throws ModelException, SCXMLExpressionException;
107
108 }
109