"jcl" wrote:
I have been playing with Javassist in order to modified a class at load
time if it implements a specific interface.
I figured creating my own class loader and catching it in the loadClass
method would work.
I was using the makeReflective(..) call since this is what I need
to do is trap all method calls to this object.
But my problem is that since I called super.loadClass(..)
and then try to a makeRefective(...)
I get a class frozen exception.
Does anyone have any suggestions on how to do this with
Javassist. Maybe there is a hook somewhere else?
Pseudo code:
MyLoader extends reflect.Loader
protected Class loadClass(...)
{
clazz = super.loadClass(..).
if ( clazz has interface xyz )
{
makeReflective(...)
return reflective modified class.
}
else
{
return clazz
}
}
Thanks for any suggestions.
You should define a subclass of javassist.reflect.Reflection,
override onWrite() in that subclass, and modify
javassist.reflect.Loader so that it uses your new class instead
of Reflection.
onWrite() can choose which class must be reflective.