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

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

Introduction

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

Prototype

public ProxyFactory() 

Source Link

Document

Create a new ProxyFactory.

Usage

From source file:net.bioclipse.recording.WrapInProxyAdvice.java

public Object invoke(MethodInvocation invocation) throws Throwable {
    Object returnValue = invocation.proceed();
    if (returnValue instanceof IBioObject && !(returnValue instanceof net.sf.cglib.proxy.Factory)) {
        ProxyFactory pf = new ProxyFactory();
        pf.addAdvice(this);
        //            pf.addAdvice(Activator.getDefault().getRecordingAdvice());
        pf.setTarget(returnValue);// www .  j  a  v  a  2s. co  m
        returnValue = pf.getProxy();
    }
    return returnValue;
}

From source file:com.organization.automation.project.spice.mix.aop.spring.TCProxy.java

public ITestCase transform(ITestCase tc) {
    // initialization
    factory = new ProxyFactory();
    Class<?>[] interfaces = new Class[] { ITestCase.class };

    // set up factory
    factory.setTarget(tc);//  ww  w . j  a v a 2s.  c o  m
    factory.setInterfaces(interfaces);
    factory.addAdvice(logAdvice);
    factory.setExposeProxy(true);

    return (ITestCase) factory.getProxy();
}

From source file:me.yanaga.winter.data.jpa.spring.SimpleRepositoryFactoryBean.java

@Override
public Repository getObject() throws Exception {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(new Class[] { repositoryInterface });
    RepositoryMetadata metadata = RepositoryMetadata.of(repositoryInterface);
    proxyFactory.setTarget(new SimpleRepository<>(metadata.getEntityClass(), entityManager));
    return (Repository) proxyFactory.getProxy();
}

From source file:com.alfresco.orm.LazyProxyFactoryBean.java

public <T extends AlfrescoContent> T getObject(String nodeUUID, Class<T> clasz)
        throws InstantiationException, IllegalAccessException {
    T obj = clasz.newInstance();//from w  w  w .j a v a  2s .  co m
    obj.setNodeUUID(nodeUUID);
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(obj);
    for (Class<? extends Advice> methodInterceptorClass : adviceList) {
        proxyFactory.addAdvice(methodInterceptorClass.newInstance());
    }
    return (T) proxyFactory.getProxy();
}

From source file:ome.testing.InterceptingServiceFactory.java

@SuppressWarnings("unchecked")
<T extends ServiceInterface> T wrap(T service) {
    ProxyFactory factory = new ProxyFactory();
    factory.setInterfaces(service.getClass().getInterfaces());
    for (MethodInterceptor i : interceptors) {
        factory.addAdvice(i);/* w w w  . j av  a2  s  .c o m*/
    }
    factory.setTarget(service);
    return (T) factory.getProxy();
}

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

@Override
public void afterPropertiesSet() throws Exception {

    if (async) {//from w  ww.  j ava  2s .  c  o  m
        Assert.notNull(taskExecutor);

        Future<Node> nodeFuture = taskExecutor.submit(new Callable<Node>() {
            @Override
            public Node call() throws Exception {
                return initialize();
            }
        });

        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setProxyTargetClass(true);
        proxyFactory.setTargetClass(Node.class);
        proxyFactory.addAdvice(new GenericInvocationHandler(nodeFuture));
        proxyfiedNode = (Node) proxyFactory.getProxy();

    } else {
        node = initialize();
    }
}

From source file:com.helpinput.spring.proxy.OptimizeTransactionProxyFactoryBean.java

public void afterPropertiesSet() {
    if (this.target == null) {
        throw new IllegalArgumentException("Property 'target' is required");
    }//from  w  w w  . j a  v  a 2s  .  co  m
    if (this.target instanceof String) {
        throw new IllegalArgumentException("'target' needs to be a bean reference, not a bean name as value");
    }

    ClassLoader proxyClassLoader = target.getClass().getClassLoader();

    ProxyFactory proxyFactory = new ProxyFactory();

    if (this.preInterceptors != null) {
        for (Object interceptor : this.preInterceptors) {
            proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor));
        }
    }

    // Add the main interceptor (typically an Advisor).
    proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(createMainInterceptor()));

    if (this.postInterceptors != null) {
        for (Object interceptor : this.postInterceptors) {
            proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor));
        }
    }

    proxyFactory.copyFrom(this);

    TargetSource targetSource = createTargetSource(this.target);
    proxyFactory.setTargetSource(targetSource);

    if (this.proxyInterfaces != null) {
        proxyFactory.setInterfaces(this.proxyInterfaces);
    } else if (!isProxyTargetClass()) {
        // Rely on AOP infrastructure to tell us what interfaces to proxy.
        proxyFactory.setInterfaces(
                ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), proxyClassLoader));
    }

    /**
     * use this option to let proxyFactory user cglib to create proxy,otherwise in dynamic script ,this is no dynamic interface
     * ? cglib ??java??
     */
    proxyFactory.setOptimize(true);
    this.proxy = proxyFactory.getProxy(proxyClassLoader);
}

From source file:serialization.ProxySerializationTest.java

@Test
public void testSerializableTargetSource() {
    ProxyFactory pf = new ProxyFactory();
    pf.setTargetSource(new SerializableTargetSource(beanFactory, "b2", true));
    pf.setProxyTargetClass(true);/*from   w w w. ja  v  a 2  s  . c  om*/
    pf.addInterface(Serializable.class);
    serialize(pf.getProxy());
}

From source file:org.springframework.data.rest.core.projection.ProxyProjectionFactory.java

@Override
@SuppressWarnings("unchecked")
public <T> T createProjection(Object source, Class<T> projectionType) {

    Assert.isTrue(projectionType.isInterface(), "Projection type must be an interface!");

    if (source == null) {
        return null;
    }//  w  w w  .j  av  a  2 s  . co  m

    ProxyFactory factory = new ProxyFactory();
    factory.setTarget(source);
    factory.setOpaque(true);
    factory.setInterfaces(projectionType, TargetClassAware.class);

    factory.addAdvice(new TargetClassAwareMethodInterceptor(source.getClass()));
    factory.addAdvice(getMethodInterceptor(source, projectionType));

    return (T) factory.getProxy();
}

From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean.java

/**
 * Creates the proxy for target object. This method is invoked by a
 * BeanFactory after it has set all bean properties supplied.
 * //from  www  . j a  v  a 2  s. c  o  m
 * @throws IllegalStateException
 *           if target is <code>null</code>.
 * @throws AopConfigException
 *           if the proxy interfaces or proxyTargetClass are not set and the
 *           target type is <code>org.springframework.aop.TargetSource</code>.
 */
public void afterPropertiesSet() throws IllegalStateException, AopConfigException {
    cachingInterceptor.afterPropertiesSet();
    flushingInterceptor.afterPropertiesSet();

    if (target == null) {
        throw new IllegalStateException("Property 'target' is required");
    }

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(new CachingModelSourceAdvisor(cachingInterceptor));

    if (hasFlushingModels) {
        proxyFactory.addAdvisor(new FlushingModelSourceAdvisor(flushingInterceptor));
    }

    proxyFactory.copyFrom(this);

    TargetSource targetSource = createTargetSource(target);
    proxyFactory.setTargetSource(targetSource);

    if (proxyInterfaces != null) {
        proxyFactory.setInterfaces(proxyInterfaces);
    } else if (!isProxyTargetClass()) {
        if (target instanceof TargetSource) {
            throw new AopConfigException("Either 'proxyInterfaces' or 'proxyTargetClass' is required "
                    + "when using a TargetSource as 'target'");
        }

        // rely on AOP infrastructure to tell us what interfaces to proxy
        proxyFactory.setInterfaces(ClassUtils.getAllInterfaces(target));
    }

    proxy = proxyFactory.getProxy();
}