导航

2013-Proxy代理的使用

Posted on 2014-01-21 11:15  酷鱼影子  阅读(129)  评论(0编辑  收藏  举报
package itour.cn.fare.gateway;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;

public class ObeQueryProxy implements InvocationHandler{
    private Object target;
    
    public Object bind(Object target) {
        this.target = target;
        //取得代理对象
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(), this);  
    }

    @Override
    /**
     * 调用方法
     */
    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
    
            result=method.invoke(target, args);

        }
        return result;
    }


}