01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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.core.annotation.AnnotationUtils;
23: import org.springframework.util.Assert;
24:
25: /**
26: * Simple ClassFilter that looks for a specific Java 5 annotation
27: * being present on a class.
28: *
29: * @author Juergen Hoeller
30: * @since 2.0
31: * @see AnnotationMatchingPointcut
32: */
33: public class AnnotationClassFilter implements ClassFilter {
34:
35: private final Class<? extends Annotation> annotationType;
36:
37: private final boolean checkInherited;
38:
39: /**
40: * Create a new AnnotationClassFilter for the given annotation type.
41: * @param annotationType the annotation type to look for
42: */
43: public AnnotationClassFilter(
44: Class<? extends Annotation> annotationType) {
45: this (annotationType, false);
46: }
47:
48: /**
49: * Create a new AnnotationClassFilter for the given annotation type.
50: * @param annotationType the annotation type to look for
51: * @param checkInherited whether to explicitly check the superclasses and
52: * interfaces for the annotation type as well (even if the annotation type
53: * is not marked as inherited itself)
54: */
55: public AnnotationClassFilter(
56: Class<? extends Annotation> annotationType,
57: boolean checkInherited) {
58: Assert.notNull(annotationType,
59: "Annotation type must not be null");
60: this .annotationType = annotationType;
61: this .checkInherited = checkInherited;
62: }
63:
64: public boolean matches(Class clazz) {
65: return (this.checkInherited ? (AnnotationUtils.findAnnotation(
66: clazz, this.annotationType) != null) : clazz
67: .isAnnotationPresent(this.annotationType));
68: }
69:
70: }
|