Example usage for org.springframework.aop.support DefaultPointcutAdvisor setPointcut

List of usage examples for org.springframework.aop.support DefaultPointcutAdvisor setPointcut

Introduction

In this page you can find the example usage for org.springframework.aop.support DefaultPointcutAdvisor setPointcut.

Prototype

public void setPointcut(@Nullable Pointcut pointcut) 

Source Link

Document

Specify the pointcut targeting the advice.

Usage

From source file:org.anyframe.iam.admin.common.web.JsonErrorAdvisingBeanPostProcessor.java

@SuppressWarnings("unchecked")
public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException {

    //  ? bean ? 
    log.debug("postProcessBeforeInitialization with : " + beanName);

    Class clazz = bean.getClass();

    // JsonError Annotation ?  MethodMatcher
    AnnotationMethodMatcher annotationMethodMatcher = new AnnotationMethodMatcher(JsonError.class);

    // advice(JsonIAMException   JsonExceptionTransfer) + Pointcut 
    // ? Advisor//from   w w  w .j ava  2 s  .  c o  m
    DefaultPointcutAdvisor advisor = (DefaultPointcutAdvisor) context.getBean("jsonErrorAdvisor");

    //  bean Class ?     JsonError Annotation ?   
    // ?
    for (Method method : clazz.getDeclaredMethods()) {
        // JsonError Annotation ?   
        if (annotationMethodMatcher.matches(method, clazz)) {
            // maching method  
            log.debug("maching method : " + clazz.getSimpleName() + "." + method.getName());

            // jsonErrorAdvisor    Pointcut ?  -   JsonError
            // Annotation ?  Bean ?  Pointcut  
            if (advisor.getPointcut() == Pointcut.TRUE) {
                advisor.setPointcut(
                        new ComposablePointcut(new RootClassFilter(clazz), annotationMethodMatcher));
                //  ? Pointcut ?  ??  JsonError Annotation ?
                //  Bean ?  Pointcut ? union  ?.
            } else {
                ComposablePointcut pointcut = (ComposablePointcut) advisor.getPointcut();
                pointcut.union(new ComposablePointcut(new RootClassFilter(clazz), annotationMethodMatcher));
                advisor.setPointcut(pointcut);
            }
        }
    }

    return bean;
}