Coverage Report - org.apache.commons.scxml.env.SimpleErrorReporter

Classes in this File Line Coverage Branch Coverage Complexity
SimpleErrorReporter
7% 
0% 
9

 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.env;
 19  
 
 20  
 import java.util.HashSet;
 21  
 import java.util.Iterator;
 22  
 import java.util.Map;
 23  
 import java.util.Set;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 import org.apache.commons.scxml.ErrorReporter;
 29  
 import org.apache.commons.scxml.model.SCXML;
 30  
 import org.apache.commons.scxml.model.State;
 31  
 import org.apache.commons.scxml.model.Transition;
 32  
 import org.apache.commons.scxml.model.TransitionTarget;
 33  
 
 34  
 /**
 35  
  * Custom error reporter that log execution errors.
 36  
  */
 37  
 public class SimpleErrorReporter implements ErrorReporter {
 38  
 
 39  
     /** Log. */
 40  38
     private Log log = LogFactory.getLog(getClass());
 41  
 
 42  
     /**
 43  
      * Constructor.
 44  
      */
 45  
     public SimpleErrorReporter() {
 46  38
         super();
 47  38
     }
 48  
 
 49  
     /**
 50  
      * @see ErrorReporter#onError(String, String, Object)
 51  
      */
 52  
     public void onError(final String errorCode, final String errDetail,
 53  
             final Object errCtx) {
 54  
         //Note: the if-then-else below is based on the actual usage
 55  
         // (codebase search), it has to be kept up-to-date as the code changes
 56  0
         String errCode = errorCode.intern();
 57  0
         StringBuffer msg = new StringBuffer();
 58  0
         msg.append(errCode).append(" (");
 59  0
         msg.append(errDetail).append("): ");
 60  0
         if (errCode == ErrorReporter.NO_INITIAL) {
 61  0
             if (errCtx instanceof SCXML) {
 62  
                 //determineInitialStates
 63  0
                 msg.append("<SCXML>");
 64  0
             } else if (errCtx instanceof State) {
 65  
                 //determineInitialStates
 66  
                 //determineTargetStates
 67  0
                 msg.append("State " + LogUtils.getTTPath((State) errCtx));
 68  
             }
 69  0
         } else if (errCode == ErrorReporter.UNKNOWN_ACTION) {
 70  
             //executeActionList
 71  0
             msg.append("Action: " + errCtx.getClass().getName());
 72  0
         } else if (errCode == ErrorReporter.NON_DETERMINISTIC) {
 73  
             //filterTransitionSet
 74  0
             msg.append(" [");
 75  0
             if (errCtx instanceof HashSet) {
 76  0
                 for (Iterator i = ((Set) errCtx).iterator(); i.hasNext();) {
 77  0
                     Transition t = (Transition) i.next();
 78  0
                     msg.append(LogUtils.transToString(t.getParent(),
 79  
                         t.getTarget(), t));
 80  0
                     if (i.hasNext()) {
 81  0
                         msg.append(", ");
 82  
                     }
 83  
                 }
 84  
             }
 85  0
             msg.append(']');
 86  0
         } else if (errCode == ErrorReporter.ILLEGAL_CONFIG) {
 87  
             //isLegalConfig
 88  0
             if (errCtx instanceof Map.Entry) {
 89  0
                 TransitionTarget tt = (TransitionTarget)
 90  
                     (((Map.Entry) errCtx).getKey());
 91  0
                 Set vals = (Set) (((Map.Entry) errCtx).getValue());
 92  0
                 msg.append(LogUtils.getTTPath(tt) + " : [");
 93  0
                 for (Iterator i = vals.iterator(); i.hasNext();) {
 94  0
                     TransitionTarget tx = (TransitionTarget) i.next();
 95  0
                     msg.append(LogUtils.getTTPath(tx));
 96  0
                     if (i.hasNext()) {
 97  0
                         msg.append(", ");
 98  
                     }
 99  
                 }
 100  0
                 msg.append(']');
 101  0
             } else if (errCtx instanceof Set) {
 102  0
                 Set vals = (Set) errCtx;
 103  0
                 msg.append("<SCXML> : [");
 104  0
                 for (Iterator i = vals.iterator(); i.hasNext();) {
 105  0
                     TransitionTarget tx = (TransitionTarget) i.next();
 106  0
                     msg.append(LogUtils.getTTPath(tx));
 107  0
                     if (i.hasNext()) {
 108  0
                         msg.append(", ");
 109  
                     }
 110  
                 }
 111  0
                 msg.append(']');
 112  
             }
 113  
         }
 114  0
         if (log.isWarnEnabled()) {
 115  0
             log.warn(msg.toString());
 116  
         }
 117  0
     }
 118  
 
 119  
 }
 120