|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2014 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import java.lang.annotation.Annotation;
|
20 | 20 | import java.lang.annotation.Inherited;
|
21 | 21 |
|
| 22 | +import org.springframework.core.annotation.AnnotationUtils; |
22 | 23 | import org.springframework.core.type.AnnotationMetadata;
|
23 | 24 | import org.springframework.core.type.classreading.MetadataReader;
|
| 25 | +import org.springframework.util.ClassUtils; |
24 | 26 |
|
25 | 27 | /**
|
26 | 28 | * A simple filter which matches classes with a given annotation,
|
@@ -49,7 +51,7 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter
|
49 | 51 | * @param annotationType the annotation type to match
|
50 | 52 | */
|
51 | 53 | public AnnotationTypeFilter(Class<? extends Annotation> annotationType) {
|
52 |
| - this(annotationType, true); |
| 54 | + this(annotationType, true, false); |
53 | 55 | }
|
54 | 56 |
|
55 | 57 | /**
|
@@ -84,16 +86,26 @@ protected boolean matchSelf(MetadataReader metadataReader) {
|
84 | 86 |
|
85 | 87 | @Override
|
86 | 88 | protected Boolean matchSuperClass(String superClassName) {
|
87 |
| - if (Object.class.getName().equals(superClassName)) { |
88 |
| - return Boolean.FALSE; |
| 89 | + return hasAnnotation(superClassName); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + protected Boolean matchInterface(String interfaceName) { |
| 94 | + return hasAnnotation(interfaceName); |
| 95 | + } |
| 96 | + |
| 97 | + protected Boolean hasAnnotation(String typeName) { |
| 98 | + if (Object.class.getName().equals(typeName)) { |
| 99 | + return false; |
89 | 100 | }
|
90 |
| - else if (superClassName.startsWith("java.")) { |
| 101 | + else if (typeName.startsWith("java")) { |
91 | 102 | try {
|
92 |
| - Class<?> clazz = getClass().getClassLoader().loadClass(superClassName); |
93 |
| - return (clazz.getAnnotation(this.annotationType) != null); |
| 103 | + Class<?> clazz = ClassUtils.forName(typeName, getClass().getClassLoader()); |
| 104 | + return ((this.considerMetaAnnotations ? AnnotationUtils.getAnnotation(clazz, this.annotationType) : |
| 105 | + clazz.getAnnotation(this.annotationType)) != null); |
94 | 106 | }
|
95 |
| - catch (ClassNotFoundException ex) { |
96 |
| - // Class not found - can't determine a match that way. |
| 107 | + catch (Throwable ex) { |
| 108 | + // Class not regularly loadable - can't determine a match that way. |
97 | 109 | }
|
98 | 110 | }
|
99 | 111 | return null;
|
|
0 commit comments