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

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

Introduction

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

Prototype

public void addInterface(Class<?> intf) 

Source Link

Document

Add a new proxied interface.

Usage

From source file:org.jdal.aop.SerializableProxyUtils.java

/**
 * Create a new Serializable proxy for the given target.
 * @param target target to proxy/*from  w  ww.  java  2 s.  com*/
 * @param reference serializable reference 
 * @return a new serializable proxy
 */
private static Object createSerializableProxy(Object target, SerializableReference reference) {
    ProxyFactory pf = new ProxyFactory(target);
    pf.setExposeProxy(true);
    pf.setProxyTargetClass(reference.isProxyTargetClass());
    pf.addInterface(SerializableObject.class);
    pf.addAdvice(new SerializableIntroductionInterceptor(reference));

    return pf.getProxy(reference.getBeanFactory().getBeanClassLoader());
}

From source file:serialization.ProxySerializationTest.java

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

From source file:com.payu.ratel.client.ContextAnnotationAutowireCandidateResolver.java

protected Object buildLazyResolutionProxy(final DependencyDescriptor descriptor, final String beanName) {
    Assert.state(getBeanFactory() instanceof DefaultListableBeanFactory,
            "BeanFactory needs to be a DefaultListableBeanFactory");
    final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) getBeanFactory();
    TargetSource ts = new TargetSource() {
        @Override/*from ww  w . j  ava 2 s .c  o  m*/
        public Class<?> getTargetClass() {
            return descriptor.getDependencyType();
        }

        @Override
        public boolean isStatic() {
            return false;
        }

        @Override
        public Object getTarget() {
            return beanFactory.doResolveDependency(descriptor, beanName, null, null);
        }

        @Override
        public void releaseTarget(Object target) {
        }
    };
    ProxyFactory pf = new ProxyFactory();
    pf.setTargetSource(ts);
    Class<?> dependencyType = descriptor.getDependencyType();
    if (dependencyType.isInterface()) {
        pf.addInterface(dependencyType);
    }
    return pf.getProxy(beanFactory.getBeanClassLoader());
}

From source file:org.jdal.remoting.rmi.RmiNativeRemoteReference.java

/**
 * {@inheritDoc}//  w  w  w.j a  v a 2 s  .c  o m
 */
@SuppressWarnings("unchecked")
public RemoteClient createRemoteClient() {
    ProxyFactory pf = null;
    if (getServiceInterface().isAssignableFrom(remoteService.getClass())) {
        pf = new ProxyFactory(remoteService);
    } else {
        pf = new ProxyFactory(getServiceInterface(),
                new RmiServiceInterceptor((RmiInvocationHandler) remoteService));
    }

    pf.addInterface(RemoteClient.class);
    pf.addAdvisor(new RemoteClientAdvisor(this));

    return (RemoteClient) pf.getProxy();
}

From source file:org.sakaiproject.genericdao.springutil.CurrentClassLoaderBeanNameAutoProxyCreator.java

@SuppressWarnings("unchecked")
@Override/*from   w w w . ja  va 2 s .  co  m*/
protected Object createProxy(Class beanClass, String beanName, Object[] specificInterceptors,
        TargetSource targetSource) {
    if (spring12x) {
        ProxyFactory proxyFactory = new ProxyFactory();
        // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig.
        proxyFactory.copyFrom(this);

        if (!shouldProxyTargetClass(beanClass, beanName)) {
            // Must allow for introductions; can't just set interfaces to
            // the target's interfaces only.
            Class[] targetInterfaces = ClassUtils.getAllInterfacesForClass(beanClass);
            for (int i = 0; i < targetInterfaces.length; i++) {
                proxyFactory.addInterface(targetInterfaces[i]);
            }
        }

        Advisor[] advisors = buildAdvisors(beanName, specificInterceptors);
        for (int i = 0; i < advisors.length; i++) {
            proxyFactory.addAdvisor(advisors[i]);
        }

        proxyFactory.setTargetSource(targetSource);
        customizeProxyFactory(proxyFactory);

        proxyFactory.setFrozen(this.freezeProxy);
        return proxyFactory.getProxy(myClassLoader);
    } else {
        return super.createProxy(beanClass, beanName, specificInterceptors, targetSource);
    }
}

From source file:org.arrow.service.engine.execution.interceptor.impl.MultipleEventAwareInitializer.java

/**
 * Initializes a catching multiple event.
 *
 * @return BpmnNodeEntity// w w w  .j a v a2s . c o m
 */
private BpmnNodeEntity initializeCatchingEvent(BpmnNodeEntity entity, Set<EventDefinition> definitions) {

    ProxyFactory factory = new ProxyFactory(entity);

    for (EventDefinition definition : definitions) {

        // Signal event definition
        if (definition instanceof SignalEventDefinition) {
            SignalEventDefinition def = (SignalEventDefinition) definition;
            Advice advice = new SignalEventHandlerIntroduction(def);
            factory.addAdvice(advice);
        }

        // Message event definition
        else if (definition instanceof MessageEventDefinition) {
            MessageEventDefinition def = (MessageEventDefinition) definition;
            Advice advice = new MessageEventHandlerIntroduction(def);
            factory.addAdvice(advice);
        }

        // Timer event definition
        else if (definition instanceof TimerEventDefinition) {
            TimerEventDefinition def = (TimerEventDefinition) definition;
            Advice advice = new TimerEventHandlerIntroduction(def);
            factory.addAdvice(advice);
        }

        // Conditional event definition
        else if (definition instanceof ConditionalEventDefinition) {
            ConditionalEventDefinition def = (ConditionalEventDefinition) definition;
            Advice advice = new ConditionalEventHandlerIntroduction(def);
            factory.addAdvice(advice);
        }

    }
    factory.addInterface(BpmnNodeEntity.class);
    return (BpmnNodeEntity) factory.getProxy();

}

From source file:org.arrow.service.engine.execution.interceptor.impl.MultipleEventAwareInitializer.java

/**
 * Initializes a throwing multiple event.
 *
 * @return BpmnNodeEntity/*from  w w  w . ja  v  a 2 s  .  c o  m*/
 */
private BpmnNodeEntity initializeThrowingEvent(BpmnNodeEntity entity, Set<EventDefinition> definitions) {

    ProxyFactory factory = new ProxyFactory(entity);

    for (EventDefinition definition : definitions) {

        // Signal event definition
        if (definition instanceof SignalEventDefinition) {
            SignalEventDefinition def = (SignalEventDefinition) definition;
            Advice advice = new SignalEventPublisherIntroduction(def);
            factory.addAdvice(advice);
        }

        // Message event definition
        else if (definition instanceof MessageEventDefinition) {
            MessageEventDefinition def = (MessageEventDefinition) definition;
            Advice advice = new MessageEventPublisherIntroduction(def);
            factory.addAdvice(advice);
        }

        // Timer event definition
        else if (definition instanceof TimerEventDefinition) {
            TimerEventDefinition def = (TimerEventDefinition) definition;
            Advice advice = new TimerEventPublisherIntroduction(def);
            factory.addAdvice(advice);
        }

        // Conditional event definition
        else if (definition instanceof ConditionalEventDefinition) {
            ConditionalEventDefinition def = (ConditionalEventDefinition) definition;
            Advice advice = new ConditionalEventPublisherIntroduction(def);
            factory.addAdvice(advice);
        }

    }
    factory.addInterface(BpmnNodeEntity.class);
    return (BpmnNodeEntity) factory.getProxy();
}

From source file:org.alfresco.opencmis.AlfrescoCmisServiceFactory.java

/**
 * TODO://from   w  ww  .  java  2s. c  o m
 *      We are producing new instances each time.   
 */
@Override
public CmisService getService(final CallContext context) {
    if (logger.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("getService: ").append(AuthenticationUtil.getFullyAuthenticatedUser()).append(" [runAsUser=")
                .append(AuthenticationUtil.getRunAsUser()).append(",ctxUserName=").append(context.getUsername())
                .append(",ctxRepoId=").append(context.getRepositoryId()).append("]");

        logger.debug(sb.toString());
    }

    // Avoid using guest user if the user is provided in the context
    if (AuthenticationUtil.getFullyAuthenticatedUser() != null
            && authorityService.isGuestAuthority(AuthenticationUtil.getFullyAuthenticatedUser())) {
        AuthenticationUtil.clearCurrentSecurityContext();
    }

    AlfrescoCmisService service = getCmisServiceTarget(connector);

    // Wrap it
    ProxyFactory proxyFactory = new ProxyFactory(service);
    proxyFactory.addInterface(AlfrescoCmisService.class);
    proxyFactory.addAdvice(cmisExceptions);
    proxyFactory.addAdvice(cmisControl);
    proxyFactory.addAdvice(cmisStreams);
    proxyFactory.addAdvice(cmisTransactions);
    AlfrescoCmisService cmisService = (AlfrescoCmisService) proxyFactory.getProxy();

    CmisServiceWrapper<CmisService> wrapperService = new CmisServiceWrapper<CmisService>(cmisService,
            connector.getTypesDefaultMaxItems(), connector.getTypesDefaultDepth(),
            connector.getObjectsDefaultMaxItems(), connector.getObjectsDefaultDepth());

    // We use our specific open method here because only we know about it
    cmisService.open(context);

    return wrapperService;
}

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 w w w  . j a  v  a2  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.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java

protected void initializeProxy(Object delegate) {
    if (this.getAdviceChain().length == 0) {
        return;/*from w  w w.  j  av  a2 s  .  c o  m*/
    }
    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());
}