@Test public void testGetProxyInterceptor() throws Exception { DataSource actual = mock(DataSource.class); RegexProxyFactory<DataSource> factory = new RegexProxyFactory<DataSource>(DataSource.class); ProxyInterceptorAware<DataSource> proxy = factory.getProxyInterceptor(actual); proxy.getProxy().getConnection(); proxy.getProxy().getConnection(); assertNotNull(proxy.getInterceptor()); assertThat(proxy.getProxy(), not(sameInstance(actual))); verify(actual, times(2)).getConnection(); }
@SuppressWarnings("unchecked") public ProxyInterceptorAware<T> getProxyInterceptor(T object) { RegexMethodInterceptor<T> wrapper = new RegexMethodInterceptorWrapper(new RegexMethodInterceptor<T>(), object); 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); }
RegexProxyFactory implements ProxyAware<T> { @SuppressWarnings("unchecked") public ProxyInterceptorAware<T> getProxyInterceptor(T object) { RegexMethodInterceptor<T> wrapper = new RegexMethodInterceptorWrapper(new RegexMethodInterceptor<T>(), object); 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); } }
RegexProxyFactory implements ProxyAware<T> { @SuppressWarnings("unchecked") public ProxyInterceptorAware<T> getProxyInterceptor(T object) { RegexMethodInterceptor<T> wrapper = new RegexMethodInterceptorWrapper(new RegexMethodInterceptor<T>(), object); 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); } RegexProxyFactory(Class<T> clazz); }
RegexProxyFactory implements ProxyAware<T> { @SuppressWarnings("unchecked") public ProxyInterceptorAware<T> getProxyInterceptor(T object) { RegexMethodInterceptor<T> wrapper = new RegexMethodInterceptorWrapper(new RegexMethodInterceptor<T>(), object); 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); } RegexProxyFactory(Class<T> clazz); T getProxy(T object); @SuppressWarnings("unchecked") ProxyInterceptorAware<T> getProxyInterceptor(T object); void addMethodListener(String regex, RegexMethodInterceptorListener<T> listener); }
RegexProxyFactory implements ProxyAware<T> { @SuppressWarnings("unchecked") public ProxyInterceptorAware<T> getProxyInterceptor(T object) { RegexMethodInterceptor<T> wrapper = new RegexMethodInterceptorWrapper(new RegexMethodInterceptor<T>(), object); 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); } RegexProxyFactory(Class<T> clazz); T getProxy(T object); @SuppressWarnings("unchecked") ProxyInterceptorAware<T> getProxyInterceptor(T object); void addMethodListener(String regex, RegexMethodInterceptorListener<T> listener);  }