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

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

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