Coverage Report - org.kuali.spring.proxy.TraceCallback
 
Classes in this File Line Coverage Branch Coverage Complexity
TraceCallback
25%
13/51
9%
2/22
4.75
 
 1  
 package org.kuali.spring.proxy;
 2  
 
 3  
 import java.lang.reflect.Method;
 4  
 import java.lang.reflect.Modifier;
 5  
 
 6  
 import net.sf.cglib.proxy.MethodInterceptor;
 7  
 import net.sf.cglib.proxy.MethodProxy;
 8  
 
 9  
 import org.slf4j.Logger;
 10  
 import org.slf4j.LoggerFactory;
 11  
 
 12  
 /**
 13  
  * 
 14  
  */
 15  1
 public class TraceCallback implements MethodInterceptor {
 16  1
     private static final Logger LOGGER = LoggerFactory.getLogger(TraceCallback.class);
 17  1
     private static final Object MUTEX = new Object();
 18  1
     long counter = 0;
 19  
     private static final int LANGUAGE_MODIFIERS = Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE
 20  
             | Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | Modifier.SYNCHRONIZED | Modifier.NATIVE;
 21  
 
 22  
     @Override
 23  
     public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
 24  3420
         return intercept(new CallbackContext(object, method, args, methodProxy));
 25  
     }
 26  
 
 27  
     public Object intercept(CallbackContext context) throws Throwable {
 28  3420
         long interceptCount = -1;
 29  3420
         synchronized (MUTEX) {
 30  3420
             interceptCount = this.counter++;
 31  3420
         }
 32  3420
         if (LOGGER.isTraceEnabled()) {
 33  0
             LOGGER.trace("Method Invocation Id=" + interceptCount + " Invoking {} parameters={}",
 34  
                     getString(context.getMethod()), context.getArgs());
 35  
         }
 36  3420
         Object result = context.getMethodProxy().invokeSuper(context.getObject(), context.getArgs());
 37  3420
         if (LOGGER.isTraceEnabled()) {
 38  0
             LOGGER.trace("Method Invocation Id={} Result=[{}]", interceptCount, result);
 39  
         }
 40  3420
         return result;
 41  
     }
 42  
 
 43  
     protected String getTypeName(Class<?> type) {
 44  0
         if (type.isArray()) {
 45  
             try {
 46  0
                 Class<?> cl = type;
 47  0
                 int dimensions = 0;
 48  0
                 while (cl.isArray()) {
 49  0
                     dimensions++;
 50  0
                     cl = cl.getComponentType();
 51  
                 }
 52  0
                 StringBuffer sb = new StringBuffer();
 53  0
                 sb.append(cl.getName());
 54  0
                 for (int i = 0; i < dimensions; i++) {
 55  0
                     sb.append("[]");
 56  
                 }
 57  0
                 return sb.toString();
 58  0
             } catch (Throwable e) { /* FALLTHRU */
 59  
             }
 60  
         }
 61  0
         return type.getSimpleName();
 62  
     }
 63  
 
 64  
     protected String getString(Method method) {
 65  
         try {
 66  0
             StringBuffer sb = new StringBuffer();
 67  0
             int mod = method.getModifiers() & LANGUAGE_MODIFIERS;
 68  0
             if (mod != 0) {
 69  0
                 sb.append(Modifier.toString(mod) + " ");
 70  
             }
 71  0
             sb.append(getTypeName(method.getReturnType()) + " ");
 72  0
             sb.append(getTypeName(method.getDeclaringClass()) + ".");
 73  0
             sb.append(method.getName() + "(");
 74  0
             Class<?>[] params = method.getParameterTypes();
 75  0
             for (int j = 0; j < params.length; j++) {
 76  0
                 sb.append(getTypeName(params[j]));
 77  0
                 if (j < (params.length - 1)) {
 78  0
                     sb.append(",");
 79  
                 }
 80  
             }
 81  0
             sb.append(")");
 82  0
             Class<?>[] exceptions = method.getExceptionTypes();
 83  0
             if (exceptions.length > 0) {
 84  0
                 sb.append(" throws ");
 85  0
                 for (int k = 0; k < exceptions.length; k++) {
 86  0
                     sb.append(exceptions[k].getName());
 87  0
                     if (k < (exceptions.length - 1)) {
 88  0
                         sb.append(",");
 89  
                     }
 90  
                 }
 91  
             }
 92  0
             return sb.toString();
 93  0
         } catch (Exception e) {
 94  0
             return "<" + e + ">";
 95  
         }
 96  
     }
 97  
 
 98  
 }