use of org.aopalliance.aop.Advice in project spring-framework by spring-projects.
the class AbstractBeanFactoryPointcutAdvisor method getAdvice.
@Override
public Advice getAdvice() {
Advice advice = this.advice;
if (advice != null || this.adviceBeanName == null) {
return advice;
}
Assert.state(this.beanFactory != null, "BeanFactory must be set to resolve 'adviceBeanName'");
if (this.beanFactory.isSingleton(this.adviceBeanName)) {
// Rely on singleton semantics provided by the factory.
advice = this.beanFactory.getBean(this.adviceBeanName, Advice.class);
this.advice = advice;
return advice;
} else {
// of our advice bean happens to trigger the singleton lock implicitly...
synchronized (this.adviceMonitor) {
if (this.advice == null) {
this.advice = this.beanFactory.getBean(this.adviceBeanName, Advice.class);
}
return this.advice;
}
}
}
use of org.aopalliance.aop.Advice in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testSerializableSingletonProxy.
@Test
public void testSerializableSingletonProxy() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializableSingleton");
assertSame("Should be a Singleton", p, bf.getBean("serializableSingleton"));
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(p, p2);
assertNotSame(p, p2);
assertEquals("serializableSingleton", p2.getName());
// Add unserializable advice
Advice nop = new NopInterceptor();
((Advised) p).addAdvice(nop);
// Check it still works
assertEquals(p2.getName(), p2.getName());
assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
// Remove offending interceptor...
assertTrue(((Advised) p).removeAdvice(nop));
assertTrue("Serializable again because offending interceptor was removed", SerializationTestUtils.isSerializable(p));
}
use of org.aopalliance.aop.Advice in project uPortal by Jasig.
the class AspectApplyingAspect method applyAspect.
public Object applyAspect(ProceedingJoinPoint pjp) throws Throwable {
final Object result = pjp.proceed();
if (result == null) {
return result;
}
final AspectJProxyFactory portletPreferencesProxyFactory = new AspectJProxyFactory(result);
for (final Advice advice : this.advices) {
portletPreferencesProxyFactory.addAdvice(advice);
}
return portletPreferencesProxyFactory.getProxy();
}
Aggregations