Package org.springframework.aop

Examples of org.springframework.aop.Advisor


    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(new Class[] {ITestBean.class});
    pc.addAdvice(new NopInterceptor());
    MethodBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
    pc.addAdvisor(advisor);
    ITestBean proxied = (ITestBean) createProxy(pc);

    String proxyConfigString = ((Advised) proxied).toProxyConfigString();
    assertTrue(proxyConfigString.indexOf(advisor.toString()) != -1);
    assertTrue(proxyConfigString.indexOf("1 interface") != -1);
  }
View Full Code Here


    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(new Class[] {ITestBean.class});
    pc.addAdvice(new NopInterceptor());
    CountingBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
    pc.addAdvisor(advisor);
    assertFalse("Opaque defaults to false", pc.isOpaque());
    pc.setOpaque(true);
    assertTrue("Opaque now true for this config", pc.isOpaque());
    ITestBean proxied = (ITestBean) createProxy(pc);
View Full Code Here

    assertFalse(proxyA.equals(proxyB));
  }

  public void testBeforeAdvisorIsInvoked() {
    CountingBeforeAdvice cba = new CountingBeforeAdvice();
    Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cba) {
      public boolean matches(Method m, Class targetClass) {
        return m.getParameterTypes().length == 0;
      }
    };
    TestBean target = new TestBean();
View Full Code Here

    assertEquals(newName, tb.getName());
  }

  public void testMultiAdvice() throws Throwable {
    CountingMultiAdvice cca = new CountingMultiAdvice();
    Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cca) {
      public boolean matches(Method m, Class targetClass) {
        return m.getParameterTypes().length == 0 || "exceptional".equals(m.getName());
      }
    };
    TestBean target = new TestBean();
View Full Code Here

      public void afterReturning(Object returnValue, Method m, Object[] args, Object target) throws Throwable {
        sum += ((Integer) returnValue).intValue();
      }
    }
    SummingAfterAdvice aa = new SummingAfterAdvice();
    Advisor matchesInt = new StaticMethodMatcherPointcutAdvisor(aa) {
      public boolean matches(Method m, Class targetClass) {
        return m.getReturnType() == int.class;
      }
    };
    TestBean target = new TestBean();
View Full Code Here


  public void testThrowsAdvisorIsInvoked() throws Throwable {
    // Reacts to ServletException and RemoteException
    ThrowsAdviceInterceptorTests.MyThrowsHandler th = new ThrowsAdviceInterceptorTests.MyThrowsHandler();
    Advisor matchesEchoInvocations = new StaticMethodMatcherPointcutAdvisor(th) {
      public boolean matches(Method m, Class targetClass) {
        return m.getName().startsWith("echo");
      }
    };
View Full Code Here

    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(new Class<?>[] {ITestBean.class});
    pc.addAdvice(new NopInterceptor());
    MethodBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
    pc.addAdvisor(advisor);
    ITestBean proxied = (ITestBean) createProxy(pc);

    String proxyConfigString = ((Advised) proxied).toProxyConfigString();
    assertTrue(proxyConfigString.indexOf(advisor.toString()) != -1);
    assertTrue(proxyConfigString.indexOf("1 interface") != -1);
  }
View Full Code Here

    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(new Class<?>[] {ITestBean.class});
    pc.addAdvice(new NopInterceptor());
    CountingBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
    pc.addAdvisor(advisor);
    assertFalse("Opaque defaults to false", pc.isOpaque());
    pc.setOpaque(true);
    assertTrue("Opaque now true for this config", pc.isOpaque());
    ITestBean proxied = (ITestBean) createProxy(pc);
View Full Code Here

  }

  @Test
  public void testBeforeAdvisorIsInvoked() {
    CountingBeforeAdvice cba = new CountingBeforeAdvice();
    @SuppressWarnings("serial")
    Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cba) {
      @Override
      public boolean matches(Method m, Class<?> targetClass) {
        return m.getParameterTypes().length == 0;
      }
View Full Code Here

  }

  @Test
  public void testMultiAdvice() throws Throwable {
    CountingMultiAdvice cca = new CountingMultiAdvice();
    @SuppressWarnings("serial")
    Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cca) {
      @Override
      public boolean matches(Method m, Class<?> targetClass) {
        return m.getParameterTypes().length == 0 || "exceptional".equals(m.getName());
      }
View Full Code Here

TOP

Related Classes of org.springframework.aop.Advisor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.