Search in sources :

Example 6 with Advice

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;
        }
    }
}
Also used : Advice(org.aopalliance.aop.Advice)

Example 7 with 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));
}
Also used : NopInterceptor(org.springframework.tests.aop.interceptor.NopInterceptor) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Advice(org.aopalliance.aop.Advice) CountingBeforeAdvice(org.springframework.tests.aop.advice.CountingBeforeAdvice) Person(org.springframework.tests.sample.beans.Person) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 8 with Advice

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();
}
Also used : AspectJProxyFactory(org.springframework.aop.aspectj.annotation.AspectJProxyFactory) Advice(org.aopalliance.aop.Advice)

Aggregations

Advice (org.aopalliance.aop.Advice)8 Test (org.junit.Test)4 SimpleRabbitListenerContainerFactory (org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 CountingBeforeAdvice (org.springframework.tests.aop.advice.CountingBeforeAdvice)2 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)2 ArrayList (java.util.ArrayList)1 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)1 ExpectedException (org.junit.rules.ExpectedException)1 Message (org.springframework.amqp.core.Message)1 MessageRecoverer (org.springframework.amqp.rabbit.retry.MessageRecoverer)1 Advisor (org.springframework.aop.Advisor)1 AfterReturningAdvice (org.springframework.aop.AfterReturningAdvice)1 DynamicIntroductionAdvice (org.springframework.aop.DynamicIntroductionAdvice)1 MethodBeforeAdvice (org.springframework.aop.MethodBeforeAdvice)1 ThrowsAdvice (org.springframework.aop.ThrowsAdvice)1 AspectJProxyFactory (org.springframework.aop.aspectj.annotation.AspectJProxyFactory)1 Advised (org.springframework.aop.framework.Advised)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1