• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DefaultIntroductionAdvisor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: create

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Helper method to create a {@link PermissionCheckedValue} from an existing <code>Object</code>.
 * 
 * @param object        the <code>Object</code> to proxy
 * @return                  a <code>Object</code> of the same type but including the
 *                          {@link PermissionCheckedValue} interface
 */
@SuppressWarnings("unchecked")
public static final <T extends Object> T create(T object)
{
    // Create the mixin
    DelegatingIntroductionInterceptor mixin = new PermissionCheckedValueMixin();
    // Create the advisor
    IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckedValue.class);
    // Proxy
    ProxyFactory pf = new ProxyFactory(object);
    pf.addAdvisor(advisor);
    Object proxiedObject = pf.getProxy();
    
    // Done
    return (T) proxiedObject;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:PermissionCheckedValue.java


示例2: create

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Helper method to create a {@link PermissionCheckedCollection} from an existing <code>Collection</code>
 * 
 * @param <TT>              the type of the <code>Collection</code>
 * @param collection        the <code>Collection</code> to proxy
 * @param isCutOff          <tt>true</tt> if permission checking was cut off before completion
 * @param sizeUnchecked     number of entries from the original collection that were not checked
 * @param sizeOriginal      number of entries in the original, pre-checked collection
 * @return                  a <code>Collection</code> of the same type but including the
 *                          {@link PermissionCheckedCollection} interface
 */
@SuppressWarnings("unchecked")
public static final <TT> Collection<TT> create(
        Collection<TT> collection,
        boolean isCutOff, int sizeUnchecked, int sizeOriginal)
{
    // Create the mixin
    DelegatingIntroductionInterceptor mixin = new PermissionCheckedCollectionMixin<Integer>(
            isCutOff,
            sizeUnchecked,
            sizeOriginal
            );
    // Create the advisor
    IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckedCollection.class);
    // Proxy
    ProxyFactory pf = new ProxyFactory(collection);
    pf.addAdvisor(advisor);
    Object proxiedObject = pf.getProxy();
    
    // Done
    return (Collection<TT>) proxiedObject;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:33,代码来源:PermissionCheckedCollection.java


示例3: create

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Helper method to create a {@link PermissionCheckCollection} from an existing <code>Collection</code>
 * 
 * @param <TT>              the type of the <code>Collection</code>
 * @param collection        the <code>Collection</code> to proxy
 * @param targetResultCount the desired number of results or default to the collection size
 * @param cutOffAfterTimeMs the number of milliseconds to wait before cut-off or zero to use the system default
 *                          time-based cut-off.
 * @param cutOffAfterCount  the number of permission checks to process before cut-off or zero to use the system default
 *                          count-based cut-off.
 * @return                  a <code>Collection</code> of the same type but including the
 *                          {@link PermissionCheckCollection} interface
 */
@SuppressWarnings("unchecked")
public static final <TT> Collection<TT> create(
        Collection<TT> collection,
        int targetResultCount, long cutOffAfterTimeMs, int cutOffAfterCount)
{
    if (targetResultCount <= 0)
    {
        targetResultCount = collection.size();
    }
    // Create the mixin
    DelegatingIntroductionInterceptor mixin = new PermissionCheckCollectionMixin<Integer>(
            targetResultCount,
            cutOffAfterTimeMs,
            cutOffAfterCount);
    // Create the advisor
    IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckCollection.class);
    // Proxy
    ProxyFactory pf = new ProxyFactory(collection);
    pf.addAdvisor(advisor);
    Object proxiedObject = pf.getProxy();
    
    // Done
    return (Collection<TT>) proxiedObject;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:38,代码来源:PermissionCheckCollection.java


示例4: addAdvice

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Cannot add introductions this way unless the advice implements IntroductionInfo.
 */
@Override
public void addAdvice(int pos, Advice advice) throws AopConfigException {
	Assert.notNull(advice, "Advice must not be null");
	if (advice instanceof IntroductionInfo) {
		// We don't need an IntroductionAdvisor for this kind of introduction:
		// It's fully self-describing.
		addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice));
	}
	else if (advice instanceof DynamicIntroductionAdvice) {
		// We need an IntroductionAdvisor for this kind of introduction.
		throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor");
	}
	else {
		addAdvisor(pos, new DefaultPointcutAdvisor(advice));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:AdvisedSupport.java


示例5: DynamicAsyncInterfaceBean

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
public DynamicAsyncInterfaceBean() {
	ProxyFactory pf = new ProxyFactory(new HashMap<>());
	DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
		@Override
		public Object invoke(MethodInvocation invocation) throws Throwable {
			assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
			if (Future.class.equals(invocation.getMethod().getReturnType())) {
				return new AsyncResult<String>(invocation.getArguments()[0].toString());
			}
			return null;
		}
	});
	advisor.addInterface(AsyncInterface.class);
	pf.addAdvisor(advisor);
	this.proxy = (AsyncInterface) pf.getProxy();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AsyncExecutionTests.java


示例6: DynamicAsyncMethodsInterfaceBean

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
public DynamicAsyncMethodsInterfaceBean() {
	ProxyFactory pf = new ProxyFactory(new HashMap<>());
	DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
		@Override
		public Object invoke(MethodInvocation invocation) throws Throwable {
			assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
			if (Future.class.equals(invocation.getMethod().getReturnType())) {
				return new AsyncResult<String>(invocation.getArguments()[0].toString());
			}
			return null;
		}
	});
	advisor.addInterface(AsyncMethodsInterface.class);
	pf.addAdvisor(advisor);
	this.proxy = (AsyncMethodsInterface) pf.getProxy();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AsyncExecutionTests.java


示例7: testRejectsBogusDynamicIntroductionAdviceWithNoAdapter

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
@Test
public void testRejectsBogusDynamicIntroductionAdviceWithNoAdapter() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);
	pc.addAdvisor(new DefaultIntroductionAdvisor(new DummyIntroductionAdviceImpl(), Comparable.class));
	try {
		// TODO May fail on either call: may want to tighten up definition
		ITestBean proxied = (ITestBean) createProxy(pc);
		proxied.getName();
		fail("Bogus introduction");
	}
	catch (Exception ex) {
		// TODO used to catch UnknownAdviceTypeException, but
		// with CGLIB some errors are in proxy creation and are wrapped
		// in aspect exception. Error message is still fine.
		//assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AbstractAopProxyTests.java


示例8: testCannotAddIntroductionAdviceWithUnimplementedInterface

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Check that the introduction advice isn't allowed to introduce interfaces
 * that are unsupported by the IntroductionInterceptor.
 */
@Test
public void testCannotAddIntroductionAdviceWithUnimplementedInterface() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);
	try {
		pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), ITestBean.class));
		fail("Shouldn't be able to add introduction advice introducing an unimplemented interface");
	}
	catch (IllegalArgumentException ex) {
		//assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
	}
	// Check it still works: proxy factory state shouldn't have been corrupted
	ITestBean proxied = (ITestBean) createProxy(pc);
	assertEquals(target.getAge(), proxied.getAge());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:AbstractAopProxyTests.java


示例9: testCannotAddIntroductionAdviceToIntroduceClass

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Should only be able to introduce interfaces, not classes.
 */
@Test
public void testCannotAddIntroductionAdviceToIntroduceClass() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);
	try {
		pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), TestBean.class));
		fail("Shouldn't be able to add introduction advice that introduces a class, rather than an interface");
	}
	catch (IllegalArgumentException ex) {
		assertTrue(ex.getMessage().indexOf("interface") > -1);
	}
	// Check it still works: proxy factory state shouldn't have been corrupted
	ITestBean proxied = (ITestBean) createProxy(pc);
	assertEquals(target.getAge(), proxied.getAge());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AbstractAopProxyTests.java


示例10: testUseAsHashKey

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
@Test
public void testUseAsHashKey() {
	TestBean target1 = new TestBean();
	ProxyFactory pf1 = new ProxyFactory(target1);
	pf1.addAdvice(new NopInterceptor());
	ITestBean proxy1 = (ITestBean) createProxy(pf1);

	TestBean target2 = new TestBean();
	ProxyFactory pf2 = new ProxyFactory(target2);
	pf2.addAdvisor(new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor()));
	ITestBean proxy2 = (ITestBean) createProxy(pf2);

	HashMap<ITestBean, Object> h = new HashMap<ITestBean, Object>();
	Object value1 = "foo";
	Object value2 = "bar";
	assertNull(h.get(proxy1));
	h.put(proxy1, value1);
	h.put(proxy2, value2);
	assertEquals(h.get(proxy1), value1);
	assertEquals(h.get(proxy2), value2);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:AbstractAopProxyTests.java


示例11: addAdvice

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Cannot add introductions this way unless the advice implements IntroductionInfo.
 */
public void addAdvice(int pos, Advice advice) throws AopConfigException {
	Assert.notNull(advice, "Advice must not be null");
	if (advice instanceof IntroductionInfo) {
		// We don't need an IntroductionAdvisor for this kind of introduction:
		// It's fully self-describing.
		addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice));
	}
	else if (advice instanceof DynamicIntroductionAdvice) {
		// We need an IntroductionAdvisor for this kind of introduction.
		throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor");
	}
	else {
		addAdvisor(pos, new DefaultPointcutAdvisor(advice));
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:AdvisedSupport.java


示例12: testGetsAllInterfaces

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
@Test
public void testGetsAllInterfaces() throws Exception {
	// Extend to get new interface
	class TestBeanSubclass extends TestBean implements Comparable<Object> {
		@Override
		public int compareTo(Object arg0) {
			throw new UnsupportedOperationException("compareTo");
		}
	}
	TestBeanSubclass raw = new TestBeanSubclass();
	ProxyFactory factory = new ProxyFactory(raw);
	//System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
	assertEquals("Found correct number of interfaces", 5, factory.getProxiedInterfaces().length);
	ITestBean tb = (ITestBean) factory.getProxy();
	assertThat("Picked up secondary interface", tb, instanceOf(IOther.class));

	raw.setAge(25);
	assertTrue(tb.getAge() == raw.getAge());

	long t = 555555L;
	TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);

	Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();

	factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));

	Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
	assertEquals("Advisor proxies one more interface after introduction", oldProxiedInterfaces.length + 1, newProxiedInterfaces.length);

	TimeStamped ts = (TimeStamped) factory.getProxy();
	assertTrue(ts.getTimeStamp() == t);
	// Shouldn't fail;
	 ((IOther) ts).absquatulate();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:35,代码来源:ProxyFactoryTests.java


示例13: testIntroductionThrowsUncheckedException

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Note that an introduction can't throw an unexpected checked exception,
 * as it's constained by the interface.
 */
@Test
public void testIntroductionThrowsUncheckedException() throws Throwable {
	TestBean target = new TestBean();
	target.setAge(21);
	ProxyFactory pc = new ProxyFactory(target);

	@SuppressWarnings("serial")
	class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped {
		/**
		 * @see test.util.TimeStamped#getTimeStamp()
		 */
		@Override
		public long getTimeStamp() {
			throw new UnsupportedOperationException();
		}
	}
	pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi()));

	TimeStamped ts = (TimeStamped) createProxy(pc);
	try {
		ts.getTimeStamp();
		fail("Should throw UnsupportedOperationException");
	}
	catch (UnsupportedOperationException ex) {
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:AbstractAopProxyTests.java


示例14: getPoolingConfigMixin

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Return an IntroductionAdvisor that providing a mixin
 * exposing statistics about the pool maintained by this object.
 */
public DefaultIntroductionAdvisor getPoolingConfigMixin() {
	DelegatingIntroductionInterceptor dii = new DelegatingIntroductionInterceptor(this);
	return new DefaultIntroductionAdvisor(dii, PoolingConfig.class);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:AbstractPoolingTargetSource.java


示例15: getStatsMixin

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Return an introduction advisor mixin that allows the AOP proxy to be
 * cast to ThreadLocalInvokerStats.
 */
public IntroductionAdvisor getStatsMixin() {
	DelegatingIntroductionInterceptor dii = new DelegatingIntroductionInterceptor(this);
	return new DefaultIntroductionAdvisor(dii, ThreadLocalTargetSourceStats.class);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:ThreadLocalTargetSource.java


示例16: testCanAddAndRemoveAspectInterfacesOnSingleton

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Should see effect immediately on behavior.
 */
@Test
public void testCanAddAndRemoveAspectInterfacesOnSingleton() {
	ProxyFactory config = new ProxyFactory(new TestBean());

	assertFalse("Shouldn't implement TimeStamped before manipulation",
			config.getProxy() instanceof TimeStamped);

	long time = 666L;
	TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
	ti.setTime(time);

	// Add to front of interceptor chain
	int oldCount = config.getAdvisors().length;
	config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));

	assertTrue(config.getAdvisors().length == oldCount + 1);

	TimeStamped ts = (TimeStamped) config.getProxy();
	assertTrue(ts.getTimeStamp() == time);

	// Can remove
	config.removeAdvice(ti);

	assertTrue(config.getAdvisors().length == oldCount);

	try {
		// Existing reference will fail
		ts.getTimeStamp();
		fail("Existing object won't implement this interface any more");
	}
	catch (RuntimeException ex) {
	}

	assertFalse("Should no longer implement TimeStamped",
			config.getProxy() instanceof TimeStamped);

	// Now check non-effect of removing interceptor that isn't there
	config.removeAdvice(new DebugInterceptor());

	assertTrue(config.getAdvisors().length == oldCount);

	ITestBean it = (ITestBean) ts;
	DebugInterceptor debugInterceptor = new DebugInterceptor();
	config.addAdvice(0, debugInterceptor);
	it.getSpouse();
	assertEquals(1, debugInterceptor.getCount());
	config.removeAdvice(debugInterceptor);
	it.getSpouse();
	// not invoked again
	assertTrue(debugInterceptor.getCount() == 1);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:55,代码来源:ProxyFactoryTests.java


示例17: testCanAddAndRemoveAspectInterfacesOnPrototype

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Try adding and removing interfaces and interceptors on prototype.
 * Changes will only affect future references obtained from the factory.
 * Each instance will be independent.
 */
@Test
public void testCanAddAndRemoveAspectInterfacesOnPrototype() {
	assertThat("Shouldn't implement TimeStamped before manipulation",
			factory.getBean("test2"), not(instanceOf(TimeStamped.class)));

	ProxyFactoryBean config = (ProxyFactoryBean) factory.getBean("&test2");
	long time = 666L;
	TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
	ti.setTime(time);
	// Add to head of interceptor chain
	int oldCount = config.getAdvisors().length;
	config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
	assertTrue(config.getAdvisors().length == oldCount + 1);

	TimeStamped ts = (TimeStamped) factory.getBean("test2");
	assertEquals(time, ts.getTimeStamp());

	// Can remove
	config.removeAdvice(ti);
	assertTrue(config.getAdvisors().length == oldCount);

	// Check no change on existing object reference
	assertTrue(ts.getTimeStamp() == time);

	assertThat("Should no longer implement TimeStamped",
			factory.getBean("test2"), not(instanceOf(TimeStamped.class)));

	// Now check non-effect of removing interceptor that isn't there
	config.removeAdvice(new DebugInterceptor());
	assertTrue(config.getAdvisors().length == oldCount);

	ITestBean it = (ITestBean) ts;
	DebugInterceptor debugInterceptor = new DebugInterceptor();
	config.addAdvice(0, debugInterceptor);
	it.getSpouse();
	// Won't affect existing reference
	assertTrue(debugInterceptor.getCount() == 0);
	it = (ITestBean) factory.getBean("test2");
	it.getSpouse();
	assertEquals(1, debugInterceptor.getCount());
	config.removeAdvice(debugInterceptor);
	it.getSpouse();

	// Still invoked wiht old reference
	assertEquals(2, debugInterceptor.getCount());

	// not invoked with new object
	it = (ITestBean) factory.getBean("test2");
	it.getSpouse();
	assertEquals(2, debugInterceptor.getCount());

	// Our own timestamped reference should still work
	assertEquals(time, ts.getTimeStamp());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:60,代码来源:ProxyFactoryBeanTests.java


示例18: createAdvisorIntroducingNamedBean

import org.springframework.aop.support.DefaultIntroductionAdvisor; //导入依赖的package包/类
/**
 * Create a new advisor that will expose the given bean name, introducing
 * the NamedBean interface to make the bean name accessible without forcing
 * the target object to be aware of this Spring IoC concept.
 * @param beanName the bean name to expose
 */
public static Advisor createAdvisorIntroducingNamedBean(String beanName) {
	return new DefaultIntroductionAdvisor(new ExposeBeanNameIntroduction(beanName));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:ExposeBeanNameAdvisors.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ReadWriteAccessDetector类代码示例发布时间:2022-05-22
下一篇:
Java AbstractClientConnector类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap