From 99ab9359c46e0d21ac5e4055fca235f064c64934 Mon Sep 17 00:00:00 2001 From: chiba Date: Tue, 14 Feb 2006 04:27:38 +0000 Subject: [PATCH] Adjusted the behavior of setHandler(). git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@244 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- .../javassist/util/proxy/ProxyFactory.java | 19 ++++++++++--------- .../javassist/util/proxy/RuntimeSupport.java | 12 ++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java index 55caa07c..89cb98cd 100644 --- a/src/main/javassist/util/proxy/ProxyFactory.java +++ b/src/main/javassist/util/proxy/ProxyFactory.java @@ -114,6 +114,7 @@ public class ProxyFactory { private static final String HOLDER = "_methods_"; private static final String HOLDER_TYPE = "[Ljava/lang/reflect/Method;"; private static final String HANDLER = "handler"; + private static final String NULL_INTERCEPTOR_HOLDER = "javassist.util.proxy.RuntimeSupport"; private static final String DEFAULT_INTERCEPTOR = "default_interceptor"; private static final String HANDLER_TYPE = 'L' + MethodHandler.class.getName().replace('.', '/') + ';'; @@ -127,14 +128,7 @@ public class ProxyFactory { superClass = null; interfaces = null; methodFilter = null; - handler = new MethodHandler() { - public Object invoke(Object self, Method m, - Method proceed, Object[] args) - throws Exception - { - return proceed.invoke(self, args); - } - }; + handler = null; thisClass = null; writeDirectory = null; } @@ -460,14 +454,21 @@ public class ProxyFactory { minfo.setAccessFlags(Modifier.PUBLIC); // cons.getModifiers() & ~Modifier.NATIVE setThrows(minfo, cp, cons.getExceptionTypes()); Bytecode code = new Bytecode(cp, 0, 0); + code.addAload(0); code.addGetstatic(thisClassName, DEFAULT_INTERCEPTOR, HANDLER_TYPE); + code.addOpcode(Opcode.DUP); + code.addOpcode(Opcode.IFNONNULL); + code.addIndex(7); + code.addOpcode(Opcode.POP); + code.addGetstatic(NULL_INTERCEPTOR_HOLDER, DEFAULT_INTERCEPTOR, HANDLER_TYPE); code.addPutfield(thisClassName, HANDLER, HANDLER_TYPE); + code.addAload(0); int s = addLoadParameters(code, cons.getParameterTypes(), 1); code.addInvokespecial(superClass.getName(), "", desc); code.addOpcode(Opcode.RETURN); - code.setMaxLocals(++s); + code.setMaxLocals(s + 1); minfo.setCodeAttribute(code.toCodeAttribute()); return minfo; } diff --git a/src/main/javassist/util/proxy/RuntimeSupport.java b/src/main/javassist/util/proxy/RuntimeSupport.java index 3e469699..db96bcfb 100644 --- a/src/main/javassist/util/proxy/RuntimeSupport.java +++ b/src/main/javassist/util/proxy/RuntimeSupport.java @@ -23,6 +23,18 @@ import java.lang.reflect.Method; * @see ProxyFactory */ public class RuntimeSupport { + /** + * A method handler that only executes a method. + */ + public static MethodHandler default_interceptor = new MethodHandler() { + public Object invoke(Object self, Method m, + Method proceed, Object[] args) + throws Exception + { + return proceed.invoke(self, args); + } + }; + /** * Finds a method with the given name and descriptor. * It searches only the class of self. -- 2.39.5