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.io.Serializable;
20 import java.util.Collection;
21 import java.util.Map;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.scxml.ErrorReporter;
25 import org.apache.commons.scxml.EventDispatcher;
26 import org.apache.commons.scxml.SCInstance;
27 import org.apache.commons.scxml.SCXMLExpressionException;
28
29 /***
30 * An abstract base class for executable elements in SCXML,
31 * such as <assign>, <log> etc.
32 *
33 */
34 public abstract class Action implements NamespacePrefixesHolder,
35 Serializable {
36
37 /***
38 * Link to its parent or container.
39 */
40 private Executable parent;
41
42 /***
43 * The current XML namespaces in the SCXML document for this action node,
44 * preserved for deferred XPath evaluation.
45 */
46 private Map namespaces;
47
48 /***
49 * Current document namespaces are saved under this key in the parent
50 * state's context.
51 */
52 private static final String NAMESPACES_KEY = "_ALL_NAMESPACES";
53
54 /***
55 * Constructor.
56 */
57 public Action() {
58 super();
59 this.parent = null;
60 this.namespaces = null;
61 }
62
63 /***
64 * Get the Executable parent.
65 *
66 * @return Returns the parent.
67 */
68 public final Executable getParent() {
69 return parent;
70 }
71
72 /***
73 * Set the Executable parent.
74 *
75 * @param parent The parent to set.
76 */
77 public final void setParent(final Executable parent) {
78 this.parent = parent;
79 }
80
81 /***
82 * Get the XML namespaces at this action node in the SCXML document.
83 *
84 * @return Returns the map of namespaces.
85 */
86 public final Map getNamespaces() {
87 return namespaces;
88 }
89
90 /***
91 * Set the XML namespaces at this action node in the SCXML document.
92 *
93 * @param namespaces The document namespaces.
94 */
95 public final void setNamespaces(final Map namespaces) {
96 this.namespaces = namespaces;
97 }
98
99 /***
100 * Return the parent state.
101 *
102 * @return The parent State
103 * @throws ModelException For an unknown TransitionTarget subclass
104 */
105 public final State getParentState() throws ModelException {
106 TransitionTarget tt = parent.getParent();
107 if (tt instanceof State) {
108 State st = (State) tt;
109 return st;
110 } else if (tt instanceof Parallel || tt instanceof History) {
111 State st = (State) tt.getParent();
112 return st;
113 } else {
114 throw new ModelException("Unknown TransitionTarget subclass:"
115 + tt.getClass().getName());
116 }
117 }
118
119 /***
120 * Execute this action instance.
121 *
122 * @param evtDispatcher The EventDispatcher for this execution instance
123 * @param errRep The ErrorReporter to broadcast any errors
124 * during execution.
125 * @param scInstance The state machine execution instance information.
126 * @param appLog The application Log.
127 * @param derivedEvents The collection to which any internal events
128 * arising from the execution of this action
129 * must be added.
130 *
131 * @throws ModelException If the execution causes the model to enter
132 * a non-deterministic state.
133 * @throws SCXMLExpressionException If the execution involves trying
134 * to evaluate an expression which is malformed.
135 */
136 public abstract void execute(final EventDispatcher evtDispatcher,
137 final ErrorReporter errRep, final SCInstance scInstance,
138 final Log appLog, final Collection derivedEvents)
139 throws ModelException, SCXMLExpressionException;
140
141 /***
142 * Return the key under which the current document namespaces are saved
143 * in the parent state's context.
144 *
145 * @return The namespaces key
146 */
147 protected static String getNamespacesKey() {
148 return NAMESPACES_KEY;
149 }
150
151 }
152