Search in sources :

Example 71 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class NameMatchMethodPointcutTests method setUp.

/**
	 * Create an empty pointcut, populating instance variables.
	 */
@Before
public void setUp() {
    ProxyFactory pf = new ProxyFactory(new SerializablePerson());
    nop = new SerializableNopInterceptor();
    pc = new NameMatchMethodPointcut();
    pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
    proxied = (Person) pf.getProxy();
}
Also used : SerializableNopInterceptor(org.springframework.tests.aop.interceptor.SerializableNopInterceptor) ProxyFactory(org.springframework.aop.framework.ProxyFactory) SerializablePerson(org.springframework.tests.sample.beans.SerializablePerson) Before(org.junit.Before)

Example 72 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class ExposeBeanNameAdvisorsTests method testWithIntroduction.

@Test
public void testWithIntroduction() {
    String beanName = "foo";
    TestBean target = new RequiresBeanNameBoundTestBean(beanName);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorIntroducingNamedBean(beanName));
    ITestBean proxy = (ITestBean) pf.getProxy();
    assertTrue("Introduction was made", proxy instanceof NamedBean);
    // Requires binding
    proxy.getAge();
    NamedBean nb = (NamedBean) proxy;
    assertEquals("Name returned correctly", beanName, nb.getBeanName());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) NamedBean(org.springframework.beans.factory.NamedBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 73 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class ExposeBeanNameAdvisorsTests method testNoIntroduction.

@Test
public void testNoIntroduction() {
    String beanName = "foo";
    TestBean target = new RequiresBeanNameBoundTestBean(beanName);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorWithoutIntroduction(beanName));
    ITestBean proxy = (ITestBean) pf.getProxy();
    assertFalse("No introduction", proxy instanceof NamedBean);
    // Requires binding
    proxy.getAge();
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) NamedBean(org.springframework.beans.factory.NamedBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 74 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class PerThisAspect method createProxy.

protected Object createProxy(Object target, List<Advisor> advisors, Class<?>... interfaces) {
    ProxyFactory pf = new ProxyFactory(target);
    if (interfaces.length > 1 || interfaces[0].isInterface()) {
        pf.setInterfaces(interfaces);
    } else {
        pf.setProxyTargetClass(true);
    }
    // Required everywhere we use AspectJ proxies
    pf.addAdvice(ExposeInvocationInterceptor.INSTANCE);
    for (Object a : advisors) {
        pf.addAdvisor((Advisor) a);
    }
    pf.setExposeProxy(true);
    return pf.getProxy();
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory)

Example 75 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class CallCountingInterceptor method getAdvisedProxy.

private TestBean getAdvisedProxy(String pointcutExpression, CallCountingInterceptor interceptor) {
    TestBean target = new TestBean();
    Pointcut pointcut = getPointcut(pointcutExpression);
    DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
    advisor.setAdvice(interceptor);
    advisor.setPointcut(pointcut);
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(target);
    pf.addAdvisor(advisor);
    return (TestBean) pf.getProxy();
}
Also used : Pointcut(org.springframework.aop.Pointcut) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor)

Aggregations

ProxyFactory (org.springframework.aop.framework.ProxyFactory)81 Test (org.junit.Test)49 ITestBean (org.springframework.tests.sample.beans.ITestBean)20 TestBean (org.springframework.tests.sample.beans.TestBean)20 TimeStamped (org.springframework.tests.TimeStamped)8 INestedTestBean (org.springframework.tests.sample.beans.INestedTestBean)8 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)8 Method (java.lang.reflect.Method)6 HashMap (java.util.HashMap)5 MethodBeforeAdvice (org.springframework.aop.MethodBeforeAdvice)4 Context (javax.naming.Context)3 TargetSource (org.springframework.aop.TargetSource)3 Advised (org.springframework.aop.framework.Advised)3 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)3 Factory (org.springframework.cglib.proxy.Factory)3 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)3 IOException (java.io.IOException)2 EJBLocalObject (javax.ejb.EJBLocalObject)2 Message (javax.jms.Message)2 TextMessage (javax.jms.TextMessage)2