Search in sources :

Example 1 with AnnotationScanPackages

use of com.sun.faces.config.WebConfiguration.WebContextInitParameter.AnnotationScanPackages in project mojarra by eclipse-ee4j.

the class FilterClassesFromFacesInitializerAnnotationProvider method createAnnotatedMap.

// ---------------------------------------------------------- Private Methods
/**
 * Go over the annotated set and converter it to a hash map.
 *
 * @param annotatedMap
 * @param annotatedSet
 */
private Map<Class<? extends Annotation>, Set<Class<?>>> createAnnotatedMap(Set<Class<?>> annotatedSet) {
    HashMap<Class<? extends Annotation>, Set<Class<?>>> annotatedMap = new HashMap<>();
    if (isEmpty(annotatedSet)) {
        return annotatedMap;
    }
    WebConfiguration webConfig = WebConfiguration.getInstance();
    boolean annotationScanPackagesSet = webConfig.isSet(AnnotationScanPackages);
    String[] annotationScanPackages = annotationScanPackagesSet ? webConfig.getOptionValue(AnnotationScanPackages).split("\\s+") : null;
    Iterator<Class<?>> iterator = annotatedSet.iterator();
    while (iterator.hasNext()) {
        try {
            Class<?> clazz = iterator.next();
            stream(clazz.getAnnotations()).map(annotation -> annotation.annotationType()).filter(annotationType -> FACES_ANNOTATION_TYPE.contains(annotationType)).forEach(annotationType -> {
                Set<Class<?>> classes = annotatedMap.computeIfAbsent(annotationType, e -> new HashSet<>());
                if (annotationScanPackagesSet) {
                    if (matchesAnnotationScanPackages(clazz, annotationScanPackages)) {
                        classes.add(clazz);
                    }
                } else {
                    classes.add(clazz);
                }
            });
        } catch (NoClassDefFoundError ncdfe) {
        }
    }
    return annotatedMap;
}
Also used : Util.isEmpty(com.sun.faces.util.Util.isEmpty) Iterator(java.util.Iterator) WebConfiguration(com.sun.faces.config.WebConfiguration) ANNOTATED_CLASSES(com.sun.faces.RIConstants.ANNOTATED_CLASSES) AnnotationProvider(com.sun.faces.spi.AnnotationProvider) Set(java.util.Set) HashMap(java.util.HashMap) AnnotationScanPackages(com.sun.faces.config.WebConfiguration.WebContextInitParameter.AnnotationScanPackages) HashSet(java.util.HashSet) FACES_ANNOTATION_TYPE(com.sun.faces.config.manager.spi.AnnotationScanner.FACES_ANNOTATION_TYPE) Map(java.util.Map) Annotation(java.lang.annotation.Annotation) URI(java.net.URI) ServletContext(jakarta.servlet.ServletContext) Arrays.stream(java.util.Arrays.stream) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Annotation(java.lang.annotation.Annotation) WebConfiguration(com.sun.faces.config.WebConfiguration)

Aggregations

ANNOTATED_CLASSES (com.sun.faces.RIConstants.ANNOTATED_CLASSES)1 WebConfiguration (com.sun.faces.config.WebConfiguration)1 AnnotationScanPackages (com.sun.faces.config.WebConfiguration.WebContextInitParameter.AnnotationScanPackages)1 FACES_ANNOTATION_TYPE (com.sun.faces.config.manager.spi.AnnotationScanner.FACES_ANNOTATION_TYPE)1 AnnotationProvider (com.sun.faces.spi.AnnotationProvider)1 Util.isEmpty (com.sun.faces.util.Util.isEmpty)1 ServletContext (jakarta.servlet.ServletContext)1 Annotation (java.lang.annotation.Annotation)1 URI (java.net.URI)1 Arrays.stream (java.util.Arrays.stream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1