Example usage for org.springframework.aop.support AopUtils isCglibProxy

List of usage examples for org.springframework.aop.support AopUtils isCglibProxy

Introduction

In this page you can find the example usage for org.springframework.aop.support AopUtils isCglibProxy.

Prototype

public static boolean isCglibProxy(@Nullable Object object) 

Source Link

Document

Check whether the given object is a CGLIB proxy.

Usage

From source file:cn.guoyukun.spring.utils.AopProxyUtils.java

/**
 * ??/*from www  .  j  av a  2 s . c  o m*/
 * see http://jinnianshilongnian.iteye.com/blog/1894465
 * @param proxy
 * @return
 */
public static boolean isMultipleProxy(Object proxy) {
    try {
        ProxyFactory proxyFactory = null;
        if (AopUtils.isJdkDynamicProxy(proxy)) {
            proxyFactory = findJdkDynamicProxyFactory(proxy);
        }
        if (AopUtils.isCglibProxy(proxy)) {
            proxyFactory = findCglibProxyFactory(proxy);
        }
        TargetSource targetSource = (TargetSource) ReflectionUtils.getField(ProxyFactory_targetSource_FIELD,
                proxyFactory);
        return AopUtils.isAopProxy(targetSource.getTarget());
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "proxy args maybe not proxy with cglib or jdk dynamic proxy. this method not support", e);
    }
}

From source file:cn.guoyukun.spring.utils.AopProxyUtils.java

private static void removeAdvisor(Object proxy, Class<? extends Advice> adviceClass) {
    if (!AopUtils.isAopProxy(proxy)) {
        return;//from w  w  w.jav  a 2 s  .co  m
    }
    ProxyFactory proxyFactory = null;
    if (AopUtils.isJdkDynamicProxy(proxy)) {
        proxyFactory = findJdkDynamicProxyFactory(proxy);
    }
    if (AopUtils.isCglibProxy(proxy)) {
        proxyFactory = findCglibProxyFactory(proxy);
    }

    Advisor[] advisors = proxyFactory.getAdvisors();

    if (advisors == null || advisors.length == 0) {
        return;
    }

    for (Advisor advisor : advisors) {
        if (adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
            proxyFactory.removeAdvisor(advisor);
            break;
        }
    }
}

From source file:cn.guoyukun.spring.utils.AopProxyUtils.java

private static boolean hasAdvice(Object proxy, Class<? extends Advice> adviceClass) {
    if (!AopUtils.isAopProxy(proxy)) {
        return false;
    }//from  ww w  .  j  a va2 s  .  c  o m
    ProxyFactory proxyFactory = null;
    if (AopUtils.isJdkDynamicProxy(proxy)) {
        proxyFactory = findJdkDynamicProxyFactory(proxy);
    }
    if (AopUtils.isCglibProxy(proxy)) {
        proxyFactory = findCglibProxyFactory(proxy);
    }

    Advisor[] advisors = proxyFactory.getAdvisors();

    if (advisors == null || advisors.length == 0) {
        return false;
    }

    for (Advisor advisor : advisors) {
        if (adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
            return true;
        }
    }
    return false;
}

From source file:com.github.blazeds.replicator.HibernateAdapter.java

/**
 * @param message//w w  w. j  ava 2s .  co m
 * @return
 */
private Method getMethod(Message message) {

    // Have to create instance to get class
    RemotingDestination remotingDestination = (RemotingDestination) getDestination();
    FactoryInstance factoryInstance = remotingDestination.getFactoryInstance();
    Object instance = createInstance(factoryInstance.getInstanceClass());

    // Class may be wrapped in proxy
    Class<?> targetClass;
    if (aopPresent && AopUtils.isAopProxy(instance) || AopUtils.isCglibProxy(instance)) {
        targetClass = AopUtils.getTargetClass(instance);
    } else {
        targetClass = instance.getClass();
    }

    // Get method to be invoked
    String operation = ((RemotingMessage) message).getOperation();
    @SuppressWarnings("rawtypes")
    List parameters = ((RemotingMessage) message).getParameters();
    Method method = remotingDestination.getMethodMatcher().getMethod(targetClass, operation, parameters);

    return method;
}

From source file:net.bubble.common.utils.BeanContextUtil.java

/**
 * ?/* w  ww . j av a 2 s  .  c  om*/
 * @param proxy ?
 * @return Object 
 * @throws CommonException ??
 */
public Object getTargetObject(Object proxy) throws CommonException {
    try {
        if (!AopUtils.isAopProxy(proxy)) {// ??
            return proxy;
        }
        if (AopUtils.isCglibProxy(proxy)) {// cglib?
            return getCglibProxyTargetObject(proxy);
        }
        if (AopUtils.isJdkDynamicProxy(proxy)) {// jdk??
            return getJdkDynamicProxyTargetObject(proxy);
        }
        //null
        return null;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new CommonException("Get target Object has error!");
    }
}