1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml2.model;
18
19 import org.apache.commons.scxml2.ActionExecutionContext;
20 import org.apache.commons.scxml2.Context;
21 import org.apache.commons.scxml2.Evaluator;
22 import org.apache.commons.scxml2.SCXMLExpressionException;
23
24
25
26
27
28
29
30 public class Script extends Action implements BodyContainer {
31
32
33
34
35 private static final long serialVersionUID = 1L;
36
37 private boolean globalScript;
38 private String body;
39
40
41
42
43 public Script() {
44 super();
45 }
46
47 public boolean isGlobalScript() {
48 return globalScript;
49 }
50
51 public void setGlobalScript(final boolean globalScript) {
52 this.globalScript = globalScript;
53 }
54
55 @Override
56 public String getBody() {
57 return body;
58 }
59
60 @Override
61 public void setBody(String body) {
62 this.body = body;
63 }
64
65
66
67
68
69
70 public String getScript() {
71 return body;
72 }
73
74
75
76
77 @Override
78 public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
79 Context ctx = isGlobalScript() ? exctx.getGlobalContext() : exctx.getContext(getParentEnterableState());
80 ctx.setLocal(getNamespacesKey(), getNamespaces());
81 Evaluator eval = exctx.getEvaluator();
82 eval.evalScript(ctx, getScript());
83 ctx.setLocal(getNamespacesKey(), null);
84 }
85
86 }
87