001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.scxml.model; 018 019 import java.util.Collection; 020 021 import org.apache.commons.scxml.Context; 022 import org.apache.commons.scxml.ErrorReporter; 023 import org.apache.commons.scxml.Evaluator; 024 import org.apache.commons.scxml.EventDispatcher; 025 import org.apache.commons.scxml.SCInstance; 026 import org.apache.commons.scxml.SCXMLExpressionException; 027 028 /** 029 * The class in this SCXML object model that corresponds to the 030 * <log> SCXML element. 031 * 032 */ 033 public class Log extends Action { 034 035 /** 036 * Serial version UID. 037 */ 038 private static final long serialVersionUID = 1L; 039 040 /** 041 * An expression evaluating to a string to be logged. 042 */ 043 private String expr; 044 045 /** 046 * An expression which returns string which may be used, for example, 047 * to indicate the purpose of the log. 048 */ 049 private String label; 050 051 /** 052 * Constructor. 053 */ 054 public Log() { 055 super(); 056 } 057 058 /** 059 * Get the log expression. 060 * 061 * @return Returns the expression. 062 */ 063 public final String getExpr() { 064 return expr; 065 } 066 067 /** 068 * Set the log expression. 069 * 070 * @param expr The expr to set. 071 */ 072 public final void setExpr(final String expr) { 073 this.expr = expr; 074 } 075 076 /** 077 * Get the log label. 078 * 079 * @return Returns the label. 080 */ 081 public final String getLabel() { 082 return label; 083 } 084 085 /** 086 * Set the log label. 087 * 088 * @param label The label to set. 089 */ 090 public final void setLabel(final String label) { 091 this.label = label; 092 } 093 094 /** 095 * {@inheritDoc} 096 */ 097 public void execute(final EventDispatcher evtDispatcher, 098 final ErrorReporter errRep, final SCInstance scInstance, 099 final org.apache.commons.logging.Log appLog, 100 final Collection derivedEvents) 101 throws ModelException, SCXMLExpressionException { 102 Context ctx = scInstance.getContext(getParentTransitionTarget()); 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