private byte[] generateProxy(ClassLoader classLoader, Class<?> classToProxy, String proxyClassName, String proxyClassFileName,
Method[] interceptedMethods, Method[] nonInterceptedMethods)
throws ProxyGenerationException
{
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
String classFileName = classToProxy.getName().replace('.', '/');
String[] interfaceNames = new String[]{Type.getInternalName(getMarkerInterface())};
String superClassName = classFileName;
if (classToProxy.isInterface())
{
interfaceNames = new String[]{Type.getInternalName(classToProxy), interfaceNames[0]};
superClassName = Type.getInternalName(Object.class);
}
cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, proxyClassFileName, null, superClassName, interfaceNames);
cw.visitSource(classFileName + ".java", null);
createInstanceVariables(cw, classToProxy, classFileName);
createSerialisation(cw, proxyClassFileName, classToProxy, classFileName);
// create a static String Field which contains the passivationId of the Bean or null if not PassivationCapable
cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
FIELD_BEAN_PASSIVATION_ID, Type.getDescriptor(String.class), null, null).visitEnd();
createConstructor(cw, proxyClassFileName, classToProxy, classFileName);
if (nonInterceptedMethods != null)
{
delegateNonInterceptedMethods(classLoader, cw, proxyClassFileName, classToProxy, nonInterceptedMethods);
}
if (interceptedMethods != null)
{
delegateInterceptedMethods(classLoader, cw, proxyClassFileName, classToProxy, interceptedMethods);
}
return cw.toByteArray();
}