List of usage examples for org.springframework.aop.framework AdvisedSupport addAdvice
@Override public void addAdvice(Advice advice) throws AopConfigException
From source file:com.yeahmobi.yunit.testutils.MustNotSwallowSpringJUnit4ClassRunner.java
@Override public void run(RunNotifier notifier) { AdvisedSupport config = new AdvisedSupport(); config.setTarget(notifier);/*from w ww. ja v a2s . 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);/*w w w . j a v a2s.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); }