private static final String HANDLER_SETTER = "setHandler";
private static final String HANDLER_SETTER_TYPE = "(" + HANDLER_TYPE + ")V";
+ private static final String HANDLER_GETTER = "getHandler";
+ private static final String HANDLER_GETTER_TYPE = "()" + HANDLER_TYPE;
+
/**
* If true, a generated proxy class is cached and it will be reused
* when generating the proxy class with the same properties is requested.
int s = overrideMethods(cf, pool, classname, allMethods);
addMethodsHolder(cf, pool, classname, s);
addSetter(classname, cf, pool);
+ addGetter(classname, cf, pool);
try {
cf.addMethod(makeWriteReplace(pool));
cf.addMethod(minfo);
}
+ private static void addGetter(String classname, ClassFile cf, ConstPool cp)
+ throws CannotCompileException
+ {
+ MethodInfo minfo = new MethodInfo(cp, HANDLER_GETTER,
+ HANDLER_GETTER_TYPE);
+ minfo.setAccessFlags(AccessFlag.PUBLIC);
+ Bytecode code = new Bytecode(cp, 1, 1);
+ code.addAload(0);
+ code.addGetfield(classname, HANDLER, HANDLER_TYPE);
+ code.addOpcode(Bytecode.ARETURN);
+ minfo.setCodeAttribute(code.toCodeAttribute());
+ cf.addMethod(minfo);
+ }
+
private int overrideMethods(ClassFile cf, ConstPool cp, String className,
HashMap allMethods)
throws CannotCompileException
throws java.io.InvalidClassException
{
Class clazz = proxy.getClass();
+
+ MethodHandler methodHandler = null;
+ if (proxy instanceof ProxyObject)
+ methodHandler = ((ProxyObject)proxy).getHandler();
+
+ if (methodHandler == null)
+ methodHandler = ProxyFactory.getHandler(clazz);
+
return new SerializedProxy(clazz, ProxyFactory.getFilter(clazz),
- ProxyFactory.getHandler(clazz));
+ methodHandler);
}
}