1 4 package com.tc.common.proxy; 5 6 import com.tc.logging.TCLogger; 7 import com.tc.logging.TCLogging; 8 import com.tc.util.Assert; 9 10 import java.lang.reflect.InvocationTargetException ; 11 import java.lang.reflect.Method ; 12 13 17 class DelegatingInvocationHandler extends GenericInvocationHandler { 18 private static final TCLogger logger = TCLogging.getLogger(GenericInvocationHandler.class); 19 private final Object delegate; 20 21 public DelegatingInvocationHandler(Object delegate, Object handler) { 22 super(handler); 23 Assert.eval(delegate != null); 24 this.delegate = delegate; 25 } 26 27 protected Object handlerMethodNotFound(Object proxy, Method method, Object [] args) throws Throwable { 28 try { 29 Method theMethod = delegate.getClass().getMethod(method.getName(), method.getParameterTypes()); 30 31 try { 32 theMethod.setAccessible(true); 33 } catch (SecurityException se) { 34 logger.warn("Cannot setAccessible(true) for method [" + theMethod + "], " + se.getMessage()); 35 } 36 37 return theMethod.invoke(delegate, args); 38 } catch (InvocationTargetException ite) { 39 throw ite.getCause(); 45 } catch (NoSuchMethodException nsme) { 46 return super.handlerMethodNotFound(proxy, method, args); 47 } 48 } 49 } | Popular Tags |