[jboss-user] [Javassist user questions] - Re: adding annotations
cat4hire
do-not-reply at jboss.com
Tue Feb 26 12:02:56 EST 2008
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#4132254
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4132254
More information about the jboss-user
mailing list