当前位置: 首页>>代码示例>>Java>>正文


Java ProxyFactory.setInterfaces方法代码示例

本文整理汇总了Java中org.springframework.aop.framework.ProxyFactory.setInterfaces方法的典型用法代码示例。如果您正苦于以下问题:Java ProxyFactory.setInterfaces方法的具体用法?Java ProxyFactory.setInterfaces怎么用?Java ProxyFactory.setInterfaces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.aop.framework.ProxyFactory的用法示例。


在下文中一共展示了ProxyFactory.setInterfaces方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRefreshableProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Create a refreshable proxy for the given AOP TargetSource.
 * @param ts the refreshable TargetSource
 * @param interfaces the proxy interfaces (may be {@code null} to
 * indicate proxying of all interfaces implemented by the target class)
 * @return the generated proxy
 * @see RefreshableScriptTargetSource
 */
protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setTargetSource(ts);
	ClassLoader classLoader = this.beanClassLoader;

	if (interfaces == null) {
		interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
	}
	proxyFactory.setInterfaces(interfaces);
	if (proxyTargetClass) {
		classLoader = null;  // force use of Class.getClassLoader()
		proxyFactory.setProxyTargetClass(proxyTargetClass);
	}

	DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
	introduction.suppressInterface(TargetSource.class);
	proxyFactory.addAdvice(introduction);

	return proxyFactory.getProxy(classLoader);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:ScriptFactoryPostProcessor.java

示例2: createRefreshableProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
    * Create a refreshable proxy for the given AOP TargetSource.
    * 
    * @param ts
    *            the refreshable TargetSource
    * @param interfaces
    *            the proxy interfaces (may be {@code null} to indicate proxying
    *            of all interfaces implemented by the target class)
    * @return the generated proxy
    * @see RefreshableScriptTargetSource
    */
   protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTargetSource(ts);
ClassLoader classLoader = this.beanClassLoader;

if (interfaces == null) {
    interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
}
proxyFactory.setInterfaces(interfaces);
if (proxyTargetClass) {
    classLoader = null; // force use of Class.getClassLoader()
    proxyFactory.setProxyTargetClass(true);
}

DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
introduction.suppressInterface(TargetSource.class);
proxyFactory.addAdvice(introduction);

return proxyFactory.getProxy(classLoader);
   }
 
开发者ID:ilivoo,项目名称:game,代码行数:32,代码来源:MyScriptFactoryPostProcessor.java

示例3: createProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
protected Object createProxy(Object target, List<Advisor> advisors, Class<?>... interfaces) {
	ProxyFactory pf = new ProxyFactory(target);
	if (interfaces.length > 1 || interfaces[0].isInterface()) {
		pf.setInterfaces(interfaces);
	}
	else {
		pf.setProxyTargetClass(true);
	}

	// Required everywhere we use AspectJ proxies
	pf.addAdvice(ExposeInvocationInterceptor.INSTANCE);

	for (Object a : advisors) {
		pf.addAdvisor((Advisor) a);
	}

	pf.setExposeProxy(true);
	return pf.getProxy();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AbstractAspectJAdvisorFactoryTests.java

示例4: testSerializable

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void testSerializable() throws Exception {
	DerivedTestBean tb = new DerivedTestBean();
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setInterfaces(new Class[] {ITestBean.class});
	ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
	proxyFactory.addAdvice(cti);
	proxyFactory.setTarget(tb);
	ITestBean proxy = (ITestBean) proxyFactory.getProxy();
	proxy.getAge();

	ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
	Advised advised = (Advised) serializedProxy;
	ConcurrencyThrottleInterceptor serializedCti =
			(ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
	assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
	serializedProxy.getAge();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ConcurrencyThrottleInterceptorTests.java

示例5: createRefreshableProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Create a refreshable proxy for the given AOP TargetSource.
 * @param ts the refreshable TargetSource
 * @param interfaces the proxy interfaces (may be {@code null} to
 * indicate proxying of all interfaces implemented by the target class)
 * @return the generated proxy
 * @see RefreshableScriptTargetSource
 */
protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setTargetSource(ts);
	ClassLoader classLoader = this.beanClassLoader;

	if (interfaces == null) {
		interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
	}
	proxyFactory.setInterfaces(interfaces);
	if (proxyTargetClass) {
		classLoader = null;  // force use of Class.getClassLoader()
		proxyFactory.setProxyTargetClass(true);
	}

	DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
	introduction.suppressInterface(TargetSource.class);
	proxyFactory.addAdvice(introduction);

	return proxyFactory.getProxy(classLoader);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:ScriptFactoryPostProcessor.java

示例6: testExportJdkProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void testExportJdkProxy() throws Exception {
	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	ProxyFactory factory = new ProxyFactory();
	factory.setTarget(bean);
	factory.addAdvice(new NopInterceptor());
	factory.setInterfaces(IJmxTestBean.class);

	IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
	String name = "bean:mmm=whatever";

	Map<String, Object> beans = new HashMap<String, Object>();
	beans.put(name, proxy);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.registerBeans();

	ObjectName oname = ObjectName.getInstance(name);
	Object nameValue = server.getAttribute(oname, "Name");
	assertEquals("Rob Harrop", nameValue);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:MBeanExporterTests.java

示例7: serializable

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void serializable() throws Exception {
	TestBean1 tb = new TestBean1();
	CallCountingTransactionManager ptm = new CallCountingTransactionManager();
	AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
	TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);

	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setInterfaces(new Class[] {ITestBean.class});
	proxyFactory.addAdvice(ti);
	proxyFactory.setTarget(tb);
	ITestBean proxy = (ITestBean) proxyFactory.getProxy();
	proxy.getAge();
	assertEquals(1, ptm.commits);

	ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
	serializedProxy.getAge();
	Advised advised = (Advised) serializedProxy;
	TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
	CallCountingTransactionManager serializedPtm =
			(CallCountingTransactionManager) serializedTi.getTransactionManager();
	assertEquals(2, serializedPtm.commits);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:AnnotationTransactionAttributeSourceTests.java

示例8: tstProxyCreation

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void tstProxyCreation() throws Exception {
	ProxyFactory pf = new ProxyFactory();
	pf.setInterfaces(new Class<?>[] { Serializable.class, Comparable.class });
	//pf.setTargetClass(Number.class);
	pf.setProxyTargetClass(true);
	Object proxy = pf.getProxy();
	System.out.println(ObjectUtils.nullSafeToString(ClassUtils.getAllInterfaces(proxy)));
	assertTrue(proxy instanceof Number);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:10,代码来源:OsgiServiceUtilsTest.java

示例9: createJndiObjectProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
private static Object createJndiObjectProxy(JndiObjectFactoryBean jof) throws NamingException {
	// Create a JndiObjectTargetSource that mirrors the JndiObjectFactoryBean's configuration.
	JndiObjectTargetSource targetSource = new JndiObjectTargetSource();
	targetSource.setJndiTemplate(jof.getJndiTemplate());
	targetSource.setJndiName(jof.getJndiName());
	targetSource.setExpectedType(jof.getExpectedType());
	targetSource.setResourceRef(jof.isResourceRef());
	targetSource.setLookupOnStartup(jof.lookupOnStartup);
	targetSource.setCache(jof.cache);
	targetSource.afterPropertiesSet();

	// Create a proxy with JndiObjectFactoryBean's proxy interface and the JndiObjectTargetSource.
	ProxyFactory proxyFactory = new ProxyFactory();
	if (jof.proxyInterfaces != null) {
		proxyFactory.setInterfaces(jof.proxyInterfaces);
	}
	else {
		Class<?> targetClass = targetSource.getTargetClass();
		if (targetClass == null) {
			throw new IllegalStateException(
					"Cannot deactivate 'lookupOnStartup' without specifying a 'proxyInterface' or 'expectedType'");
		}
		Class<?>[] ifcs = ClassUtils.getAllInterfacesForClass(targetClass, jof.beanClassLoader);
		for (Class<?> ifc : ifcs) {
			if (Modifier.isPublic(ifc.getModifiers())) {
				proxyFactory.addInterface(ifc);
			}
		}
	}
	if (jof.exposeAccessContext) {
		proxyFactory.addAdvice(new JndiContextExposingInterceptor(jof.getJndiTemplate()));
	}
	proxyFactory.setTargetSource(targetSource);
	return proxyFactory.getProxy(jof.beanClassLoader);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:JndiObjectFactoryBean.java

示例10: setBeanFactory

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Override
public void setBeanFactory(BeanFactory beanFactory) {
	if (!(beanFactory instanceof ConfigurableBeanFactory)) {
		throw new IllegalStateException("Not running in a ConfigurableBeanFactory: " + beanFactory);
	}
	ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;

	this.scopedTargetSource.setBeanFactory(beanFactory);

	ProxyFactory pf = new ProxyFactory();
	pf.copyFrom(this);
	pf.setTargetSource(this.scopedTargetSource);

	Class<?> beanType = beanFactory.getType(this.targetBeanName);
	if (beanType == null) {
		throw new IllegalStateException("Cannot create scoped proxy for bean '" + this.targetBeanName +
				"': Target type could not be determined at the time of proxy creation.");
	}
	if (!isProxyTargetClass() || beanType.isInterface() || Modifier.isPrivate(beanType.getModifiers())) {
		pf.setInterfaces(ClassUtils.getAllInterfacesForClass(beanType, cbf.getBeanClassLoader()));
	}

	// Add an introduction that implements only the methods on ScopedObject.
	ScopedObject scopedObject = new DefaultScopedObject(cbf, this.scopedTargetSource.getTargetBeanName());
	pf.addAdvice(new DelegatingIntroductionInterceptor(scopedObject));

	// Add the AopInfrastructureBean marker to indicate that the scoped proxy
	// itself is not subject to auto-proxying! Only its target bean is.
	pf.addInterface(AopInfrastructureBean.class);

	this.proxy = pf.getProxy(cbf.getBeanClassLoader());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:ScopedProxyFactoryBean.java

示例11: createContentStore

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected Store<? extends Serializable> createContentStore() {
	Object target = getContentStoreImpl();

	// Create proxy
	ProxyFactory result = new ProxyFactory();
	result.setTarget(target);
	result.setInterfaces(new Class[] { storeInterface, Store.class, ContentStore.class });
	
	Map<Method, StoreExtension> extensionsMap = new HashMap<>();
	try {
           for (StoreExtension extension : extensions) {
               for (Method method : extension.getMethods()) {
                   extensionsMap.put(method, extension);
               }
           }
	} catch (Exception e) {
		logger.error("Failed to setup extensions", e);
	}
	StoreMethodInterceptor intercepter = new StoreMethodInterceptor((ContentStore<Object,Serializable>)target, 
																							getDomainClass(storeInterface), 
																							getContentIdClass(storeInterface), 
																							extensionsMap, 
																							publisher);
	result.addAdvice(intercepter);

	return (Store<? extends Serializable>)result.getProxy(classLoader);
}
 
开发者ID:paulcwarren,项目名称:spring-content,代码行数:29,代码来源:AbstractStoreFactoryBean.java


注:本文中的org.springframework.aop.framework.ProxyFactory.setInterfaces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。