Example usage for org.springframework.aop.support.annotation AnnotationMethodMatcher AnnotationMethodMatcher

List of usage examples for org.springframework.aop.support.annotation AnnotationMethodMatcher AnnotationMethodMatcher

Introduction

In this page you can find the example usage for org.springframework.aop.support.annotation AnnotationMethodMatcher AnnotationMethodMatcher.

Prototype

public AnnotationMethodMatcher(Class<? extends Annotation> annotationType) 

Source Link

Document

Create a new AnnotationClassFilter for the given annotation type.

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  www.j a  v a2  s  .  c  om*/
    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;
}