##### Coverage Report - org.apache.commons.scxml.model.Log

Classes in this File | Line Coverage | Branch Coverage | Complexity
Log |
92% |
N/A |
| 1.0;1

1 |  |
     /*
2 |  |
      *
3 |  |
      *   Copyright 2005 The Apache Software Foundation.
4 |  |
      *
5 |  |
      *  Licensed under the Apache License, Version 2.0 (the "License");
6 |  |
      *  you may not use this file except in compliance with the License.
7 |  |
      *  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 |  |
      */
18 |  |
     package org.apache.commons.scxml.model;
19 |  |
20 |  |
     import java.util.Collection;
21 |  |
22 |  |
     import org.apache.commons.scxml.Context;
23 |  |
     import org.apache.commons.scxml.ErrorReporter;
24 |  |
     import org.apache.commons.scxml.Evaluator;
25 |  |
     import org.apache.commons.scxml.EventDispatcher;
26 |  |
     import org.apache.commons.scxml.SCInstance;
27 |  |
     import org.apache.commons.scxml.SCXMLExpressionException;
28 |  |
29 |  |
     /**
30 |  |
      * The class in this SCXML object model that corresponds to the
31 |  |
      * &lt;log&gt; SCXML element.
32 |  |
      *
33 |  |
      */
34 |  |
     public class Log extends Action {
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 | 26 |
             super();
52 | 26 |
         }
53 |  |
54 |  |
         /**
55 |  |
          * Get the log expression.
56 |  |
          *
57 |  |
          * @return Returns the expression.
58 |  |
          */
59 |  |
         public final String getExpr() {
60 | 11 |
             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 | 26 |
             this.expr = expr;
70 | 26 |
         }
71 |  |
72 |  |
         /**
73 |  |
          * Get the log label.
74 |  |
          *
75 |  |
          * @return Returns the label.
76 |  |
          */
77 |  |
         public final String getLabel() {
78 | 0 |
             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 | 1 |
             this.label = label;
88 | 1 |
         }
89 |  |
90 |  |
         /**
91 |  |
          * {@inheritDoc}
92 |  |
          */
93 |  |
         public void execute(final EventDispatcher evtDispatcher,
94 |  |
                 final ErrorReporter errRep, final SCInstance scInstance,
95 |  |
                 final org.apache.commons.logging.Log appLog,
96 |  |
                 final Collection derivedEvents)
97 |  |
         throws ModelException, SCXMLExpressionException {
98 | 8 |
             Context ctx = scInstance.getContext(getParentState());
99 | 8 |
             Evaluator eval = scInstance.getEvaluator();
100 | 8 |
             appLog.info(label + ": " + String.valueOf(eval.eval(ctx, expr)));
101 | 8 |
         }
102 |  |
     }
103 |  |