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 import org.apache.commons.scxml2.TriggerEvent;
24
25
26
27
28
29
30 public class Var extends Action {
31
32
33
34
35 private static final long serialVersionUID = 1L;
36
37
38
39
40 private String name;
41
42
43
44
45 private String expr;
46
47
48
49
50 public Var() {
51 super();
52 }
53
54
55
56
57
58
59
60 public final String getExpr() {
61 return expr;
62 }
63
64
65
66
67
68
69
70 public final void setExpr(final String expr) {
71 this.expr = expr;
72 }
73
74
75
76
77
78
79 public final String getName() {
80 return name;
81 }
82
83
84
85
86
87
88 public final void setName(final String name) {
89 this.name = name;
90 }
91
92
93
94
95 @Override
96 public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
97 Context ctx = exctx.getContext(getParentEnterableState());
98 Evaluator eval = exctx.getEvaluator();
99 ctx.setLocal(getNamespacesKey(), getNamespaces());
100 Object varObj = eval.eval(ctx, expr);
101 ctx.setLocal(getNamespacesKey(), null);
102 ctx.setLocal(name, varObj);
103 if (exctx.getAppLog().isDebugEnabled()) {
104 exctx.getAppLog().debug("<var>: Defined variable '" + name
105 + "' with initial value '" + String.valueOf(varObj) + "'");
106 }
107 TriggerEvent ev = new TriggerEvent(name + ".change", TriggerEvent.CHANGE_EVENT);
108 exctx.getInternalIOProcessor().addEvent(ev);
109 }
110 }
111