Example usage for org.springframework.core.type.filter AnnotationTypeFilter match

List of usage examples for org.springframework.core.type.filter AnnotationTypeFilter match

Introduction

In this page you can find the example usage for org.springframework.core.type.filter AnnotationTypeFilter match.

Prototype

@Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
            throws IOException 

Source Link

Usage

From source file:org.bitsofinfo.util.reflection.SpringClassFinder.java

public Set<Class> findByTypeAnnotation(Class<? extends Annotation> annotation, String packageRoot)
        throws Exception {

    Set<Class> foundClasses = new HashSet<Class>();

    packageRoot = StringUtils.replace(packageRoot, ".", File.separator);

    AnnotationTypeFilter typeFilter = new AnnotationTypeFilter(annotation);
    String pattern = "classpath*:" + packageRoot + File.separator + "**" + File.separator + "*.class";

    Resource[] resources = resourcePatternResolver.getResources(pattern);

    for (Resource resource : resources) {

        MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
        if (typeFilter.match(metadataReader, metadataReaderFactory)) {
            String className = convertResourceToClassName(resource, packageRoot);
            foundClasses.add(Class.forName(className));
        }/*from w ww  .  j av  a 2 s  . c o m*/
    }

    return foundClasses;

}