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 java.util.Map;
20 import java.util.StringTokenizer;
21
22 import org.apache.commons.scxml2.ActionExecutionContext;
23 import org.apache.commons.scxml2.Context;
24 import org.apache.commons.scxml2.Evaluator;
25 import org.apache.commons.scxml2.SCXMLExpressionException;
26 import org.apache.commons.scxml2.semantics.ErrorConstants;
27
28
29
30
31
32
33 public abstract class NamelistHolder extends ParamsContainer {
34
35
36
37
38 private String namelist;
39
40
41
42
43
44
45 public final String getNamelist() {
46 return namelist;
47 }
48
49
50
51
52
53
54 public final void setNamelist(final String namelist) {
55 this.namelist = namelist;
56 }
57
58
59
60
61
62
63
64
65
66
67
68 protected void addNamelistDataToPayload(ActionExecutionContext exctx, Map<String, Object> payload)
69 throws ModelException, SCXMLExpressionException {
70 if (namelist != null) {
71 EnterableState parentState = getParentEnterableState();
72 Context ctx = exctx.getContext(parentState);
73 try {
74 ctx.setLocal(getNamespacesKey(), getNamespaces());
75 Evaluator evaluator = exctx.getEvaluator();
76 StringTokenizer tkn = new StringTokenizer(namelist);
77 boolean xpathEvaluator = Evaluator.XPATH_DATA_MODEL.equals(evaluator.getSupportedDatamodel());
78 while (tkn.hasMoreTokens()) {
79 String varName = tkn.nextToken();
80 Object varObj = evaluator.eval(ctx, varName);
81 if (varObj == null) {
82
83 exctx.getErrorReporter().onError(ErrorConstants.UNDEFINED_VARIABLE,
84 varName + " = null", parentState);
85 }
86 if (xpathEvaluator && varName.startsWith("$")) {
87 varName = varName.substring(1);
88 }
89 addToPayload(varName, varObj, payload);
90 }
91 }
92 finally {
93 ctx.setLocal(getNamespacesKey(), null);
94 }
95 }
96 }
97 }