Clover coverage report - Code Coverage for hivemind release 1.1-alpha-1
Coverage timestamp: Tue Jan 18 2005 07:55:08 EST
file stats: LOC: 131   Methods: 5
NCLOC: 75   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
LoggingUtils.java 92.9% 100% 100% 98.5%
coverage coverage
 1   
 // Copyright 2004, 2005 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   
  * Collection of static methods used by loggers to
 22   
  * log method entry and exit.
 23   
  *
 24   
  * @author Howard Lewis Ship
 25   
  */
 26   
 public class LoggingUtils
 27   
 {
 28   
     private static final int BUFFER_SIZE = 100;
 29   
 
 30  19
     public static void entry(Log log, String methodName, Object[] args)
 31   
     {
 32  19
         StringBuffer buffer = new StringBuffer(BUFFER_SIZE);
 33   
 
 34  19
         buffer.append("BEGIN ");
 35  19
         buffer.append(methodName);
 36  19
         buffer.append("(");
 37   
 
 38  19
         int count = (args == null) ? 0 : args.length;
 39   
 
 40  19
         for (int i = 0; i < count; i++)
 41   
         {
 42  7
             Object arg = args[i];
 43   
 
 44  7
             if (i > 0)
 45  2
                 buffer.append(", ");
 46   
 
 47  7
             convert(buffer, arg);
 48   
         }
 49   
 
 50  19
         buffer.append(")");
 51   
 
 52  19
         log.debug(buffer.toString());
 53   
     }
 54   
 
 55  12
     public static void exit(Log log, String methodName, Object result)
 56   
     {
 57  12
         StringBuffer buffer = new StringBuffer(BUFFER_SIZE);
 58   
 
 59  12
         buffer.append("END ");
 60  12
         buffer.append(methodName);
 61  12
         buffer.append("() [");
 62   
 
 63  12
         convert(buffer, result);
 64   
 
 65  12
         buffer.append("]");
 66   
 
 67  12
         log.debug(buffer.toString());
 68   
     }
 69   
 
 70  6
     public static void voidExit(Log log, String methodName)
 71   
     {
 72  6
         StringBuffer buffer = new StringBuffer(BUFFER_SIZE);
 73   
 
 74  6
         buffer.append("END ");
 75  6
         buffer.append(methodName);
 76  6
         buffer.append("()");
 77   
 
 78  6
         log.debug(buffer.toString());
 79   
     }
 80   
 
 81  2
     public static void exception(Log log, String methodName, Throwable t)
 82   
     {
 83  2
         StringBuffer buffer = new StringBuffer(BUFFER_SIZE);
 84   
 
 85  2
         buffer.append("EXCEPTION ");
 86  2
         buffer.append(methodName);
 87  2
         buffer.append("() -- ");
 88   
 
 89  2
         buffer.append(t.getClass().getName());
 90   
 
 91  2
         log.debug(buffer.toString(), t);
 92   
     }
 93   
 
 94  21
     public static void convert(StringBuffer buffer, Object input)
 95   
     {
 96  21
         if (input == null)
 97   
         {
 98  4
             buffer.append("<null>");
 99  4
             return;
 100   
         }
 101   
 
 102   
         // Primitive types, and non-object arrays
 103   
         // use toString().  Less than ideal for int[], etc., but
 104   
         // that's a lot of work for a rare case.
 105   
 
 106  17
         if (!(input instanceof Object[]))
 107   
         {
 108  16
             buffer.append(input.toString());
 109  16
             return;
 110   
         }
 111   
 
 112  1
         buffer.append("(");
 113  1
         buffer.append(ClassFabUtils.getJavaClassName(input.getClass()));
 114  1
         buffer.append("){");
 115   
 
 116  1
         Object[] array = (Object[]) input;
 117  1
         int count = array.length;
 118   
 
 119  1
         for (int i = 0; i < count; i++)
 120   
         {
 121  2
             if (i > 0)
 122  1
                 buffer.append(", ");
 123   
 
 124   
             // We use convert() again, because it could be a multi-dimensional array
 125   
             // (god help us) where each element must be converted.
 126  2
             convert(buffer, array[i]);
 127   
         }
 128   
 
 129  1
         buffer.append("}");
 130   
     }
 131   
 }