Search in sources :

Example 1 with ProjectType

use of de.tudarmstadt.ukp.clarin.webanno.api.ProjectType in project webanno by webanno.

the class ProjectServiceImpl method scanProjectTypes.

private void scanProjectTypes() {
    projectTypes = new ArrayList<>();
    // Scan for project type annotations
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(ProjectType.class));
    for (BeanDefinition bd : scanner.findCandidateComponents("de.tudarmstadt.ukp")) {
        try {
            Class<?> clazz = Class.forName(bd.getBeanClassName());
            ProjectType pt = clazz.getAnnotation(ProjectType.class);
            if (projectTypes.stream().anyMatch(t -> t.id().equals(pt.id()))) {
                log.debug("Ignoring duplicate project type: {} ({})", pt.id(), pt.prio());
            } else {
                log.debug("Found project type: {} ({})", pt.id(), pt.prio());
                projectTypes.add(pt);
            }
        } catch (ClassNotFoundException e) {
            log.error("Class [{}] not found", bd.getBeanClassName(), e);
        }
    }
    projectTypes.sort(comparingInt(ProjectType::prio));
}
Also used : AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) ProjectType(de.tudarmstadt.ukp.clarin.webanno.api.ProjectType) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

ProjectType (de.tudarmstadt.ukp.clarin.webanno.api.ProjectType)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)1 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)1