1 15 package org.apache.hivemind.examples.impl; 16 17 import java.lang.reflect.InvocationHandler ; 18 import java.lang.reflect.InvocationTargetException ; 19 import java.lang.reflect.Method ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.hivemind.service.impl.LoggingUtils; 23 24 32 public class ProxyLoggingInvocationHandler implements InvocationHandler 33 { 34 private Log _log; 35 private Object _delegate; 36 37 public ProxyLoggingInvocationHandler(Log log, Object delegate) 38 { 39 _log = log; 40 _delegate = delegate; 41 } 42 43 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable 44 { 45 boolean debug = _log.isDebugEnabled(); 46 47 if (debug) 48 LoggingUtils.entry(_log, method.getName(), args); 49 50 try 51 { 52 Object result = method.invoke(_delegate, args); 53 54 if (debug) 55 { 56 if (method.getReturnType() == void.class) 57 LoggingUtils.voidExit(_log, method.getName()); 58 else 59 LoggingUtils.exit(_log, method.getName(), result); 60 } 61 62 return result; 63 } 64 catch (InvocationTargetException ex) 65 { 66 Throwable targetException = ex.getTargetException(); 67 68 if (debug) 69 LoggingUtils.exception(_log, method.getName(), targetException); 70 71 throw targetException; 72 } 73 } 74 75 } 76 | Popular Tags |