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

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

Introduction

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

Prototype

DefaultAopProxyFactory

Source Link

Usage

From source file:com.yeahmobi.yunit.testutils.MustNotSwallowSpringJUnit4ClassRunner.java

@Override
public void run(RunNotifier notifier) {
    AdvisedSupport config = new AdvisedSupport();
    config.setTarget(notifier);//from w w  w.  j  a v  a2 s  . c  o m
    config.addAdvice(new org.aopalliance.intercept.MethodInterceptor() {
        public Object invoke(MethodInvocation invocation) throws Throwable {
            if ("fireTestFailure".equals(invocation.getMethod().getName())) {
                Failure failure = (Failure) invocation.getArguments()[0];
                if (failure.getException() instanceof NotSwallowedException) {
                    // We expect this
                    return null;
                }
            }
            return invocation.proceed();
        }
    });
    DefaultAopProxyFactory aopProxyFactory = new DefaultAopProxyFactory();
    RunNotifier runNotifierProxy = (RunNotifier) aopProxyFactory.createAopProxy(config).getProxy();
    super.run(runNotifierProxy);
}

From source file:org.piraso.proxy.RegexProxyFactory.java

@SuppressWarnings("unchecked")
public ProxyInterceptorAware<T> getProxyInterceptor(T object) {
    RegexMethodInterceptor<T> wrapper = new RegexMethodInterceptorWrapper(new RegexMethodInterceptor<T>(),
            object);//from   w ww  .  j a  v  a 2  s. c o m
    wrapper.addAllMethodListener(listeners);

    T proxy;

    if (clazz.isInterface()) {
        proxy = ProxyFactory.getProxy(clazz, wrapper);
    } else {
        AdvisedSupport advisedSupport = new AdvisedSupport();
        advisedSupport.setTarget(object);
        advisedSupport.addAdvice(wrapper);
        AopProxy aopProxy = new DefaultAopProxyFactory().createAopProxy(advisedSupport);
        proxy = (T) aopProxy.getProxy();
    }

    return new ProxyInterceptorAware<T>(proxy, wrapper);
}