Java Code Examples for org.springframework.aop.support.DefaultPointcutAdvisor

Following code examples demonstrate how to use org.springframework.aop.support.DefaultPointcutAdvisorfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.aop.support.DefaultPointcutAdvisorand various code implementation of this class.

    public static void main(String[] args) {
        RegexBean target = new RegexBean();
        JdkRegexpMethodPointcut pc = new JdkRegexpMethodPointcut();
        pc.setPattern(".*foo.*");
        Advisor advisor = new DefaultPointcutAdvisor( pc, new SimpleAdvice());
        ProxyFactory factory = new ProxyFactory();
        factory.addAdvisor(advisor);
        factory.setTarget(target);

        RegexBean proxy = (RegexBean) factory.getProxy();

        proxy.foo1();
        proxy.foo2();
        proxy.bar();

    } 


	public static void main(String[] args) {

		Advice advice = new MyAdvice();

		AnnotationMatchingPointcut pointcut = AnnotationMatchingPointcut
				.forMethodAnnotation(AdviceRequired.class);

		Advisor advisor = new DefaultPointcutAdvisor(pointcut, advice);

		ProxyFactory factory = new ProxyFactory();
		factory.setTarget(new First());
		factory.addAdvisor(advisor);

		First f = (First) factory.getProxy();
		f.one();
		f.one2();
		f.two();
		f.add(2, 3);

		System.out.println();

		ProxyFactory factory2 = new ProxyFactory();
		factory2.setTarget(new Second());
		factory2.addAdvisor(advisor);

		Second s = (Second) factory2.getProxy();
		s.one();
		s.one2();
		s.two();
		s.add(2, 3);
	} 

	public static void main(String[] args) {
		ProxyFactory pf = new ProxyFactory();
		pf.setTarget(new Calculator());
		pf.addAdvisor(new DefaultPointcutAdvisor(new LoggingDynamicPointcut(), new LoggingAdvice()));
		
		Calculator proxy = (Calculator) pf.getProxy();
		int sum = proxy.add(101, 201);
		System.out.println("Sum: "+sum);
		
		int mul = proxy.multiply(10, 5);
		System.out.println("Multiply: "+mul);
		
	} 

    public static void main(String[] args) {
        SampleBean target = new SampleBean();
        Advisor advisor = new DefaultPointcutAdvisor(new SimpleDynamicPoincut(),new com.apress.prospring4.ch5AOP.dynamicpointcut.SimpleAdvice());
        ProxyFactory factory = new ProxyFactory();
        factory.setTarget(target);
        factory.addAdvisor(advisor);
        SampleBean proxy =(SampleBean) factory.getProxy();
        proxy.foo(1);
        proxy.foo(10);
        proxy.foo(100);
        proxy.bar();
        proxy.bar();
        proxy.bar();


    } 

	public Advisor performanceMonitorAdvisor() {
		AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
		pointcut.setExpression("pl.entito.demo.PerformanceMonitorConfiguration.monitor()");
		return new DefaultPointcutAdvisor(pointcut, performanceMonitorInterceptor());
	} 

    public static void main(String[] args) {
        AspectjexpBean target = new AspectjexpBean();
        AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
        pc.setExpression("execution(* foo*(..))");
        Advisor advisor = new DefaultPointcutAdvisor(pc,new SimpleAdvice());
        ProxyFactory factory = new ProxyFactory();
        factory.setTarget(target);
        factory.addAdvisor(advisor);

        AspectjexpBean proxy = (AspectjexpBean) factory.getProxy();

        proxy.foo1();
        proxy.foo2();
        proxy.bar();
    } 

Advertisement
Javadoc
Convenient Pointcut-driven Advisor implementation.

This is the most commonly used Advisor

implementation. It can be used with any pointcut and advice type, except for introductions. There is normally no need to subclass this class, or to implement custom Advisors. @author Rod Johnson @author Juergen Hoeller @see #setPointcut @see #setAdvice

Read More
Advertisement