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.util.Collection;
20
21 import org.apache.commons.scxml.Context;
22 import org.apache.commons.scxml.ErrorReporter;
23 import org.apache.commons.scxml.Evaluator;
24 import org.apache.commons.scxml.EventDispatcher;
25 import org.apache.commons.scxml.SCInstance;
26 import org.apache.commons.scxml.SCXMLExpressionException;
27
28 /***
29 * The class in this SCXML object model that corresponds to the
30 * <log> SCXML element.
31 *
32 */
33 public class Log extends Action {
34
35 /***
36 * Serial version UID.
37 */
38 private static final long serialVersionUID = 1L;
39
40 /***
41 * An expression evaluating to a string to be logged.
42 */
43 private String expr;
44
45 /***
46 * An expression which returns string which may be used, for example,
47 * to indicate the purpose of the log.
48 */
49 private String label;
50
51 /***
52 * Constructor.
53 */
54 public Log() {
55 super();
56 }
57
58 /***
59 * Get the log expression.
60 *
61 * @return Returns the expression.
62 */
63 public final String getExpr() {
64 return expr;
65 }
66
67 /***
68 * Set the log expression.
69 *
70 * @param expr The expr to set.
71 */
72 public final void setExpr(final String expr) {
73 this.expr = expr;
74 }
75
76 /***
77 * Get the log label.
78 *
79 * @return Returns the label.
80 */
81 public final String getLabel() {
82 return label;
83 }
84
85 /***
86 * Set the log label.
87 *
88 * @param label The label to set.
89 */
90 public final void setLabel(final String label) {
91 this.label = label;
92 }
93
94 /***
95 * {@inheritDoc}
96 */
97 public void execute(final EventDispatcher evtDispatcher,
98 final ErrorReporter errRep, final SCInstance scInstance,
99 final org.apache.commons.logging.Log appLog,
100 final Collection derivedEvents)
101 throws ModelException, SCXMLExpressionException {
102 Context ctx = scInstance.getContext(getParentState());
103 Evaluator eval = scInstance.getEvaluator();
104 ctx.setLocal(getNamespacesKey(), getNamespaces());
105 appLog.info(label + ": " + String.valueOf(eval.eval(ctx, expr)));
106 ctx.setLocal(getNamespacesKey(), null);
107 }
108 }
109