All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.dreampie.orm.aspect.AspectFactory Maven / Gradle / Ivy

There is a newer version: 1.3.0.RELEASE
Show newest version
package cn.dreampie.orm.aspect;


import cn.dreampie.common.util.Joiner;
import cn.dreampie.log.Logger;

import java.lang.reflect.Proxy;

/**
 * Created by wangrenhui on 15/1/2.
 * 代理工厂类
 */
public class AspectFactory {

  private static final Logger logger = Logger.getLogger(AspectFactory.class);

  /**
   * 私有构造方法
   */
  private AspectFactory() {
  }

  /**
   * 工厂方法
   *
   * @param target  代理目标对象
   * @param aspects 切面集合
   */
  public static  T newInstance(T target, Aspect... aspects) {
    AspectHandler hander = new AspectHandler(target, aspects);
    Class clazz = target.getClass();
    if (logger.isDebugEnabled()) {
      logger.debug("Instance of " + clazz + ", " + Joiner.on(",").useForNull("null").join(clazz.getInterfaces()));
    }
    return (T) Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), hander);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy