Clover coverage report - Code Coverage for hivemind release 1.0-beta-2
Coverage timestamp: Sun Aug 1 2004 14:03:45 EDT
file stats: LOC: 145   Methods: 7
NCLOC: 84   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AbstractLoggingInterceptor.java 92.9% 100% 100% 98.6%
coverage coverage
 1   
 //  Copyright 2004 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.service.impl;
 16   
 
 17   
 import org.apache.commons.logging.Log;
 18   
 import org.apache.hivemind.service.ClassFabUtils;
 19   
 
 20   
 /**
 21   
  * Base class used to dynamically build logging interceptors.
 22   
  * {@link org.apache.hivemind.service.impl.LoggingInterceptorFactory}
 23   
  * will create a subclass dynamically.
 24   
  *
 25   
  * @author Howard Lewis Ship
 26   
  */
 27   
 public abstract class AbstractLoggingInterceptor
 28   
 {
 29   
     private static final int BUFFER_SIZE = 100;
 30   
 
 31   
     private Log _log;
 32   
 
 33  10
     protected AbstractLoggingInterceptor(Log log)
 34   
     {
 35  10
         _log = log;
 36   
     }
 37   
 
 38  20
     protected void _logEntry(String methodName, Object[] args)
 39   
     {
 40  20
         StringBuffer buffer = new StringBuffer(BUFFER_SIZE);
 41   
 
 42  20
         buffer.append("BEGIN ");
 43  20
         buffer.append(methodName);
 44  20
         buffer.append("(");
 45   
 
 46  20
         int count = (args == null) ? 0 : args.length;
 47   
 
 48  20
         for (int i = 0; i < count; i++)
 49   
         {
 50  7
             Object arg = args[i];
 51   
 
 52  7
             if (i > 0)
 53  2
                 buffer.append(", ");
 54   
 
 55  7
             convert(buffer, arg);
 56   
         }
 57   
 
 58  20
         buffer.append(")");
 59   
 
 60  20
         _log.debug(buffer.toString());
 61   
     }
 62   
 
 63  21
     private void convert(StringBuffer buffer, Object input)
 64   
     {
 65  21
         if (input == null)
 66   
         {
 67  4
             buffer.append("<null>");
 68  4
             return;
 69   
         }
 70   
 
 71   
         // Primitive types, and non-object arrays
 72   
         // use toString().  Less than ideal for int[], etc., but
 73   
         // that's a lot of work for a rare case.
 74   
 
 75  17
         if (!(input instanceof Object[]))
 76   
         {
 77  16
             buffer.append(input.toString());
 78  16
             return;
 79   
         }
 80   
 
 81  1
         buffer.append("(");
 82  1
         buffer.append(ClassFabUtils.getJavaClassName(input.getClass()));
 83  1
         buffer.append("){");
 84   
 
 85  1
         Object[] array = (Object[]) input;
 86  1
         int count = array.length;
 87   
 
 88  1
         for (int i = 0; i < count; i++)
 89   
         {
 90  2
             if (i > 0)
 91  1
                 buffer.append(", ");
 92   
 
 93   
             // We use convert() again, because it could be a multi-dimensional array
 94   
             // (god help us) where each element must be converted.
 95  2
             convert(buffer, array[i]);
 96   
         }
 97   
 
 98  1
         buffer.append("}");
 99   
     }
 100   
 
 101  12
     protected void _logExit(String methodName, Object result)
 102   
     {
 103  12
         StringBuffer buffer = new StringBuffer(BUFFER_SIZE);
 104   
 
 105  12
         buffer.append("END ");
 106  12
         buffer.append(methodName);
 107  12
         buffer.append("() [");
 108   
 
 109  12
         convert(buffer, result);
 110   
 
 111  12
         buffer.append("]");
 112   
 
 113  12
         _log.debug(buffer.toString());
 114   
     }
 115   
 
 116  5
     protected void _logVoidExit(String methodName)
 117   
     {
 118  5
         StringBuffer buffer = new StringBuffer(BUFFER_SIZE);
 119   
 
 120  5
         buffer.append("END ");
 121  5
         buffer.append(methodName);
 122  5
         buffer.append("()");
 123   
 
 124  5
         _log.debug(buffer.toString());
 125   
     }
 126   
 
 127  1
     protected void _logException(String methodName, Throwable t)
 128   
     {
 129  1
         StringBuffer buffer = new StringBuffer(BUFFER_SIZE);
 130   
 
 131  1
         buffer.append("EXCEPTION ");
 132  1
         buffer.append(methodName);
 133  1
         buffer.append("() -- ");
 134   
 
 135  1
         buffer.append(t.getClass().getName());
 136   
 
 137  1
         _log.debug(buffer.toString(), t);
 138   
     }
 139   
 
 140  21
     protected boolean _isDebugEnabled()
 141   
     {
 142  21
         return _log.isDebugEnabled();
 143   
     }
 144   
 
 145   
 }