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

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

Introduction

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

Prototype

public static boolean isAopProxy(@Nullable Object object) 

Source Link

Document

Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.

Usage

From source file:flex.contrib.utils.FlexUtils.java

/**
* Checks if the bean has a remoting destination annotation declares either locally or using a proxy bean.
*
* @param bean the bean for which to check if it has a remoting destination annotation declared
* @return true if the bean has a remoting destination annotation declared
*//*  w  w w. j a v a2 s . com*/
public static boolean hasRemotingDestinationAnnotation(Object bean) {
    return (AnnotationUtils.isAnnotationDeclaredLocally(flex.contrib.stereotypes.RemotingDestination.class,
            bean.getClass()))
            || (AopUtils.isAopProxy(bean) && AnnotationUtils.isAnnotationDeclaredLocally(
                    flex.contrib.stereotypes.RemotingDestination.class, AopUtils.getTargetClass(bean)));
}

From source file:flex.contrib.utils.FlexUtils.java

/**
* Gets the remoting destination annotation from the bean.
*
* @param bean the bean for which to return the remoting destination annotation
* @return remoting destination annotation of the bean
*//*from  w ww  .j a va2 s  .  c om*/
public static flex.contrib.stereotypes.RemotingDestination getRemotingDestinationAnnotation(Object bean) {
    flex.contrib.stereotypes.RemotingDestination annotation;
    if (!AopUtils.isAopProxy(bean)) {
        annotation = AnnotationUtils.findAnnotation(bean.getClass(),
                flex.contrib.stereotypes.RemotingDestination.class);
    } else {
        annotation = AnnotationUtils.findAnnotation(AopUtils.getTargetClass(bean),
                flex.contrib.stereotypes.RemotingDestination.class);
    }
    return annotation;
}

From source file:org.springmodules.validation.valang.javascript.taglib.ValangRulesExportInterceptor.java

/**
 * Convert the specified <code>handler</code> to a {@link BaseCommandController} if possible.
 * //ww  w. j  a v a 2s  .com
 * <p>
 * If the <code>handler</code> is type compatible with a <code>BaseCommandController</code> then it will simply be
 * cast.
 * </p>
 * <p>
 * If the <code>handler</code> is a Spring JDK (or CGLIB) proxy, then it will unravelled and returned (assuming the
 * target is a <code>BaseCommandController</code>.
 * </p>
 * If neither of the above strategies work, <code>null</code> will be returned.
 * 
 * @param handler
 *            the handler to convert to a <code>BaseCommandController</code>.
 * @return a <code>BaseCommandController</code> or <code>null</code> if <code>handler</code> cannot be converted.
 * @throws Exception
 */
private BaseCommandController retrieveBaseCommandControllerIfPossible(Object handler) throws Exception {
    BaseCommandController baseCommandController = null;

    if (BaseCommandController.class.isAssignableFrom(handler.getClass())) {
        if (logger.isDebugEnabled()) {
            logger.debug("handler is type compatible, simply cast");
        }
        baseCommandController = (BaseCommandController) handler;
    } else if (AopUtils.isAopProxy(handler)) {
        if (logger.isDebugEnabled()) {
            logger.debug("handler is AOP proxy");
        }

        Advised advisedObject = (Advised) handler;
        Class proxiedClass = advisedObject.getTargetClass();
        Object target = advisedObject.getTargetSource().getTarget();

        // convert (if possible) the target.
        baseCommandController = retrieveBaseCommandControllerIfPossible(target);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Cannot convert handler to BaseCommandController");
    }
    return baseCommandController;
}

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

/**
 * @param message/*  w w  w  . ja va2 s .  c  o 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:com.google.gwt.sample.dynatablemvp.server.loc.ProxyObjectLocator.java

private Object getTarget(Object advisedObject) {
    Object target = advisedObject;
    if (AopUtils.isAopProxy(advisedObject) && advisedObject instanceof Advised) {
        try {//from  www  .  j  a v a  2  s .  com
            target = ((Advised) advisedObject).getTargetSource().getTarget();
        } catch (Exception e) {
            target = null;
        }
    }
    return target;
}

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

/**
 * ?/*from   w ww. j  a  v 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!");
    }
}

From source file:io.dyn.core.EventedBase.java

@SuppressWarnings({ "unchecked" })
@Override// ww w. j  a  v a  2 s .  co  m
public E handler(Object handler) {
    if (null != handler) {
        if (handler instanceof Collection) {
            for (Object o : (Collection) handler) {
                handler(o);
            }
        } else if (handler instanceof Map) {
            for (Map.Entry<String, Object> entry : ((Map<String, Object>) handler).entrySet()) {
                on(entry.getKey(), entry.getValue());
            }
        } else if (handler instanceof Class) {
            try {
                Object o = ((Class<?>) handler).newInstance();
                if (null != beanFactory) {
                    beanFactory.autowireBean(o);
                }
                handler(o);
            } catch (Throwable t) {
                event(Events.classToEventExpression(t.getClass()), t);
            }
        } else {
            Class<?> targetClass;

            if (AopUtils.isAopProxy(handler)) {
                targetClass = AopUtils.getTargetClass(handler);
            } else {
                targetClass = handler.getClass();
            }

            Map<Object, HandlerMethod> handlers = handlerMethodResolver.resolve(targetClass);
            for (Map.Entry<Object, HandlerMethod> entry : handlers.entrySet()) {
                final Object key = entry.getKey();
                final HandlerMethod hm = entry.getValue();
                registerHandlerMethod(key, hm, handler);
            }
        }
    }
    return (E) this;
}

From source file:com.wavemaker.runtime.server.ServerUtils.java

/**
  * Detect proxy class, and find underlying class. <br>
  * An inglorious hack: This simple version works for CGLIB proxy; as used by Springframework.security. No guarantee
  * (or even expectation) that other AOP proxies will be detected. Java (or CGLIB) may have more deterministic ways
  * to find the underlying class./*  w w  w .j a  v  a 2s .c o m*/
  * <p>
  * Used by FileUploadController and FileDownloadController, which to findMethod() on SpringBeans obtained at
  * runtime.
  * 
  * @param sClass the class of an object that may be wrapped by a proxy object.
  * @return the underlying Class of the object that was wrapped
  */
public static Class<?> getRealClass(Object o) {

    Class<?> ret;
    if (AopUtils.isAopProxy(o)) {
        ret = AopUtils.getTargetClass(o);
    } else {
        ret = o.getClass();
    }
    return ret;
}

From source file:com.appleframework.core.utils.ClassUtility.java

public static Class<?> getGenericTypeFromBean(Object object) {
    Class<?> clazz = object.getClass();

    if (AopUtils.isAopProxy(object)) {
        clazz = AopUtils.getTargetClass(object);
    }/*from   ww  w.  java2 s .c om*/
    return getGenericType(clazz);
}