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


Java SpringProxy类代码示例

本文整理汇总了Java中org.springframework.aop.SpringProxy的典型用法代码示例。如果您正苦于以下问题:Java SpringProxy类的具体用法?Java SpringProxy怎么用?Java SpringProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testGetObjectWithFilterOnly

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
public void testGetObjectWithFilterOnly() throws Exception {
	this.serviceFactoryBean.setBundleContext(new MockBundleContext());
	this.serviceFactoryBean.setInterfaces(new Class<?>[] { Serializable.class });
	String filter = "(beanName=myBean)";
	this.serviceFactoryBean.setFilter(filter);

	MockServiceReference ref = new MockServiceReference();
	Dictionary dict = new Hashtable();
	dict.put(Constants.OBJECTCLASS, new String[] { Serializable.class.getName() });
	ref.setProperties(dict);

	serviceFactoryBean.setBeanClassLoader(getClass().getClassLoader());
	serviceFactoryBean.afterPropertiesSet();

	Object proxy = serviceFactoryBean.getObject();
	assertTrue(proxy instanceof Serializable);
	assertTrue("should be proxied", proxy instanceof SpringProxy);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:19,代码来源:OsgiSingleServiceProxyFactoryBeanTest.java

示例2: proxiedUserInterfaces

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
/**
 * Extract the user-specified interfaces that the given proxy implements,
 * i.e. all non-Advised interfaces that the proxy implements.
 * @param proxy the proxy to analyze (usually a JDK dynamic proxy)
 * @return all user-specified interfaces that the proxy implements,
 * in the original order (never {@code null} or empty)
 * @see Advised
 */
public static Class<?>[] proxiedUserInterfaces(Object proxy) {
	Class<?>[] proxyInterfaces = proxy.getClass().getInterfaces();
	int nonUserIfcCount = 0;
	if (proxy instanceof SpringProxy) {
		nonUserIfcCount++;
	}
	if (proxy instanceof Advised) {
		nonUserIfcCount++;
	}
	if (proxy instanceof DecoratingProxy) {
		nonUserIfcCount++;
	}
	Class<?>[] userInterfaces = new Class<?>[proxyInterfaces.length - nonUserIfcCount];
	System.arraycopy(proxyInterfaces, 0, userInterfaces, 0, userInterfaces.length);
	Assert.notEmpty(userInterfaces, "JDK proxy must implement one or more interfaces");
	return userInterfaces;
}
 
开发者ID:txazo,项目名称:spring,代码行数:26,代码来源:AopProxyUtils.java

示例3: testGetObjectWithFilterOnly

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
public void testGetObjectWithFilterOnly() throws Exception {
	this.serviceFactoryBean.setBundleContext(new MockBundleContext());
	this.serviceFactoryBean.setInterfaces(new Class[] { Serializable.class });
	String filter = "(beanName=myBean)";
	this.serviceFactoryBean.setFilter(filter);

	MockServiceReference ref = new MockServiceReference();
	Dictionary dict = new Hashtable();
	dict.put(Constants.OBJECTCLASS, new String[] { Serializable.class.getName() });
	ref.setProperties(dict);

	serviceFactoryBean.setBeanClassLoader(getClass().getClassLoader());
	serviceFactoryBean.afterPropertiesSet();

	Object proxy = serviceFactoryBean.getObject();
	assertTrue(proxy instanceof Serializable);
	assertTrue("should be proxied", proxy instanceof SpringProxy);
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:19,代码来源:OsgiSingleServiceProxyFactoryBeanTest.java

示例4: testProxyForUnaryCardinality

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
public void testProxyForUnaryCardinality() throws Exception {
	long time = 1234;
	Date date = new Date(time);
	ServiceRegistration reg = publishService(date);

	fb.setAvailability(Availability.MANDATORY);

	fb.setInterfaces(new Class<?>[] { Date.class });
	fb.afterPropertiesSet();

	ImportedOsgiServiceProxy refAware = null;
	try {
		Object result = fb.getObject();
		assertTrue(result instanceof Date);
		// check it's our object
		assertEquals(time, ((Date) result).getTime());
		assertTrue(result instanceof SpringProxy);
		assertTrue(result instanceof ImportedOsgiServiceProxy);
		assertTrue(result instanceof InfrastructureProxy);

		refAware = (ImportedOsgiServiceProxy) result;
		assertNotNull(refAware.getServiceReference());

		assertEquals("wrong target returned", date, ((InfrastructureProxy) result).getWrappedObject());
	}
	finally {
		if (reg != null)
			reg.unregister();
	}

	// test reference after the service went down
	assertNotNull(refAware.getServiceReference());
	assertNull(refAware.getServiceReference().getBundle());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:35,代码来源:ServiceRefAwareWithSingleServiceTest.java

示例5: SimpleServiceJDKProxyCreator

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
public SimpleServiceJDKProxyCreator(BundleContext context, Class<?>[] classes, ClassLoader loader) {
	// add Spring-DM proxies
	Object[] obj = ObjectUtils.addObjectToArray(classes, ImportedOsgiServiceProxy.class);
	this.classes = (Class[]) ObjectUtils.addObjectToArray(obj, SpringProxy.class);
	System.out.println("given classes " + ObjectUtils.nullSafeToString(classes) + " | resulting classes "
			+ ObjectUtils.nullSafeToString(this.classes));
	this.loader = loader;
	this.context = context;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:10,代码来源:SimpleServiceJDKProxyCreator.java

示例6: completeProxiedInterfaces

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
/**
 * Determine the complete set of interfaces to proxy for the given AOP configuration.
 * <p>This will always add the {@link Advised} interface unless the AdvisedSupport's
 * {@link AdvisedSupport#setOpaque "opaque"} flag is on. Always adds the
 * {@link org.springframework.aop.SpringProxy} marker interface.
 * @return the complete set of interfaces to proxy
 * @see Advised
 * @see org.springframework.aop.SpringProxy
 */
public static Class<?>[] completeProxiedInterfaces(AdvisedSupport advised) {
	Class<?>[] specifiedInterfaces = advised.getProxiedInterfaces();
	if (specifiedInterfaces.length == 0) {
		// No user-specified interfaces: check whether target class is an interface.
		Class<?> targetClass = advised.getTargetClass();
		if (targetClass != null && targetClass.isInterface()) {
			specifiedInterfaces = new Class<?>[] {targetClass};
		}
	}
	boolean addSpringProxy = !advised.isInterfaceProxied(SpringProxy.class);
	boolean addAdvised = !advised.isOpaque() && !advised.isInterfaceProxied(Advised.class);
	int nonUserIfcCount = 0;
	if (addSpringProxy) {
		nonUserIfcCount++;
	}
	if (addAdvised) {
		nonUserIfcCount++;
	}
	Class<?>[] proxiedInterfaces = new Class<?>[specifiedInterfaces.length + nonUserIfcCount];
	System.arraycopy(specifiedInterfaces, 0, proxiedInterfaces, 0, specifiedInterfaces.length);
	if (addSpringProxy) {
		proxiedInterfaces[specifiedInterfaces.length] = SpringProxy.class;
	}
	if (addAdvised) {
		proxiedInterfaces[proxiedInterfaces.length - 1] = Advised.class;
	}
	return proxiedInterfaces;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:AopProxyUtils.java

示例7: proxiedUserInterfaces

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
/**
 * Extract the user-specified interfaces that the given proxy implements,
 * i.e. all non-Advised interfaces that the proxy implements.
 * @param proxy the proxy to analyze (usually a JDK dynamic proxy)
 * @return all user-specified interfaces that the proxy implements,
 * in the original order (never {@code null} or empty)
 * @see Advised
 */
public static Class<?>[] proxiedUserInterfaces(Object proxy) {
	Class<?>[] proxyInterfaces = proxy.getClass().getInterfaces();
	int nonUserIfcCount = 0;
	if (proxy instanceof SpringProxy) {
		nonUserIfcCount++;
	}
	if (proxy instanceof Advised) {
		nonUserIfcCount++;
	}
	Class<?>[] userInterfaces = new Class<?>[proxyInterfaces.length - nonUserIfcCount];
	System.arraycopy(proxyInterfaces, 0, userInterfaces, 0, userInterfaces.length);
	Assert.notEmpty(userInterfaces, "JDK proxy must implement one or more interfaces");
	return userInterfaces;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:AopProxyUtils.java

示例8: completeProxiedInterfaces

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
/**
 * Determine the complete set of interfaces to proxy for the given AOP configuration.
 * <p>This will always add the {@link Advised} interface unless the AdvisedSupport's
 * {@link AdvisedSupport#setOpaque "opaque"} flag is on. Always adds the
 * {@link org.springframework.aop.SpringProxy} marker interface.
 * @return the complete set of interfaces to proxy
 * @see Advised
 * @see org.springframework.aop.SpringProxy
 */
public static Class<?>[] completeProxiedInterfaces(AdvisedSupport advised) {
	Class<?>[] specifiedInterfaces = advised.getProxiedInterfaces();
	if (specifiedInterfaces.length == 0) {
		// No user-specified interfaces: check whether target class is an interface.
		Class<?> targetClass = advised.getTargetClass();
		if (targetClass != null) {
			if (targetClass.isInterface()) {
				advised.setInterfaces(targetClass);
			}
			else if (Proxy.isProxyClass(targetClass)) {
				advised.setInterfaces(targetClass.getInterfaces());
			}
			specifiedInterfaces = advised.getProxiedInterfaces();
		}
	}
	boolean addSpringProxy = !advised.isInterfaceProxied(SpringProxy.class);
	boolean addAdvised = !advised.isOpaque() && !advised.isInterfaceProxied(Advised.class);
	int nonUserIfcCount = 0;
	if (addSpringProxy) {
		nonUserIfcCount++;
	}
	if (addAdvised) {
		nonUserIfcCount++;
	}
	Class<?>[] proxiedInterfaces = new Class<?>[specifiedInterfaces.length + nonUserIfcCount];
	System.arraycopy(specifiedInterfaces, 0, proxiedInterfaces, 0, specifiedInterfaces.length);
	if (addSpringProxy) {
		proxiedInterfaces[specifiedInterfaces.length] = SpringProxy.class;
	}
	if (addAdvised) {
		proxiedInterfaces[proxiedInterfaces.length - 1] = Advised.class;
	}
	return proxiedInterfaces;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:44,代码来源:AopProxyUtils.java

示例9: testCompleteProxiedInterfacesWorksWithNull

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
@Test
public void testCompleteProxiedInterfacesWorksWithNull() {
	AdvisedSupport as = new AdvisedSupport();
	Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
	assertEquals(2, completedInterfaces.length);
	List<?> ifaces = Arrays.asList(completedInterfaces);
	assertTrue(ifaces.contains(Advised.class));
	assertTrue(ifaces.contains(SpringProxy.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:AopProxyUtilsTests.java

示例10: completeProxiedInterfaces

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
/**
 * Determine the complete set of interfaces to proxy for the given AOP configuration.
 * <p>This will always add the {@link Advised} interface unless the AdvisedSupport's
 * {@link AdvisedSupport#setOpaque "opaque"} flag is on. Always adds the
 * {@link org.springframework.aop.SpringProxy} marker interface.
 * @return the complete set of interfaces to proxy
 * @see Advised
 * @see org.springframework.aop.SpringProxy
 */
public static Class[] completeProxiedInterfaces(AdvisedSupport advised) {
	Class[] specifiedInterfaces = advised.getProxiedInterfaces();
	if (specifiedInterfaces.length == 0) {
		// No user-specified interfaces: check whether target class is an interface.
		Class targetClass = advised.getTargetClass();
		if (targetClass != null && targetClass.isInterface()) {
			specifiedInterfaces = new Class[] {targetClass};
		}
	}
	boolean addSpringProxy = !advised.isInterfaceProxied(SpringProxy.class);
	boolean addAdvised = !advised.isOpaque() && !advised.isInterfaceProxied(Advised.class);
	int nonUserIfcCount = 0;
	if (addSpringProxy) {
		nonUserIfcCount++;
	}
	if (addAdvised) {
		nonUserIfcCount++;
	}
	Class[] proxiedInterfaces = new Class[specifiedInterfaces.length + nonUserIfcCount];
	System.arraycopy(specifiedInterfaces, 0, proxiedInterfaces, 0, specifiedInterfaces.length);
	if (addSpringProxy) {
		proxiedInterfaces[specifiedInterfaces.length] = SpringProxy.class;
	}
	if (addAdvised) {
		proxiedInterfaces[proxiedInterfaces.length - 1] = Advised.class;
	}
	return proxiedInterfaces;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:38,代码来源:AopProxyUtils.java

示例11: proxiedUserInterfaces

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
/**
 * Extract the user-specified interfaces that the given proxy implements,
 * i.e. all non-Advised interfaces that the proxy implements.
 * @param proxy the proxy to analyze (usually a JDK dynamic proxy)
 * @return all user-specified interfaces that the proxy implements,
 * in the original order (never {@code null} or empty)
 * @see Advised
 */
public static Class[] proxiedUserInterfaces(Object proxy) {
	Class[] proxyInterfaces = proxy.getClass().getInterfaces();
	int nonUserIfcCount = 0;
	if (proxy instanceof SpringProxy) {
		nonUserIfcCount++;
	}
	if (proxy instanceof Advised) {
		nonUserIfcCount++;
	}
	Class[] userInterfaces = new Class[proxyInterfaces.length - nonUserIfcCount];
	System.arraycopy(proxyInterfaces, 0, userInterfaces, 0, userInterfaces.length);
	Assert.notEmpty(userInterfaces, "JDK proxy must implement one or more interfaces");
	return userInterfaces;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:AopProxyUtils.java

示例12: getMeaningfulClassName

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
protected String getMeaningfulClassName(Class<?> targetClass) {
	if (java.lang.reflect.Proxy.isProxyClass(targetClass)) {
		for (Class<?> iface : targetClass.getInterfaces()) {
			if (iface != SpringProxy.class && iface != Advised.class) {
				return iface.getName();
			}
		}
	}
	return targetClass.getName();
}
 
开发者ID:virgo47,项目名称:javasimon,代码行数:11,代码来源:SpringStopwatchSource.java

示例13: testProxyForUnaryCardinality

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
public void testProxyForUnaryCardinality() throws Exception {
	long time = 1234;
	Date date = new Date(time);
	ServiceRegistration reg = publishService(date);

	fb.setCardinality(Cardinality.C_1__1);

	fb.setInterfaces(new Class[] { Date.class });
	fb.afterPropertiesSet();

	ImportedOsgiServiceProxy refAware = null;
	try {
		Object result = fb.getObject();
		assertTrue(result instanceof Date);
		// check it's our object
		assertEquals(time, ((Date) result).getTime());
		assertTrue(result instanceof SpringProxy);
		assertTrue(result instanceof ImportedOsgiServiceProxy);
		assertTrue(result instanceof InfrastructureProxy);

		refAware = (ImportedOsgiServiceProxy) result;
		assertNotNull(refAware.getServiceReference());

		assertEquals("wrong target returned", date, ((InfrastructureProxy) result).getWrappedObject());
	}
	finally {
		if (reg != null)
			reg.unregister();
	}

	// test reference after the service went down
	assertNotNull(refAware.getServiceReference());
	assertNull(refAware.getServiceReference().getBundle());
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:35,代码来源:ServiceRefAwareWithSingleServiceTest.java

示例14: SimpleServiceJDKProxyCreator

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
public SimpleServiceJDKProxyCreator(BundleContext context, Class[] classes, ClassLoader loader) {
	// add Spring-DM proxies
	Object[] obj = ObjectUtils.addObjectToArray(classes, ImportedOsgiServiceProxy.class);
	this.classes = (Class[]) ObjectUtils.addObjectToArray(obj, SpringProxy.class);
	System.out.println("given classes " + ObjectUtils.nullSafeToString(classes) + " | resulting classes "
			+ ObjectUtils.nullSafeToString(this.classes));
	this.loader = loader;
	this.context = context;
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:10,代码来源:SimpleServiceJDKProxyCreator.java

示例15: completeProxiedInterfaces

import org.springframework.aop.SpringProxy; //导入依赖的package包/类
/**
 * Determine the complete set of interfaces to proxy for the given AOP configuration.
 * <p>This will always add the {@link Advised} interface unless the AdvisedSupport's
 * {@link AdvisedSupport#setOpaque "opaque"} flag is on. Always adds the
 * {@link org.springframework.aop.SpringProxy} marker interface.
 * @param advised the proxy config
 * @param decoratingProxy whether to expose the {@link DecoratingProxy} interface
 * @return the complete set of interfaces to proxy
 * @since 4.3
 * @see SpringProxy
 * @see Advised
 * @see DecoratingProxy
 */
static Class<?>[] completeProxiedInterfaces(AdvisedSupport advised, boolean decoratingProxy) {
	Class<?>[] specifiedInterfaces = advised.getProxiedInterfaces();
	if (specifiedInterfaces.length == 0) {
		// No user-specified interfaces: check whether target class is an interface.
		Class<?> targetClass = advised.getTargetClass();
		if (targetClass != null) {
			if (targetClass.isInterface()) {
				advised.setInterfaces(targetClass);
			}
			else if (Proxy.isProxyClass(targetClass)) {
				advised.setInterfaces(targetClass.getInterfaces());
			}
			specifiedInterfaces = advised.getProxiedInterfaces();
		}
	}
	boolean addSpringProxy = !advised.isInterfaceProxied(SpringProxy.class);
	boolean addAdvised = !advised.isOpaque() && !advised.isInterfaceProxied(Advised.class);
	boolean addDecoratingProxy = (decoratingProxy && !advised.isInterfaceProxied(DecoratingProxy.class));
	int nonUserIfcCount = 0;
	if (addSpringProxy) {
		nonUserIfcCount++;
	}
	if (addAdvised) {
		nonUserIfcCount++;
	}
	if (addDecoratingProxy) {
		nonUserIfcCount++;
	}
	Class<?>[] proxiedInterfaces = new Class<?>[specifiedInterfaces.length + nonUserIfcCount];
	System.arraycopy(specifiedInterfaces, 0, proxiedInterfaces, 0, specifiedInterfaces.length);
	int index = specifiedInterfaces.length;
	if (addSpringProxy) {
		proxiedInterfaces[index] = SpringProxy.class;
		index++;
	}
	if (addAdvised) {
		proxiedInterfaces[index] = Advised.class;
		index++;
	}
	if (addDecoratingProxy) {
		proxiedInterfaces[index] = DecoratingProxy.class;
	}
	return proxiedInterfaces;
}
 
开发者ID:txazo,项目名称:spring,代码行数:58,代码来源:AopProxyUtils.java


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