Hi, I'm new to Javassist. Thanks a lot to the developers of this project!
I'm pretty sure it's not the first time this question is asked, but I did a search and found nothing.
I'm proxying an abstract class. Something like this (I hope I'm not making any mistakes since this is not the exact code I use) :
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(MyAbstractClass.class);
factory.setFilter(new MethodFilter()
{
public boolean isHandled(Method method)
{
return true;
}
}
MyAbstractClass myInstance = (IDictionary<?>) factory.create(new Class<?>[0], new Object[0], new MyHandler());
MyAbstractClass is :
public abstract class MyAbstractClass
{
public String sayHello()
{
return "Hello";
}
public String sayHelloWord()
{
return sayHello() + " World!";
}
}
And MyHandler is Something like :
public class MyHandler implements MethodHandler
{
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
{
System.out.println("In invoke()!");
[ + code to actually call thisMethod on the self object ]
}
}
Now, If I call :
myInstance.sayHelloWord();
The invoke() method will be called first, since I told Javassist to handle all methods. But - and this is my question - when sayHello() is called from sayHelloWord(), it is called directly, without going through invoke() first!
Is there a way to make all methods, even when they are called from within the instance itself, being proxied and going through invoke()?