1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
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 * The class in this SCXML object model that corresponds to the
26 * <log> SCXML element.
27 *
28 */
29 public class Log extends Action {
30
31 /**
32 * Serial version UID.
33 */
34 private static final long serialVersionUID = 1L;
35
36 /**
37 * An expression evaluating to a string to be logged.
38 */
39 private String expr;
40
41 /**
42 * An expression which returns string which may be used, for example,
43 * to indicate the purpose of the log.
44 */
45 private String label;
46
47 /**
48 * Constructor.
49 */
50 public Log() {
51 super();
52 }
53
54 /**
55 * Get the log expression.
56 *
57 * @return Returns the expression.
58 */
59 public final String getExpr() {
60 return expr;
61 }
62
63 /**
64 * Set the log expression.
65 *
66 * @param expr The expr to set.
67 */
68 public final void setExpr(final String expr) {
69 this.expr = expr;
70 }
71
72 /**
73 * Get the log label.
74 *
75 * @return Returns the label.
76 */
77 public final String getLabel() {
78 return label;
79 }
80
81 /**
82 * Set the log label.
83 *
84 * @param label The label to set.
85 */
86 public final void setLabel(final String label) {
87 this.label = label;
88 }
89
90 /**
91 * {@inheritDoc}
92 */
93 @Override
94 public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
95 Context ctx = exctx.getContext(getParentEnterableState());
96 Evaluator eval = exctx.getEvaluator();
97 ctx.setLocal(getNamespacesKey(), getNamespaces());
98 exctx.getAppLog().info(label + ": " + String.valueOf(getTextContentIfNodeResult(eval.eval(ctx, expr))));
99 ctx.setLocal(getNamespacesKey(), null);
100 }
101 }
102