package j2ee2;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
interface Sell_0{
void sell();
void run();
void seek();
}
class Factory implements Sell_0{
public void sell(){
System.out.println("Factory...sell");
}
public void run(){
System.out.println("Factory...run");
}
public void seek(){
System.out.println("Factory...seek");
}
}
/*
class ProxySeller implements Sell_0{
Factory fac = new Factory();
public void sell(){
System.out.println("p...bengin");
fac.sell();
System.out.println("p...end");
}
}
*/
//中间类
class MyInvocationHandler implements InvocationHandler{
Factory fac = null;
public MyInvocationHandler(Factory obj){
this.fac = obj;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
// TODO Auto-generated method stub
System.out.println("begin...");
method.invoke(fac, args);
System.out.println("end...");
return null;
}
}
public class Sell {
public static void main(String[] args) {
// TODO Auto-generated method stub
Factory fac = new Factory();
InvocationHandler h = new MyInvocationHandler(fac);
Sell_0 s = (Sell_0)Proxy.newProxyInstance(fac.getClass().getClassLoader(), fac.getClass().getInterfaces(), h);
s.run();
s.seek();
s.sell();
}
}