當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。