Refine search
/** * Create a proxy for the specified {@code TargetSource}, * implementing the specified interface. * @param proxyInterface the interface that the proxy should implement * @param targetSource the TargetSource that the proxy should invoke * @return the proxy object * @see #ProxyFactory(Class, org.springframework.aop.TargetSource) */ @SuppressWarnings("unchecked") public static <T> T getProxy(Class<T> proxyInterface, TargetSource targetSource) { return (T) new ProxyFactory(proxyInterface, targetSource).getProxy(); }
@Override public void afterPropertiesSet() throws NamingException { super.afterPropertiesSet(); if (this.businessInterface == null) { throw new IllegalArgumentException("businessInterface is required"); } this.proxy = new ProxyFactory(this.businessInterface, this).getProxy(this.beanClassLoader); }
@Override public void afterPropertiesSet() throws NamingException { super.afterPropertiesSet(); if (this.businessInterface == null) { throw new IllegalArgumentException("businessInterface is required"); } this.proxy = new ProxyFactory(this.businessInterface, this).getProxy(this.beanClassLoader); }
/** * Creates lazy proxies for the {@code JMXConnector} and {@code MBeanServerConnection}. */ private void createLazyConnection() { this.connectorTargetSource = new JMXConnectorLazyInitTargetSource(); TargetSource connectionTargetSource = new MBeanServerConnectionLazyInitTargetSource(); this.connector = (JMXConnector) new ProxyFactory(JMXConnector.class, this.connectorTargetSource).getProxy(this.beanClassLoader); this.connection = (MBeanServerConnection) new ProxyFactory(MBeanServerConnection.class, connectionTargetSource).getProxy(this.beanClassLoader); }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Assert.notNull(this.serviceInterface, "Property 'serviceInterface' is required"); this.serviceProxy = new ProxyFactory(this.serviceInterface, this).getProxy(this.beanClassLoader); }
@Override public void afterPropertiesSet() throws NamingException { super.afterPropertiesSet(); Class<?> ifc = getServiceInterface(); Assert.notNull(ifc, "Property 'serviceInterface' is required"); this.serviceProxy = new ProxyFactory(ifc, this).getProxy(this.beanClassLoader); }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { ProxyFactory pf = new ProxyFactory(bean); return pf.getProxy(); } }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Class<?> ifc = getServiceInterface(); Assert.notNull(ifc, "Property 'serviceInterface' is required"); this.serviceProxy = new ProxyFactory(ifc, this).getProxy(getBeanClassLoader()); }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Class<?> ifc = getServiceInterface(); Assert.notNull(ifc, "Property 'serviceInterface' is required"); this.serviceProxy = new ProxyFactory(ifc, this).getProxy(getBeanClassLoader()); }
protected Object configuredProxy(SimpleRemoteSlsbInvokerInterceptor si, Class<?> ifc) throws NamingException { si.afterPropertiesSet(); ProxyFactory pf = new ProxyFactory(new Class<?>[] {ifc}); pf.addAdvice(si); return pf.getProxy(); }
static SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean nestedProxy() { ProxyFactory pf1 = new ProxyFactory(new SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean()); pf1.setProxyTargetClass(true); ProxyFactory pf2 = new ProxyFactory(pf1.getProxy()); pf2.setProxyTargetClass(true); return (SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean) pf2.getProxy(); } }
@Test public void testInterfaceProxiesCanBeOrderedThroughAnnotations() { Object proxy1 = new ProxyFactory(new A()).getProxy(); Object proxy2 = new ProxyFactory(new B()).getProxy(); List<Object> list = new ArrayList<>(2); list.add(proxy1); list.add(proxy2); AnnotationAwareOrderComparator.sort(list); assertSame(proxy2, list.get(0)); assertSame(proxy1, list.get(1)); }
@Test @Ignore("Not implemented yet, see http://jira.springframework.org/browse/SPR-5708") public void testExclusionOfNonPublicInterfaces() { JFrame frame = new JFrame(); ProxyFactory proxyFactory = new ProxyFactory(frame); Object proxy = proxyFactory.getProxy(); assertTrue(proxy instanceof RootPaneContainer); assertTrue(proxy instanceof Accessible); }
@Override protected Object advised(Object target, PlatformTransactionManager ptm, TransactionAttributeSource[] tas) throws Exception { TransactionInterceptor ti = new TransactionInterceptor(); ti.setTransactionManager(ptm); ti.setTransactionAttributeSources(tas); ProxyFactory pf = new ProxyFactory(target); pf.addAdvice(0, ti); return pf.getProxy(); }
private Foo jdkProxy(Foo foo) { ProxyFactory pf = new ProxyFactory(); pf.setTarget(foo); pf.addInterface(Foo.class); Foo proxy = (Foo) pf.getProxy(); assertTrue("Proxy is a JDK dynamic proxy", AopUtils.isJdkDynamicProxy(proxy)); assertThat(proxy, instanceOf(Foo.class)); return proxy; }
@Test public void proxiedConverter() { Converter<?, ?> converter = new IntegerConverter(); formattingService.addConverter((Converter<?, ?>) new ProxyFactory(converter).getProxy()); assertEquals(Integer.valueOf(1), formattingService.convert("1", Integer.class)); }
private Foo cglibProxy(Foo foo) { ProxyFactory pf = new ProxyFactory(); pf.setTarget(foo); pf.setProxyTargetClass(true); Foo proxy = (Foo) pf.getProxy(); assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy)); assertThat(proxy, instanceOf(FooImpl.class)); return proxy; }
@Test public void testAopJdkProxyWithDetectedInterfaces() throws Exception { ModelMap map = new ModelMap(); Map<?, ?> target = new HashMap<>(); ProxyFactory factory = new ProxyFactory(target); Object proxy = factory.getProxy(); map.addAttribute(proxy); assertSame(proxy, map.get("map")); }
@Test public void proxiedConverterFactory() { ConverterFactory<?, ?> converterFactory = new IntegerConverterFactory(); formattingService.addConverterFactory((ConverterFactory<?, ?>) new ProxyFactory(converterFactory).getProxy()); assertEquals(Integer.valueOf(1), formattingService.convert("1", Integer.class)); }
@Test public void getShortNameForCglibClass() { TestBean tb = new TestBean(); ProxyFactory pf = new ProxyFactory(); pf.setTarget(tb); pf.setProxyTargetClass(true); TestBean proxy = (TestBean) pf.getProxy(); String className = ClassUtils.getShortName(proxy.getClass()); assertEquals("Class name did not match", "TestBean", className); } }