ProxyFactory.java 816 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package cn.noexception.container.aop.framework;

import cn.noexception.container.aop.AdvisedSupport;

/**
 * ProxyFactory<p>
 * - 代理工厂类,用于解决关于选择Cglib 和 JDK 两种代理的问题<p>
 * - 有了代理工厂就可以安札不同的创建需求进行控制
 *
 * @author 吕滔
 * @Date 2021/11/4 16:43
 */
public class ProxyFactory {
    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getProxy() {
        return createAopProxy().getProxy();
    }

    private AopProxy createAopProxy() {
        if (advisedSupport.isProxyTargetClass()) {
            return new Cglib2AopProxy(advisedSupport);
        }
        return new JdkDynamicAopProxy(advisedSupport);
    }
}