String className=createClassName(extendz,interfaces);
//Mapping mapping = cfc.getPageSource().getMapping();
// get ClassLoader
PhysicalClassLoader cl=null;
try {
cl = (PhysicalClassLoader) pci.getRPCClassLoader(false);// mapping.getConfig().getRPCClassLoader(false)
} catch (IOException e) {
throw Caster.toPageException(e);
}
Resource classFile = cl.getDirectory().getRealResource(className.concat(".class"));
// check if already exists, if yes return
if(classFile.exists()) {
//Object obj=newInstance(cl,className,cfc);
// if(obj!=null) return obj;
}
/*
String classNameOriginal=component.getPageSource().getFullClassName();
String realOriginal=classNameOriginal.replace('.','/');
Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));
*/
ClassWriter cw = ASMUtil.getClassWriter();
cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, className, null, typeExtends.getInternalName(), strInterfaces);
//BytecodeContext statConstr = null;//new BytecodeContext(null,null,null,cw,real,ga,Page.STATIC_CONSTRUCTOR);
//BytecodeContext constr = null;//new BytecodeContext(null,null,null,cw,real,ga,Page.CONSTRUCTOR);
// field Component
FieldVisitor _fv = cw.visitField(Opcodes.ACC_PRIVATE, "cfc", COMPONENT_NAME, null, null);
_fv.visitEnd();
_fv = cw.visitField(Opcodes.ACC_PRIVATE, "config", CONFIG_WEB_NAME, null, null);
_fv.visitEnd();
// Constructor
GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC,CONSTRUCTOR,null,null,cw);
Label begin = new Label();
adapter.visitLabel(begin);
adapter.loadThis();
adapter.invokeConstructor(Types.OBJECT, SUPER_CONSTRUCTOR);
//adapter.putField(JAVA_PROXY, arg1, arg2)
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.visitVarInsn(Opcodes.ALOAD, 1);
adapter.visitFieldInsn(Opcodes.PUTFIELD, className, "config", CONFIG_WEB_NAME);
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.visitVarInsn(Opcodes.ALOAD, 2);
adapter.visitFieldInsn(Opcodes.PUTFIELD, className, "cfc", COMPONENT_NAME);
adapter.visitInsn(Opcodes.RETURN);
Label end = new Label();
adapter.visitLabel(end);
adapter.visitLocalVariable("config",CONFIG_WEB_NAME, null, begin, end, 1);
adapter.visitLocalVariable("cfc",COMPONENT_NAME, null, begin, end, 2);
//adapter.returnValue();
adapter.endMethod();
// create methods
Set<Class> cDone=new HashSet<Class>();
Map<String,Class> mDone=new HashMap<String,Class>();
for(int i=0;i<interfaces.length;i++){
_createProxy(cw,cDone,mDone, cfc, interfaces[i],className);
}
cw.visitEnd();
// create class file
byte[] barr = cw.toByteArray();
try {
ResourceUtil.touch(classFile);
IOUtil.copy(new ByteArrayInputStream(barr), classFile,true);
cl = (PhysicalClassLoader) pci.getRPCClassLoader(true);
Class<?> clazz = cl.loadClass(className, barr);
return newInstance(clazz, pc.getConfig(),cfc);
}
catch(Throwable t) {
throw Caster.toPageException(t);
}