Example usage for org.springframework.aop.framework ProxyFactory setProxyTargetClass

List of usage examples for org.springframework.aop.framework ProxyFactory setProxyTargetClass

Introduction

In this page you can find the example usage for org.springframework.aop.framework ProxyFactory setProxyTargetClass.

Prototype

public void setProxyTargetClass(boolean proxyTargetClass) 

Source Link

Document

Set whether to proxy the target class directly, instead of just proxying specific interfaces.

Usage

From source file:org.activiti.spring.components.scope.ProcessScope.java

private Object createDirtyCheckingProxy(final String name, final Object scopedObject) throws Throwable {
    ProxyFactory proxyFactoryBean = new ProxyFactory(scopedObject);
    proxyFactoryBean.setProxyTargetClass(this.proxyTargetClass);
    proxyFactoryBean.addAdvice(new MethodInterceptor() {
        public Object invoke(MethodInvocation methodInvocation) throws Throwable {
            Object result = methodInvocation.proceed();
            persistVariable(name, scopedObject);
            return result;
        }//from ww w. j a va 2 s. com
    });
    return proxyFactoryBean.getProxy(this.classLoader);
}

From source file:org.LexGrid.LexBIG.caCore.client.proxy.DataServiceProxyHelperImpl.java

@Override
protected Object convertObjectToProxy(ApplicationService as, Object obj) {
    if (null == obj)
        return null;

    if (obj instanceof Integer || obj instanceof Float || obj instanceof Double || obj instanceof Character
            || obj instanceof Long || obj instanceof Boolean || obj instanceof String || obj instanceof Date
            || obj instanceof LexEVSBeanProxy || obj instanceof BeanProxy)
        return obj;

    ProxyFactory pf = new ProxyFactory(obj);
    pf.setProxyTargetClass(true);
    pf.addAdvice(new LexEVSBeanProxy(as, this));
    pf.setExposeProxy(true);/*from w w  w  . j a v a  2s.  c om*/
    return pf.getProxy();
}

From source file:org.LexGrid.LexBIG.caCore.client.proxy.LexEVSProxyHelperImpl.java

@Override
protected Object convertObjectToProxy(ApplicationService as, Object obj) {
    if (null == obj)
        return null;

    //Check to see if the returned object is an EVSRemoteExecutionResults.
    //If so, unwrap it and update the proxy target
    if (obj instanceof RemoteExecutionResults) {
        RemoteExecutionResults results = (RemoteExecutionResults) obj;

        //if the returned results are null, return null
        if (results.getReturnValue() == null)
            return null;

        //Get the current proxy target and update it with the retuned value
        //from the server
        Advised advised = (Advised) AopContext.currentProxy();
        advised.setTargetSource(new SingletonTargetSource(results.getObj()));

        obj = results.getReturnValue();/*from  ww  w .j av a2s  . c  o  m*/
    }

    if (obj instanceof RemoteShell) {
        Class<?>[] targetInterfaces = ((RemoteShell) obj).getTargetInterfaces();
        Class<?> targetClass = ((RemoteShell) obj).getTargetClass();
        ProxyFactory pf = new ProxyFactory(targetInterfaces);
        pf.addAdvice(new LexEVSBeanProxy(as, this));
        pf.setProxyTargetClass(true);
        pf.setTargetClass(targetClass);
        pf.setTarget(obj);

        return pf.getProxy();
    }

    if (obj instanceof Integer || obj instanceof Float || obj instanceof Double || obj instanceof Character
            || obj instanceof Long || obj instanceof Boolean || obj instanceof String || obj instanceof Date
            || obj instanceof LexEVSBeanProxy || obj instanceof BeanProxy)
        return obj;

    if (!LexEVSCaCoreUtils.isLexBigClass(obj.getClass())) {
        return obj;
    }

    // Don't proxy client-safe LexBig objects
    if (isClientSafe(obj.getClass())) {
        return obj;
    } else {
        return LexEVSCaCoreUtils.createProxy(obj, as, this);
    }
}

From source file:fr.pilato.spring.elasticsearch.ElasticsearchAbstractClientFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {
    logger.info("Starting ElasticSearch client");

    if (async) {//from  w w w  . jav a 2s  .c  om
        Assert.notNull(taskExecutor);
        Future<Client> future = taskExecutor.submit(new Callable<Client>() {
            @Override
            public Client call() throws Exception {
                return initialize();
            }
        });

        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setProxyTargetClass(true);
        proxyFactory.setTargetClass(Client.class);
        proxyFactory.addAdvice(new GenericInvocationHandler(future));
        proxyfiedClient = (Client) proxyFactory.getProxy();
    } else {
        client = initialize();
    }
}

From source file:org.iff.infra.util.spring.script.ScriptFactoryPostProcessor.java

/**
 * Create a refreshable proxy for the given AOP TargetSource.
 * @param ts the refreshable TargetSource
 * @param interfaces the proxy interfaces (may be {@code null} to
 * indicate proxying of all interfaces implemented by the target class)
 * @return the generated proxy//from  ww w .  j  a  v a 2  s  .  c  om
 * @see RefreshableScriptTargetSource
 */
protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTargetSource(ts);
    ClassLoader classLoader = this.beanClassLoader;

    if (interfaces == null) {
        interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
    }
    proxyFactory.setInterfaces(interfaces);
    if (proxyTargetClass) {
        classLoader = null; // force use of Class.getClassLoader()
        proxyFactory.setProxyTargetClass(proxyTargetClass);
    }

    DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
    introduction.suppressInterface(TargetSource.class);
    proxyFactory.addAdvice(introduction);

    return proxyFactory.getProxy(classLoader);
}

From source file:org.beangle.model.persist.hibernate.internal.ClassUtils.java

/**
 * Based on the given class, properly instructs the ProxyFactory proxies.
 * For additional sanity checks on the passed classes, check the methods
 * below./*from  www  .  j  a va2 s  .c  o m*/
 * 
 * @see #containsUnrelatedClasses(Class[])
 * @see #removeParents(Class[])
 * @param factory
 * @param classes
 */
public static void configureFactoryForClass(ProxyFactory factory, Class<?>[] classes) {
    if (ObjectUtils.isEmpty(classes))
        return;

    for (int i = 0; i < classes.length; i++) {
        Class<?> clazz = classes[i];

        if (clazz.isInterface()) {
            factory.addInterface(clazz);
        } else {
            factory.setTargetClass(clazz);
            factory.setProxyTargetClass(true);
        }
    }
}

From source file:org.lexevs.dao.database.service.error.ErrorCallbackDatabaseServiceFactory.java

/**
 * Gets the error callback database service.
 * /*from ww w.j  a  v  a 2 s. c  om*/
 * @param databaseService the database service
 * @param callback the callback
 * 
 * @return the error callback database service
 */
@SuppressWarnings("unchecked")
public <T> T getErrorCallbackDatabaseService(T databaseService, ErrorCallbackListener callback) {
    ErrorHandlingService serviceAnnotation = AnnotationUtils.findAnnotation(databaseService.getClass(),
            ErrorHandlingService.class);

    if (serviceAnnotation == null) {
        throw new RuntimeException(
                "Class: " + databaseService.getClass().getName() + " is not an Error Handling Service.");
    }

    ProxyFactory pf = new ProxyFactory(databaseService);

    pf.setProxyTargetClass(true);
    ErrorCallbackInterceptor interceptor = new ErrorCallbackInterceptor(callback);

    if (serviceAnnotation.matchAllMethods()) {
        pf.addAdvice(interceptor);
    } else {
        AnnotationMatchingPointcut pointcut = new AnnotationMatchingPointcut(null,
                DatabaseErrorIdentifier.class);
        Advisor advisor = new DefaultPointcutAdvisor(pointcut, interceptor);
        pf.addAdvisor(advisor);

        Class<?>[] annotationClasses = serviceAnnotation.matchAnnotatedMethods();

        if (!ArrayUtils.isEmpty(annotationClasses)) {
            for (Class clazz : annotationClasses) {
                AnnotationMatchingPointcut methodAnnotationPointcuts = new AnnotationMatchingPointcut(
                        ErrorHandlingService.class, clazz);
                pf.addAdvisor(new DefaultPointcutAdvisor(methodAnnotationPointcuts, interceptor));
            }
        }
    }

    Object obj = pf.getProxy();
    return (T) obj;
}

From source file:org.openlegacy.utils.ProxyUtil.java

public static Object createPojoProxy(Class<?> entityClass, Class<?> entityInterface, Interceptor interceptor) {
    Object entity = ReflectionUtil.newInstance(entityClass);
    ProxyFactory proxyFactory = new ProxyFactory(entityInterface, interceptor);

    proxyFactory.setTarget(entity);//  w w w. ja  va 2s. co  m
    proxyFactory.setProxyTargetClass(true);
    Object entityProxy = proxyFactory.getProxy();

    return entityProxy;
}

From source file:org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.java

/**
 * Create an AOP proxy for the given bean.
 * @param beanClass the class of the bean
 * @param beanName the name of the bean/*  ww  w .j  a va 2s .  co m*/
 * @param specificInterceptors the set of interceptors that is
 * specific to this bean (may be empty, but not null)
 * @param targetSource the TargetSource for the proxy,
 * already pre-configured to access the bean
 * @return the AOP proxy for the bean
 * @see #buildAdvisors
 */
protected Object createProxy(Class<?> beanClass, @Nullable String beanName,
        @Nullable Object[] specificInterceptors, TargetSource targetSource) {

    if (this.beanFactory instanceof ConfigurableListableBeanFactory) {
        AutoProxyUtils.exposeTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName,
                beanClass);
    }

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.copyFrom(this);

    if (!proxyFactory.isProxyTargetClass()) {
        if (shouldProxyTargetClass(beanClass, beanName)) {
            proxyFactory.setProxyTargetClass(true);
        } else {
            evaluateProxyInterfaces(beanClass, proxyFactory);
        }
    }

    Advisor[] advisors = buildAdvisors(beanName, specificInterceptors);
    proxyFactory.addAdvisors(advisors);
    proxyFactory.setTargetSource(targetSource);
    customizeProxyFactory(proxyFactory);

    proxyFactory.setFrozen(this.freezeProxy);
    if (advisorsPreFiltered()) {
        proxyFactory.setPreFiltered(true);
    }

    return proxyFactory.getProxy(getProxyClassLoader());
}