I've made another try: I've tried to get the classfile from a CtClass object
instantied with the class name of the base class:
| // make a new class and prepare the annotation
| CtClass newProxyClass = pool.makeClass(subProxyClassName);
| ClassFile classFile = newProxyClass.getClassFile(); //new ClassFile( false,
subProxyClassName, baseProxyClass.getName() );
| ConstPool constantPool = classFile.getConstPool();
| AnnotationsAttribute attribute = new AnnotationsAttribute( constantPool,
AnnotationsAttribute.visibleTag );
| javassist.bytecode.annotation.Annotation annotation = new
javassist.bytecode.annotation.Annotation( this.annotationClassName, constantPool );
| attribute.setAnnotation( annotation );
| classFile.addAttribute( attribute );
| classFile.setVersionToJava5();
| classFile.setName(subProxyClassName);
| classFile.setSuperclass( baseProxyClass.getName() );
| ByteArrayOutputStream bos = new ByteArrayOutputStream();
| DataOutputStream os = new DataOutputStream( bos );
| classFile.write( os );
| bytecode = bos.toByteArray();
|
but again, when I try to instantiate this class, that is of kind "proxy", I got
an instantiation error:
| Class clazz = this.defineClass(subProxyClassName, bytecode, 0, bytecode.length);
| AgentProxy aProxy = (AgentProxy) clazz.newInstance();
|
I got the same instantiation exception of the previous post.
Any idea?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4132254#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...