[jboss-user] [Javassist user questions] - Role injection for agents

2008-10-02 Thread cat4hire
Hi all, in the case you are interested in a prototype for dynamic role injection into java agents: http://fluca1978.blogspot.com/2008/10/whitecat-injecting-roles-into-java.html The work has been done, of course, using the Javassist library and is based on my previous experience in agents and rol

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-04-01 Thread cat4hire
After a lot I found that the following is the code that works for me: | ClassFile classFile = newProxyClass.getClassFile(); | ConstPool constantPool = classFile.getConstPool(); | AnnotationsAttribute attr = new AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag)

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-03-12 Thread cat4hire
Hi, I'm still fighting with the annotation problem. I've made a code clean up, and now I've got the following piece of code: | // make a new class | CtClass newProxyClass = pool.makeClass( subProxyClassName ); | newProxyClass.setSuperclass(

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-03-05 Thread cat4hire
I'm going mad, anyone with a suggestion? I've found that the following piece of code: | ByteArrayOutputStream aos = new ByteArrayOutputStream(); | AnnotationsWriter aw = new AnnotationsWriter(aos, constantPool); | aw.numAnnotations(1); |

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-02-29 Thread cat4hire
I've made another experiment: using an AnnotationsWriter as follows does not work too: | | ByteArrayOutputStream aos = new ByteArrayOutputStream(); | AnnotationsWriter aw = new AnnotationsWriter(aos, constantPool); | aw.nu

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-02-29 Thread cat4hire
I've found how to make the ClassFile working for defining my new class, but I'm still unable to add the annotation. Now I work as follows: 1) I create a CtClass object and set the inheritance chain on that; 2) I get the byte[] from the CtClass and place them into a ByteArrayInputStream, used to c

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-02-26 Thread cat4hire
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); | Cla

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-02-25 Thread cat4hire
I've tried to define the class within the class loader, introspecting it in place to see what happens. In other words, I added the following code: | subProxyClassName += this.getSubClassNameSuffix(); | | // make a new class and prepare the

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-02-25 Thread cat4hire
This is what I've tried to do in my class loader: | subProxyClassName += this.getSubClassNameSuffix(); | | // make a new class and prepare the annotation | ClassFile classFile = new ClassFile( false, subProxyClassName, base

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-02-21 Thread cat4hire
Just to make it more clear: I've got a special class loader that is going to subclass a class that it must load to add specific behaviours, one of such behaviour should be an annotation. That is why I'm searching to do them thru Javassist. Any suggestion? View the original post : http://www.jb

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-02-21 Thread cat4hire
I'm not sure about the use of an agent, because it will perform the annotation addition at the program load time, while I have to perform it depending on run-time conditions at class loading time, and most important I could have separate class loaders that add or not the annotations to the class

[jboss-user] [Javassist user questions] - Re: adding annotations

2008-02-20 Thread cat4hire
Hi, thanks for your reply, I was having a look at annotation_attribute, annotationwriter and annotationattribute, and now I've got a doubt: is the annotation only stored in the class file? Because what I'd like to obtain is to "inject" an annotation into a class (Runtime retention) when the clas

[jboss-user] [Javassist user questions] - adding annotations

2008-02-19 Thread cat4hire
Hi, can anybody point me to a simple example of how to add an annotation to a class thru javassist? Thanks, Luca View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4130370#4130370 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=repl

[jboss-user] [Javassist user questions] - Re: error reloading a class

2008-02-10 Thread cat4hire
Just to make it clearer: * the interface I'm going to apply will remain the same during the whole program, and so I guess it can be loaded by a parent (even root) loader; * the class to which the interface will be applied can change during the program execution, and so should be loaded by a custo

[jboss-user] [Javassist user questions] - error reloading a class

2008-02-10 Thread cat4hire
Hi all, I'm writing a custom class loader that exploits Javassist to manipulate classes on the fly. This is what I'd like to do: 1) start with a clear class (not manipulated) loaded from the root custom classloader 2) manipulate the class inserting an interface on it, load the class with a custo

[jboss-user] [Javassist user questions] - Re: JA seems inactive, is it?

2008-02-10 Thread cat4hire
Well, I guess Javassist is still active, since on Janauary 2008 it has been released the 3.6 release, but the JBoss page seems not up to date. View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4128160#4128160 Reply to the post : http://www.jboss.com/index.html?m

[jboss-user] [Javassist user questions] - Re: Duplicate a method

2008-02-10 Thread cat4hire
You are not trying to duplicate, rather to overload the method. I usually do this: 1) create a StringBuffer where I place the java source code for the new method; 2) use CtNewMethod.make() to obtain a new CtMethod for the source code; 3) add the method to the CtClass. View the original post : ht

[jboss-user] [Javassist user questions] - Re: How to use an new method argument?

2008-02-10 Thread cat4hire
You can refer to method arguments using the special $n variables, for instance if your argument is the third, than in the method code you can refer to it as $3. Similarly, $$ is substituted to the full list of arguments. View the original post : http://www.jboss.com/index.html?module=bb&op=view

[jboss-user] [Javassist user questions] - know who has the monitor on an object

2008-01-16 Thread cat4hire
Hi, is it possible using Javassist to understand if a specified instance has a monitor active? I know this is not a problem of reflection, but given an instance CI of class C, if I need to load a modified version of class C to produce CI2 that substitutes CI I should bother with any possible thr