1 16 17 package org.springframework.aop.support.annotation; 18 19 import java.lang.annotation.Annotation ; 20 21 import org.springframework.aop.ClassFilter; 22 import org.springframework.aop.MethodMatcher; 23 import org.springframework.aop.Pointcut; 24 import org.springframework.util.Assert; 25 26 36 public class AnnotationMatchingPointcut implements Pointcut { 37 38 private final ClassFilter classFilter; 39 40 private final MethodMatcher methodMatcher; 41 42 43 47 public AnnotationMatchingPointcut(Class <? extends Annotation > classAnnotationType) { 48 this(classAnnotationType, null); 49 } 50 51 58 public AnnotationMatchingPointcut( 59 Class <? extends Annotation > classAnnotationType, Class <? extends Annotation > methodAnnotationType) { 60 61 Assert.isTrue((classAnnotationType != null || methodAnnotationType != null), 62 "Either Class annotation type or Method annotation type needs to be specified (or both)"); 63 64 if (classAnnotationType != null) { 65 this.classFilter = new AnnotationClassFilter(classAnnotationType); 66 } 67 else { 68 this.classFilter = ClassFilter.TRUE; 69 } 70 71 if (methodAnnotationType != null) { 72 this.methodMatcher = new AnnotationMethodMatcher(methodAnnotationType); 73 } 74 else { 75 this.methodMatcher = MethodMatcher.TRUE; 76 } 77 } 78 79 80 public ClassFilter getClassFilter() { 81 return this.classFilter; 82 } 83 84 public MethodMatcher getMethodMatcher() { 85 return this.methodMatcher; 86 } 87 88 89 95 public static AnnotationMatchingPointcut forClassAnnotation(Class <? extends Annotation > annotationType) { 96 Assert.notNull(annotationType, "Annotation type must not be null"); 97 return new AnnotationMatchingPointcut(annotationType); 98 } 99 100 106 public static AnnotationMatchingPointcut forMethodAnnotation(Class <? extends Annotation > annotationType) { 107 Assert.notNull(annotationType, "Annotation type must not be null"); 108 return new AnnotationMatchingPointcut(null, annotationType); 109 } 110 111 } 112 | Popular Tags |