Example usage for org.springframework.aop.framework Advised getTargetSource

List of usage examples for org.springframework.aop.framework Advised getTargetSource

Introduction

In this page you can find the example usage for org.springframework.aop.framework Advised getTargetSource.

Prototype

TargetSource getTargetSource();

Source Link

Document

Return the TargetSource used by this Advised object.

Usage

From source file:fr.acxio.tools.agia.SpringTestUtils.java

public static final Object unwrapProxy(Object bean) throws Exception {
    /*//from ww  w  .  j  a v a 2s  .  c  o  m
     * If the given object is a proxy, set the return value as the object
     * being proxied, otherwise return the given object.
     */
    if (AopUtils.isAopProxy(bean) && bean instanceof Advised) {
        Advised advised = (Advised) bean;
        bean = advised.getTargetSource().getTarget();
    }
    return bean;
}

From source file:com.github.tddts.jet.util.SpringUtil.java

/**
 * Checks if given bean is a dynamic proxy and if it is so returns actual bean behind proxy and it's type.
 *
 * @param bean bean object/*from   ww  w .java2 s  .co m*/
 * @return pair containing of bean and it's class
 * @throws BeanInitializationException in case of any exception
 */
public static Pair<Class<?>, Object> checkForDinamicProxy(Object bean) throws BeanInitializationException {
    try {
        Class<?> type = bean.getClass();
        if (AopUtils.isJdkDynamicProxy(bean)) {
            Advised advised = (Advised) bean;
            type = advised.getTargetClass();
            bean = advised.getTargetSource().getTarget();
        }
        return Pair.of(type, bean);
    } catch (Exception e) {
        throw new BeanInitializationException(e.getMessage(), e);
    }
}

From source file:org.nekorp.workflow.desktop.servicio.imp.ProxyUtil.java

/**
 * recupera el objeto proxeado.//from   w  w  w.  ja  v a  2s  . com
 * @param proxy el supuesto proxy
 * @return el objeto proxeado
 */
public Object getTarget(Object proxy) {
    Object obj = proxy;
    if (AopUtils.isAopProxy(proxy)) {
        try {
            Advised advised = (Advised) proxy;
            obj = advised.getTargetSource().getTarget();
        } catch (Exception ex) {
            ProxyUtil.LOGGER.error("No se logro recuperar el proxy", ex);
        }
    }
    return obj;
}

From source file:de.langmi.spring.batch.examples.playground.file.getcurrentresource.GetCurrentResourceChunkListener.java

@Override
public void beforeChunk(ChunkContext cc) {
    if (proxy instanceof Advised) {
        try {/*  www .j  a v  a 2s .c om*/
            Advised advised = (Advised) proxy;
            Object obj = advised.getTargetSource().getTarget();
            MultiResourceItemReader mrirTarget = (MultiResourceItemReader) obj;
            if (mrirTarget != null && mrirTarget.getCurrentResource() != null
                    && !fileNames.contains(mrirTarget.getCurrentResource().getFilename())) {
                String fileName = mrirTarget.getCurrentResource().getFilename();
                fileNames.add(fileName);
                String index = String.valueOf(fileNames.indexOf(fileName));
                stepExecution.getExecutionContext().put("current.resource" + index, fileName);
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}

From source file:org.solmix.runtime.exchange.support.SpringAopClassHelper.java

@Override
protected Object getRealObjectInternal(Object o) {
    if (o instanceof Advised) {
        try {/*from www  .j  a  v  a  2  s  . c o m*/

            Advised advised = (Advised) o;
            Object target = advised.getTargetSource().getTarget();
            //could be a proxy of a proxy.....   
            return getRealObjectInternal(target);
        } catch (Exception ex) {
            // ignore
        }
    }
    return o;
}

From source file:com.esofthead.mycollab.common.interceptor.aspect.TraceableAspect.java

@AfterReturning("execution(public * com.esofthead.mycollab..service..*.saveWithSession(..)) && args(bean, username)")
public void traceSaveActivity(JoinPoint joinPoint, Object bean, String username) {

    Advised advised = (Advised) joinPoint.getThis();
    Class<?> cls = advised.getTargetSource().getTargetClass();

    Traceable traceableAnnotation = cls.getAnnotation(Traceable.class);
    if (traceableAnnotation != null) {
        try {/*from www.  j a  v a  2s  .  com*/
            ActivityStreamWithBLOBs activity = constructActivity(cls, traceableAnnotation, bean, username,
                    ActivityStreamConstants.ACTION_CREATE);
            activityStreamService.save(activity);
        } catch (Exception e) {
            LOG.error("Error when save activity for save action of service " + cls.getName(), e);
        }
    }

}

From source file:com.esofthead.mycollab.common.interceptor.aspect.TraceableCreateAspect.java

@AfterReturning("execution(public * com.esofthead.mycollab..service..*.saveWithSession(..)) && args(bean, username)")
public void traceSaveActivity(JoinPoint joinPoint, Object bean, String username) {
    Advised advised = (Advised) joinPoint.getThis();
    Class<?> cls = advised.getTargetSource().getTargetClass();

    Traceable traceableAnnotation = cls.getAnnotation(Traceable.class);
    if (traceableAnnotation != null) {
        try {/*from  www . java  2 s .c  o  m*/
            ActivityStreamWithBLOBs activity = constructActivity(cls, traceableAnnotation, bean, username,
                    ActivityStreamConstants.ACTION_CREATE);
            activityStreamService.save(activity);
        } catch (Exception e) {
            LOG.error("Error when save activity for save action of service " + cls.getName(), e);
        }
    }
}

From source file:com.esofthead.mycollab.common.interceptor.aspect.TraceableCreateAspect.java

@AfterReturning("execution(public * com.esofthead.mycollab..service..*.removeWithSession(..)) && args(bean, username, sAccountId)")
public void traceDeleteActivity(JoinPoint joinPoint, Object bean, String username, Integer sAccountId) {
    Advised advised = (Advised) joinPoint.getThis();
    Class<?> cls = advised.getTargetSource().getTargetClass();

    Traceable traceableAnnotation = cls.getAnnotation(Traceable.class);
    if (traceableAnnotation != null) {
        try {//ww  w.j a  v a  2 s .  c  o  m
            ActivityStreamWithBLOBs activity = constructActivity(cls, traceableAnnotation, bean, username,
                    ActivityStreamConstants.ACTION_DELETE);
            activityStreamService.save(activity);
        } catch (Exception e) {
            LOG.error("Error when save activity for save action of service " + cls.getName(), e);
        }
    }
}

From source file:com.mycollab.aspect.TraceableCreateAspect.java

@AfterReturning("execution(public * com.mycollab..service..*.saveWithSession(..)) && args(bean, username)")
public void traceSaveActivity(JoinPoint joinPoint, Object bean, String username) {
    Advised advised = (Advised) joinPoint.getThis();
    Class<?> cls = advised.getTargetSource().getTargetClass();

    Traceable traceableAnnotation = cls.getAnnotation(Traceable.class);
    if (traceableAnnotation != null) {
        try {/* www  . ja  va2 s. co m*/
            ActivityStreamWithBLOBs activity = constructActivity(cls, traceableAnnotation, bean, username,
                    ActivityStreamConstants.ACTION_CREATE);
            activityStreamService.save(activity);
        } catch (Exception e) {
            LOG.error("Error when save activity for save action of service " + cls.getName(), e);
        }
    }
}

From source file:com.mycollab.aspect.TraceableCreateAspect.java

@AfterReturning("execution(public * com.mycollab..service..*.removeWithSession(..)) && args(bean, username, sAccountId)")
public void traceDeleteActivity(JoinPoint joinPoint, Object bean, String username, Integer sAccountId) {
    Advised advised = (Advised) joinPoint.getThis();
    Class<?> cls = advised.getTargetSource().getTargetClass();

    Traceable traceableAnnotation = cls.getAnnotation(Traceable.class);
    if (traceableAnnotation != null) {
        try {/*  w  ww  .  j ava 2 s.co m*/
            ActivityStreamWithBLOBs activity = constructActivity(cls, traceableAnnotation, bean, username,
                    ActivityStreamConstants.ACTION_DELETE);
            activityStreamService.save(activity);
        } catch (Exception e) {
            LOG.error("Error when save activity for save action of service " + cls.getName(), e);
        }
    }
}