[url]http://hi.baidu.com/huahua035/blog/item/6e5bff135b8412c2c3fd78b5.html[/url]
[color=red]jdk動態代理 例子[/color]
[url]http://www.blogjava.net/DoubleJ/archive/2008/03/04/183796.html[/url]
[color=red]cglib代理例子[/color]
[url]http://carterslam.iteye.com/blog/541009[/url]
[color=red]cglib代理原理解釋及例子[/color]
[url]http://hnicypb.iteye.com/blog/263841[/url]
[color=red]cglib api文檔[/color]
[url]http://cglib.sourceforge.net/apidocs/net/sf/cglib/proxy/MethodProxy.html[/url]
[color=red]asm框架了解[/color]
[url]http://www.ibm.com/developerworks/cn/java/j-lo-asm30/index.html[/url]
[color=red]jdk動態代理例子[/color]
package cun.InvocationHandler;
public class Hello implements IHello{
public void sayHello() {
System.out.println("Hello , sytcun!");
}
}
package cun.InvocationHandler;
public interface IHello {
public void sayHello();
}
public class InvoHelloMain implements InvocationHandler{
private Object obj;
public InvoHelloMain(Object obj) {
this.obj = obj;
}
public static void main(String args[]) {
IHello hello = new Hello();
IHello ihello = (IHello) InvoHelloMain.newInstance(hello);
ihello.sayHello();
}
@SuppressWarnings("finally")
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Object result = null;
try{
System.out.println("before hello, hello execute");
result = method.invoke(proxy, args);
return result;
}catch(Exception ex) {
ex.printStackTrace();
} finally {
System.out.println("execute method" + method.getName());
return result;
}
}
public static Object newInstance(Object obj)
{
return java.lang.reflect.Proxy.newProxyInstance(obj.getClass().getClassLoader(),
obj.getClass().getInterfaces(), new InvoHelloMain(obj));
}
}