DATACMNS-382 - Remove copy of AnnotationTypeFilter in RepositoryComponentProvider.
Removed the copied class to use the one from Spring Core now that the necessary tweak is available in Spring 3.1.x. Original pull request: #49.
This commit is contained in:
committed by
Oliver Gierke
parent
06df973c54
commit
e76f820469
@@ -1,17 +1,14 @@
|
|||||||
package org.springframework.data.repository.config;
|
package org.springframework.data.repository.config;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.annotation.Inherited;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
|
||||||
import org.springframework.core.type.classreading.MetadataReader;
|
import org.springframework.core.type.classreading.MetadataReader;
|
||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter;
|
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||||
import org.springframework.core.type.filter.TypeFilter;
|
import org.springframework.core.type.filter.TypeFilter;
|
||||||
import org.springframework.data.repository.NoRepositoryBean;
|
import org.springframework.data.repository.NoRepositoryBean;
|
||||||
@@ -25,6 +22,7 @@ import org.springframework.util.Assert;
|
|||||||
* interface. Skips interfaces annotated with {@link NoRepositoryBean}.
|
* interface. Skips interfaces annotated with {@link NoRepositoryBean}.
|
||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @author Thomas Darimont
|
||||||
*/
|
*/
|
||||||
class RepositoryComponentProvider extends ClassPathScanningCandidateComponentProvider {
|
class RepositoryComponentProvider extends ClassPathScanningCandidateComponentProvider {
|
||||||
|
|
||||||
@@ -117,82 +115,6 @@ class RepositoryComponentProvider extends ClassPathScanningCandidateComponentPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy of Spring's AnnotationTypeFilter until SPR-8336 gets resolved.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple filter which matches classes with a given annotation, checking inherited annotations as well.
|
|
||||||
* <p>
|
|
||||||
* The matching logic mirrors that of <code>Class.isAnnotationPresent()</code>.
|
|
||||||
*
|
|
||||||
* @author Mark Fisher
|
|
||||||
* @author Ramnivas Laddad
|
|
||||||
* @author Juergen Hoeller
|
|
||||||
* @since 2.5
|
|
||||||
*/
|
|
||||||
private static class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter {
|
|
||||||
|
|
||||||
private final Class<? extends Annotation> annotationType;
|
|
||||||
|
|
||||||
private final boolean considerMetaAnnotations;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new AnnotationTypeFilter for the given annotation type. This filter will also match meta-annotations. To
|
|
||||||
* disable the meta-annotation matching, use the constructor that accepts a ' <code>considerMetaAnnotations</code>'
|
|
||||||
* argument. The filter will not match interfaces.
|
|
||||||
*
|
|
||||||
* @param annotationType the annotation type to match
|
|
||||||
*/
|
|
||||||
public AnnotationTypeFilter(Class<? extends Annotation> annotationType) {
|
|
||||||
this(annotationType, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new AnnotationTypeFilter for the given annotation type. The filter will not match interfaces.
|
|
||||||
*
|
|
||||||
* @param annotationType the annotation type to match
|
|
||||||
* @param considerMetaAnnotations whether to also match on meta-annotations
|
|
||||||
*/
|
|
||||||
public AnnotationTypeFilter(Class<? extends Annotation> annotationType, boolean considerMetaAnnotations) {
|
|
||||||
this(annotationType, considerMetaAnnotations, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link AnnotationTypeFilter} for the given annotation type.
|
|
||||||
*
|
|
||||||
* @param annotationType the annotation type to match
|
|
||||||
* @param considerMetaAnnotations whether to also match on meta-annotations
|
|
||||||
* @param considerInterfaces whether to also match interfaces
|
|
||||||
*/
|
|
||||||
public AnnotationTypeFilter(Class<? extends Annotation> annotationType, boolean considerMetaAnnotations,
|
|
||||||
boolean considerInterfaces) {
|
|
||||||
super(annotationType.isAnnotationPresent(Inherited.class), considerInterfaces);
|
|
||||||
this.annotationType = annotationType;
|
|
||||||
this.considerMetaAnnotations = considerMetaAnnotations;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean matchSelf(MetadataReader metadataReader) {
|
|
||||||
AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
|
|
||||||
return metadata.hasAnnotation(this.annotationType.getName())
|
|
||||||
|| (this.considerMetaAnnotations && metadata.hasMetaAnnotation(this.annotationType.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Boolean matchSuperClass(String superClassName) {
|
|
||||||
if (Object.class.getName().equals(superClassName)) {
|
|
||||||
return Boolean.FALSE;
|
|
||||||
} else if (superClassName.startsWith("java.")) {
|
|
||||||
try {
|
|
||||||
Class<?> clazz = getClass().getClassLoader().loadClass(superClassName);
|
|
||||||
return (clazz.getAnnotation(this.annotationType) != null);
|
|
||||||
} catch (ClassNotFoundException ex) {
|
|
||||||
// Class not found - can't determine a match that way.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to create a {@link TypeFilter} that matches if all the delegates match.
|
* Helper class to create a {@link TypeFilter} that matches if all the delegates match.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user