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

Classes in this File Line Coverage Branch Coverage Complexity
Log
93% 
N/A 
1

 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.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  34
         super();
 56  34
     }
 57  
 
 58  
     /**
 59  
      * Get the log expression.
 60  
      *
 61  
      * @return Returns the expression.
 62  
      */
 63  
     public final String getExpr() {
 64  11
         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  34
         this.expr = expr;
 74  34
     }
 75  
 
 76  
     /**
 77  
      * Get the log label.
 78  
      *
 79  
      * @return Returns the label.
 80  
      */
 81  
     public final String getLabel() {
 82  0
         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  1
         this.label = label;
 92  1
     }
 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  15
         Context ctx = scInstance.getContext(getParentState());
 103  15
         Evaluator eval = scInstance.getEvaluator();
 104  15
         ctx.setLocal(getNamespacesKey(), getNamespaces());
 105  15
         appLog.info(label + ": " + String.valueOf(eval.eval(ctx, expr)));
 106  15
         ctx.setLocal(getNamespacesKey(), null);
 107  15
     }
 108  
 }
 109