1 22 23 package org.jboss.test.javassist.test.support; 24 25 import java.lang.reflect.Method ; 26 import java.lang.reflect.InvocationTargetException ; 27 28 import javassist.util.proxy.MethodHandler; 29 import javassist.util.proxy.RuntimeSupport; 30 31 35 public class ThingMethodHandler implements MethodHandler 36 { 37 private IThing theThing; 38 public ThingMethodHandler(IThing theThing) 39 { 40 this.theThing = theThing; 41 } 42 43 public Object invoke(Object self, Method thisMethod, Method proceed, Object [] args) 44 throws Exception 45 { 46 Object result = null; 47 try 48 { 49 if( theThing.getClass() == thisMethod.getDeclaringClass() ) 50 result = thisMethod.invoke(theThing, args); 51 else 52 { 53 String desc = RuntimeSupport.makeDescriptor(thisMethod); 54 Method m = RuntimeSupport.findMethod(theThing, thisMethod.getName(), desc); 55 result = m.invoke(theThing, args); 56 } 57 } 58 catch (InvocationTargetException e) 59 { 60 Throwable t = e.getTargetException(); 61 if( t instanceof Exception ) 62 throw (Exception ) t; 63 else if( t instanceof Error ) 64 throw (Error ) t; 65 throw e; 67 } 68 69 return result; 70 } 71 } 72 | Popular Tags |