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


Java Advised类代码示例

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


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

示例1: clear

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
private void clear(TokenStore tokenStore) throws Exception {
	if (tokenStore instanceof Advised) {
		Advised advised = (Advised) tokenStore;
		TokenStore target = (TokenStore) advised.getTargetSource().getTarget();
		clear(target);
		return;
	}
	if (tokenStore instanceof InMemoryTokenStore) {
		((InMemoryTokenStore) tokenStore).clear();
	}
	if (tokenStore instanceof JdbcTokenStore) {
		JdbcTemplate template = new JdbcTemplate(dataSource);
		template.execute("delete from oauth_access_token");
		template.execute("delete from oauth_refresh_token");
		template.execute("delete from oauth_client_token");
		template.execute("delete from oauth_code");
	}
}
 
开发者ID:jfcorugedo,项目名称:spring-oauth2-samples,代码行数:19,代码来源:AbstractIntegrationTests.java

示例2: unwrapProxy

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
public static <T> T unwrapProxy(final Class<T> clazz, final Object proxy) {
    Object target = proxy;

    if (AopUtils.isAopProxy(proxy) && proxy instanceof Advised) {
        try {
            target = Advised.class.cast(proxy).getTargetSource().getTarget();
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }

    if (target != null && clazz.isAssignableFrom(target.getClass())) {
        return clazz.cast(target);
    }

    throw new IllegalArgumentException("proxy object does not represent given class: " + clazz.getSimpleName());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:18,代码来源:TestUtils.java

示例3: testSerializable

import org.springframework.aop.framework.Advised; //导入依赖的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

示例4: customAsyncAnnotationIsPropagated

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
@Test
public void customAsyncAnnotationIsPropagated() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(CustomAsyncAnnotationConfig.class);
	ctx.refresh();

	Object bean = ctx.getBean(CustomAsyncBean.class);
	assertTrue(AopUtils.isAopProxy(bean));
	boolean isAsyncAdvised = false;
	for (Advisor advisor : ((Advised)bean).getAdvisors()) {
		if (advisor instanceof AsyncAnnotationAdvisor) {
			isAsyncAdvised = true;
			break;
		}
	}
	assertTrue("bean was not async advised as expected", isAsyncAdvised);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:EnableAsyncTests.java

示例5: testAdviseWithProxyFactoryBean

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
@Test
public void testAdviseWithProxyFactoryBean() {
	ClassPathXmlApplicationContext ctx =
		new ClassPathXmlApplicationContext(FACTORYBEAN_CONTEXT, CLASS);
	try {
		Messenger bean = (Messenger) ctx.getBean("messenger");
		assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean));
		assertTrue("Bean is not an Advised object", bean instanceof Advised);

		CountingBeforeAdvice advice = (CountingBeforeAdvice) ctx.getBean("advice");
		assertEquals(0, advice.getCalls());
		bean.getMessage();
		assertEquals(1, advice.getCalls());
	} finally {
		ctx.close();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:AdvisedJRubyScriptFactoryTests.java

示例6: testAdviseWithBeanNameAutoProxyCreator

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
@Test
public void testAdviseWithBeanNameAutoProxyCreator() {
	ClassPathXmlApplicationContext ctx =
		new ClassPathXmlApplicationContext(APC_CONTEXT, CLASS);
	try {
		Messenger bean = (Messenger) ctx.getBean("messenger");
		assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean));
		assertTrue("Bean is not an Advised object", bean instanceof Advised);

		CountingBeforeAdvice advice = (CountingBeforeAdvice) ctx.getBean("advice");
		assertEquals(0, advice.getCalls());
		bean.getMessage();
		assertEquals(1, advice.getCalls());
	} finally {
		ctx.close();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:AdvisedJRubyScriptFactoryTests.java

示例7: eventListenerWorksWithSimpleInterfaceProxy

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
@Test
public void eventListenerWorksWithSimpleInterfaceProxy() throws Exception {
	load(ScopedProxyTestBean.class);

	SimpleService proxy = this.context.getBean(SimpleService.class);
	assertTrue("bean should be a proxy", proxy instanceof Advised);
	this.eventCollector.assertNoEventReceived(proxy.getId());

	this.context.publishEvent(new ContextRefreshedEvent(this.context));
	this.eventCollector.assertNoEventReceived(proxy.getId());

	TestEvent event = new TestEvent();
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(proxy.getId(), event);
	this.eventCollector.assertTotalEventsCount(1);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AnnotationDrivenEventListenerTests.java

示例8: eventListenerWorksWithAnnotatedInterfaceProxy

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
@Test
public void eventListenerWorksWithAnnotatedInterfaceProxy() throws Exception {
	load(AnnotatedProxyTestBean.class);

	AnnotatedSimpleService proxy = this.context.getBean(AnnotatedSimpleService.class);
	assertTrue("bean should be a proxy", proxy instanceof Advised);
	this.eventCollector.assertNoEventReceived(proxy.getId());

	this.context.publishEvent(new ContextRefreshedEvent(this.context));
	this.eventCollector.assertNoEventReceived(proxy.getId());

	TestEvent event = new TestEvent();
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(proxy.getId(), event);
	this.eventCollector.assertTotalEventsCount(1);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AnnotationDrivenEventListenerTests.java

示例9: testProgrammaticProxyCreation

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
@Test
public void testProgrammaticProxyCreation() {
	ITestBean testBean = new TestBean();

	AspectJProxyFactory factory = new AspectJProxyFactory();
	factory.setTarget(testBean);

	CounterAspect myCounterAspect = new CounterAspect();
	factory.addAspect(myCounterAspect);

	ITestBean proxyTestBean = factory.getProxy();

	assertTrue("Expected a proxy", proxyTestBean instanceof Advised);
	proxyTestBean.setAge(20);
	assertEquals("Programmatically created proxy shouldn't match bean()", 0, myCounterAspect.count);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:BeanNamePointcutAtAspectTests.java

示例10: setUp

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	ClassPathXmlApplicationContext ctx =
		new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());

	afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect");

	mockCollaborator = mock(AfterReturningAdviceBindingCollaborator.class);
	afterAdviceAspect.setCollaborator(mockCollaborator);

	testBeanProxy = (ITestBean) ctx.getBean("testBean");
	assertTrue(AopUtils.isAopProxy(testBeanProxy));

	// we need the real target too, not just the proxy...
	this.testBeanTarget = (TestBean) ((Advised)testBeanProxy).getTargetSource().getTarget();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AfterReturningAdviceBindingTests.java

示例11: onSetUp

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
@Before
public void onSetUp() throws Exception {
	ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());

	AroundAdviceBindingTestAspect  aroundAdviceAspect = ((AroundAdviceBindingTestAspect) ctx.getBean("testAspect"));

	ITestBean injectedTestBean = (ITestBean) ctx.getBean("testBean");
	assertTrue(AopUtils.isAopProxy(injectedTestBean));

	this.testBeanProxy = injectedTestBean;
	// we need the real target too, not just the proxy...

	this.testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();

	mockCollaborator = mock(AroundAdviceBindingCollaborator.class);
	aroundAdviceAspect.setCollaborator(mockCollaborator);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:AroundAdviceBindingTests.java

示例12: testBeforeAdviceWithoutJoinPoint

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

	StopWatch sw = new StopWatch();
	sw.start(howmany + " repeated before advice invocations with " + technology);
	ITestBean adrian = (ITestBean) bf.getBean("adrian");

	assertTrue(AopUtils.isAopProxy(adrian));
	Advised a = (Advised) adrian;
	assertTrue(a.getAdvisors().length >= 3);
	assertEquals("adrian", adrian.getName());

	for (int i = 0; i < howmany; i++) {
		adrian.getName();
	}

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:BenchmarkTests.java

示例13: testAfterReturningAdviceWithoutJoinPoint

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

	StopWatch sw = new StopWatch();
	sw.start(howmany + " repeated after returning advice invocations with " + technology);
	ITestBean adrian = (ITestBean) bf.getBean("adrian");

	assertTrue(AopUtils.isAopProxy(adrian));
	Advised a = (Advised) adrian;
	assertTrue(a.getAdvisors().length >= 3);
	// Hits joinpoint
	adrian.setAge(25);

	for (int i = 0; i < howmany; i++) {
		adrian.setAge(i);
	}

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:BenchmarkTests.java

示例14: setUp

import org.springframework.aop.framework.Advised; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	ClassPathXmlApplicationContext ctx =
		new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());

	testBeanProxy = (ITestBean) ctx.getBean("testBean");
	assertTrue(AopUtils.isAopProxy(testBeanProxy));

	// we need the real target too, not just the proxy...
	testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();

	AdviceBindingTestAspect beforeAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");

	mockCollaborator = mock(AdviceBindingCollaborator.class);
	beforeAdviceAspect.setCollaborator(mockCollaborator);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:BeforeAdviceBindingTests.java

示例15: serializable

import org.springframework.aop.framework.Advised; //导入依赖的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


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