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:oz.hadoop.yarn.api.YarnAssembly.java

/**
 * //w ww  . j a v  a 2s .  co m
 */
@SuppressWarnings("unchecked")
private static WithVcPrMemCount<Void> createV(String command,
        Class<? extends ApplicationContainerProcessor> applicationContainer, ByteBuffer arguments,
        String javaShellPath) {
    ProxyFactory pf = new ProxyFactory();
    pf.setInterfaces(WithVcPrMemCount.class);
    AssemblyAdvice assemblyAdvice = new AssemblyAdvice(command, applicationContainer, arguments, javaShellPath);
    pf.addAdvice(assemblyAdvice);
    WithVcPrMemCount<Void> builder = (WithVcPrMemCount<Void>) pf.getProxy();
    return builder;
}

From source file:oz.hadoop.yarn.api.YarnAssembly.java

/**
 * //  w  ww.ja va2s . com
 */
@SuppressWarnings("unchecked")
private static WithVcPrMemCount<DataProcessor> createC(String command,
        Class<? extends ApplicationContainerProcessor> applicationContainer, ByteBuffer arguments,
        String javaShellPath) {
    ProxyFactory pf = new ProxyFactory();
    pf.setInterfaces(WithVcPrMemCount.class);
    AssemblyAdvice assemblyAdvice = new AssemblyAdvice(command, applicationContainer, arguments, javaShellPath);
    pf.addAdvice(assemblyAdvice);
    WithVcPrMemCount<DataProcessor> builder = (WithVcPrMemCount<DataProcessor>) pf.getProxy();
    return builder;
}

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

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

    if (async) {/*from  w  ww  .  jav  a2  s  .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/*  w w  w.j av  a2 s.  co  m*/
 * @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:ome.services.blitz.impl.AbstractAmdServant.java

/**
 * Applies the hard-wired intercepting to this instance. It is not possible
 * to configure hard-wired interceptors in Spring, instead they must be
 * passed in at runtime from a properly compiled class.
 *//* w  ww  . j a v a2s  . c  om*/
public final void applyHardWiredInterceptors(List<HardWiredInterceptor> cptors,
        AopContextInitializer initializer) {

    if (service != null) {
        ProxyFactory wiredService = new ProxyFactory();
        wiredService.setInterfaces(service.getClass().getInterfaces());
        wiredService.setTarget(service);

        List<HardWiredInterceptor> reversed = new ArrayList<HardWiredInterceptor>(cptors);
        Collections.reverse(reversed);
        for (HardWiredInterceptor hwi : reversed) {
            wiredService.addAdvice(0, hwi);
        }
        wiredService.addAdvice(0, initializer);
        service = (ServiceInterface) wiredService.getProxy();
    }
}

From source file:org.impalaframework.service.proxy.ProxyHelper.java

/**
 * Possibly wraps bean with proxy. Based on following rules:
 * <ul>/*from   w w w. j  a  va  2s .  com*/
 * <li>if proxyEntries is false, then does not wrap
 * <li>if the bean does not implement any interface, then does not wrap
 * <li>if proxyInterfaces is not empty, but bean does not implement any of the specified interface, then does not wrap
 * <li>if proxyInterfaces is not empty, then wraps with proxy, exposing with interfaces which are both are in proxyInterfaces and implemented by bean
 * <li>if proxyInterfaces is null or empty, then wraps with proxy, exposing with all interfaces implemented by bean
 * </ul>
 */
public Object maybeGetProxy(ServiceRegistryEntry entry) {

    Object bean = entry.getServiceBeanReference().getService();

    if (!proxyEntries) {
        return bean;
    }

    final List<Class<?>> interfaces = ReflectionUtils.findInterfaceList(bean);

    if (interfaces.size() == 0) {
        logger.warn("Bean of instance " + bean.getClass().getName()
                + " could not be backed by a proxy as it does not implement an interface");
        return bean;
    }

    final Class<?>[] proxyInterfaces = this.proxyInterfaces;

    final List<Class<?>> filteredInterfaces = filterInterfaces(interfaces, proxyInterfaces);

    if (filteredInterfaces.size() == 0) {
        logger.warn("Bean of instance " + bean.getClass().getName()
                + " does not implement any of the specified interfaces: " + proxyInterfaces);
        return bean;
    }

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(filteredInterfaces.toArray(new Class[0]));
    proxyFactory.setTarget(bean);
    final Object proxyObject = proxyFactory.getProxy();
    return proxyObject;
}

From source file:org.impalaframework.spring.service.proxy.BeanRetrievingProxyFactorySource.java

public void init() {

    Assert.notNull(this.serviceRegistry, "serviceRegistry cannot be null");

    //BeanRetrievingServiceRegistryTargetSource implements rules on whether bean name, proxyTypes or exportTypes can and cannot be null

    //this will return a non-null value if single interface which is concrete class
    ServiceEndpointTargetSource targetSource = new BeanRetrievingServiceRegistryTargetSource(
            this.serviceRegistry, registryBeanName, proxyTypes, exportTypes);

    ProxyFactory proxyFactory = new ProxyFactory();

    if (targetSource.getTargetClass() == null) {
        //not proxying by class, so proxy by interface
        ProxyFactorySourceUtils.addInterfaces(proxyFactory, proxyTypes);
    }// ww w. j  a va2  s .  c  om

    afterInit(proxyFactory, targetSource);
}

From source file:org.openengsb.core.services.internal.ConnectorRegistrationManager.java

private Connector proxyForSecurity(String id, ConnectorDescription description, Connector serviceInstance,
        Class<?>[] clazzes) {
    if (INTERCEPTOR_BLACKLIST.contains(description.getDomainType())) {
        LOGGER.info("not proxying service because domain is blacklisted: {} ", serviceInstance);
        return serviceInstance;
    }//from  www .j a  v  a 2s.  c  om
    if (securityInterceptor == null) {
        LOGGER.warn("security interceptor is not available yet");
        return serviceInstance;
    }
    // @extract-start register-secure-service-code
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(clazzes);
    proxyFactory.addAdvice(securityInterceptor);
    proxyFactory.setTarget(serviceInstance);
    Connector result = (Connector) proxyFactory.getProxy(this.getClass().getClassLoader());
    // @extract-end
    attributeStore.replaceAttributes(serviceInstance, new SecurityAttributeEntry("name", id));
    return result;
}

From source file:org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java

protected void initializeProxy(Object delegate) {
    if (this.getAdviceChain().length == 0) {
        return;//from   w  ww . ja v  a 2  s  .  c  om
    }
    ProxyFactory factory = new ProxyFactory();
    for (Advice advice : getAdviceChain()) {
        factory.addAdvisor(new DefaultPointcutAdvisor(advice));
    }
    factory.addInterface(ContainerDelegate.class);
    factory.setTarget(delegate);
    this.proxy = (ContainerDelegate) factory.getProxy(ContainerDelegate.class.getClassLoader());
}

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/*from   w  w  w . j av a2s.c  o  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());
}