use of org.springframework.core.type.filter.AnnotationTypeFilter in project spring-framework by spring-projects.
the class ClassPathScanningCandidateComponentProviderTests method testWithAspectAnnotationOnly.
@Test
public void testWithAspectAnnotationOnly() throws Exception {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(Aspect.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(1, candidates.size());
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
}
use of org.springframework.core.type.filter.AnnotationTypeFilter in project spring-framework by spring-projects.
the class AnnotationTypeFilterTests method testInheritedAnnotationFromInterfaceDoesNotMatch.
@Test
public void testInheritedAnnotationFromInterfaceDoesNotMatch() throws Exception {
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubClassOfSomeComponentInterface";
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
// Must fail as annotation on interfaces should not be considered a match
assertFalse(filter.match(metadataReader, metadataReaderFactory));
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
use of org.springframework.core.type.filter.AnnotationTypeFilter in project spring-framework by spring-projects.
the class AnnotationTypeFilterTests method testInheritedAnnotationFromBaseClassDoesMatch.
@Test
public void testInheritedAnnotationFromBaseClassDoesMatch() throws Exception {
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubClassOfSomeComponent";
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
assertTrue(filter.match(metadataReader, metadataReaderFactory));
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
use of org.springframework.core.type.filter.AnnotationTypeFilter in project spring-framework by spring-projects.
the class AnnotationTypeFilterTests method testNonAnnotatedClassDoesntMatch.
@Test
public void testNonAnnotatedClassDoesntMatch() throws Exception {
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeNonCandidateClass";
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
AnnotationTypeFilter filter = new AnnotationTypeFilter(Component.class);
assertFalse(filter.match(metadataReader, metadataReaderFactory));
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
use of org.springframework.core.type.filter.AnnotationTypeFilter in project opennms by OpenNMS.
the class JaxbUtils method getClassForElement.
public static Class<?> getClassForElement(final String elementName) {
if (elementName == null)
return null;
final Class<?> existing = m_elementClasses.get(elementName);
if (existing != null)
return existing;
final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(XmlRootElement.class));
for (final BeanDefinition bd : scanner.findCandidateComponents("org.opennms")) {
final String className = bd.getBeanClassName();
try {
final Class<?> clazz = Class.forName(className);
final XmlRootElement annotation = clazz.getAnnotation(XmlRootElement.class);
if (annotation == null) {
LOG.warn("Somehow found class {} but it has no @XmlRootElement annotation! Skipping.", className);
continue;
}
if (elementName.equalsIgnoreCase(annotation.name())) {
LOG.trace("Found class {} for element name {}", className, elementName);
m_elementClasses.put(elementName, clazz);
return clazz;
}
} catch (final ClassNotFoundException e) {
LOG.warn("Unable to get class object from class name {}. Skipping.", className, e);
}
}
return null;
}
Aggregations