import java.lang.reflect.Method;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
class Myclass {
public void method() {
System.out.println(this.getClass() + "is invoked..");
}
}
class MethodInterceptorImpl implements MethodInterceptor {
@Override
public Object intercept(Object o, Method m, Object[] os, MethodProxy mp)
throws Throwable {
System.out.println(this.getClass() + "is invoked..");
System.out.println(m);
return mp.invokeSuper(o, os);
}
}
public class testmain {
public static void main(String[] args) {
Enhancer en = new Enhancer();
en.setSuperclass(Myclass.class);
en.setCallback(new MethodInterceptorImpl());
Myclass mc = (Myclass) en.create();
mc.method();
}
}
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
class Myclass {
public void method() {
System.out.println(this.getClass() + "is invoked..");
}
}
class MethodInterceptorImpl implements MethodInterceptor {
@Override
public Object intercept(Object o, Method m, Object[] os, MethodProxy mp)
throws Throwable {
System.out.println(this.getClass() + "is invoked..");
System.out.println(m);
return mp.invokeSuper(o, os);
}
}
public class testmain {
public static void main(String[] args) {
Enhancer en = new Enhancer();
en.setSuperclass(Myclass.class);
en.setCallback(new MethodInterceptorImpl());
Myclass mc = (Myclass) en.create();
mc.method();
}
}