List of usage examples for org.springframework.aop.target EmptyTargetSource INSTANCE
EmptyTargetSource INSTANCE
To view the source code for org.springframework.aop.target EmptyTargetSource INSTANCE.
Click Source Link
From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBeanTests.java
public void testAfterPropertiesSetWithProxyInterfacesEqualToNullAndProxyTargetFlagEqualToFalseAndTargetInstanceOfTargetSource() throws Exception { expectAfterPropertiesSetOnInterceptors(); replay();// w w w.java 2 s . co m factoryBean.setProxyTargetClass(false); Object targetInstanceOfTargetSource = EmptyTargetSource.INSTANCE; factoryBean.setTarget(targetInstanceOfTargetSource); try { factoryBean.afterPropertiesSet(); fail(); } catch (AopConfigException exception) { // we are expecting this exception. } verify(); }
From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBeanTests.java
/** * Verifies that the method// w ww. j av a 2 s . c o m * <code>{@link CacheProxyFactoryBean#createTargetSource(Object)}</code> * returns the same object sent as argument if such argument is an instance of * <code>org.springframework.aop.TargetSource</code>. */ public void testCreateTargetSourceWithTargetObjectInstanceOfTargetSource() { Object targetObject = EmptyTargetSource.INSTANCE; assertSame(targetObject, factoryBean.createTargetSource(targetObject)); }
From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBeanTests.java
/** * Verifies that the method/*w ww .ja v a 2 s . c om*/ * <code>{@link CacheProxyFactoryBean#getObjectType()}</code> returns the * class of the target if: * <ul> * <li>The proxy is <code>null</code>.</li> * <li>The target is not <code>null</code> and it is an instance of * <code>org.springframework.aop.TargetSource</code>.</li> * </ul> */ public void testGetObjectTypeWhenProxyIsNullAndTargetIsNotNullAndTargetIsInstanceOfTargetSource() { TargetSource instanceOfTargetSource = EmptyTargetSource.INSTANCE; factoryBean.setTarget(instanceOfTargetSource); // verify that the proxy is null before running the method to test. assertNull(factoryBean.getProxy()); assertEquals(instanceOfTargetSource.getClass(), factoryBean.getObjectType()); }
From source file:org.springframework.cloud.iot.coap.method.ResolvableMethod.java
@SuppressWarnings("unchecked") private static <T> T initProxy(Class<?> type, MethodInvocationInterceptor interceptor) { Assert.notNull(type, "'type' must not be null"); if (type.isInterface()) { ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); factory.addInterface(type);/*from w ww . ja v a 2s . co m*/ factory.addInterface(Supplier.class); factory.addAdvice(interceptor); return (T) factory.getProxy(); } else { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(type); enhancer.setInterfaces(new Class<?>[] { Supplier.class }); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); enhancer.setCallbackType(org.springframework.cglib.proxy.MethodInterceptor.class); Class<?> proxyClass = enhancer.createClass(); Object proxy = null; if (objenesis.isWorthTrying()) { try { proxy = objenesis.newInstance(proxyClass, enhancer.getUseCache()); } catch (ObjenesisException ex) { logger.debug("Objenesis failed, falling back to default constructor", ex); } } if (proxy == null) { try { proxy = ReflectionUtils.accessibleConstructor(proxyClass).newInstance(); } catch (Throwable ex) { throw new IllegalStateException("Unable to instantiate proxy " + "via both Objenesis and default constructor fails as well", ex); } } ((Factory) proxy).setCallbacks(new Callback[] { interceptor }); return (T) proxy; } }
From source file:org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.java
@SuppressWarnings("unchecked") private static <T> T initProxy(Class<?> type, ControllerMethodInvocationInterceptor interceptor) { if (type.isInterface()) { ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); factory.addInterface(type);/*from w w w . j a v a 2 s . co m*/ factory.addInterface(MethodInvocationInfo.class); factory.addAdvice(interceptor); return (T) factory.getProxy(); } else { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(type); enhancer.setInterfaces(new Class<?>[] { MethodInvocationInfo.class }); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); enhancer.setCallbackType(org.springframework.cglib.proxy.MethodInterceptor.class); Class<?> proxyClass = enhancer.createClass(); Object proxy = null; if (objenesis.isWorthTrying()) { try { proxy = objenesis.newInstance(proxyClass, enhancer.getUseCache()); } catch (ObjenesisException ex) { logger.debug("Unable to instantiate controller proxy using Objenesis, " + "falling back to regular construction", ex); } } if (proxy == null) { try { proxy = ReflectionUtils.accessibleConstructor(proxyClass).newInstance(); } catch (Throwable ex) { throw new IllegalStateException( "Unable to instantiate controller proxy using Objenesis, " + "and regular controller instantiation via default constructor fails as well", ex); } } ((Factory) proxy).setCallbacks(new Callback[] { interceptor }); return (T) proxy; } }
From source file:org.springframework.web.servlet.mvc.support.MvcUrlUtils.java
@SuppressWarnings("unchecked") private static <T> T initProxy(Class<?> type, ControllerMethodInvocationInterceptor interceptor) { if (type.isInterface()) { ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); factory.addInterface(type);/*from ww w . j a v a2 s .co m*/ factory.addInterface(ControllerMethodValues.class); factory.addAdvice(interceptor); return (T) factory.getProxy(); } else { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(type); enhancer.setInterfaces(new Class<?>[] { ControllerMethodValues.class }); enhancer.setCallbackType(org.springframework.cglib.proxy.MethodInterceptor.class); Factory factory = (Factory) OBJENESIS.newInstance(enhancer.createClass()); factory.setCallbacks(new Callback[] { interceptor }); return (T) factory; } }