Control Flow Pointcut : Pointcut « Spring « Java Tutorial






File: Main.java

import java.lang.reflect.Method;

import org.springframework.aop.Advisor;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.ControlFlowPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;

public class Main {
  public static void main(String[] args) {
    TestBean target = new TestBean();

    Pointcut pc = new ControlFlowPointcut(Main.class, "test");
    Advisor advisor = new DefaultPointcutAdvisor(pc, new SimpleBeforeAdvice());

    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(target);
    pf.addAdvisor(advisor);

    TestBean proxy = (TestBean) pf.getProxy();

    proxy.foo();
    test(proxy);

  }

  static void test(TestBean bean) {
    bean.foo();
  }
}

class TestBean {

  public void foo() {
    System.out.println("foo");
  }

}

class SimpleBeforeAdvice implements MethodBeforeAdvice {

  public void before(Method method, Object[] args, Object target) throws Throwable {
    System.out.println("Before method " + method);
  }
}
  Download:  Spring-ControlFlowPointcut.zip( 4,745 k)








28.56.Pointcut
28.56.1.Default Pointcut Advisor
28.56.2.Control Flow Pointcut
28.56.3.ComposablePointcut Union
28.56.4.ComposablePointcut Intersection
28.56.5.Class Filter In DynamicMethodMatcherPointcut
28.56.6.NameMatchMethodPointcutAdvisor
28.56.7.NameMatchMethodPointcut
28.56.8.Jdk Regexp based Method Pointcut
28.56.9.All Kinds Of Pointcut