/** * Compute types handled ( set of annotation classes and set of other classes ) * handled by servlet container initializer. * @return types to be handled by jsf implementation */ private TypesHandled handlesTypes() { TypesHandled result = new TypesHandled(); HandlesTypes ht = null; if (this.jsfAnnotatedClassFactoryConfiguration.getServletContainerInitializer() != null) { ht = this.jsfAnnotatedClassFactoryConfiguration.getServletContainerInitializer().getClass().getAnnotation(HandlesTypes.class); } if (ht != null) { Set<Class<? extends Annotation>> annotationsToExclude = annotationsToExclude(); for (Class<?> type : ht.value()) { if (type.isAnnotation()) { Class<? extends Annotation> annotation = (Class<? extends Annotation>) type; if (!annotationsToExclude.contains(annotation)) { result.getAnnotationTypes().add(annotation); } } else { result.getOtherTypes().add(type); } } } return result; }
private List<ServletContainerInitializerInfo> getServletContainerInitializers() { List<ServletContainerInitializerInfo> infos = new ArrayList<>(); for (ServletContainerInitializer initializer : ServiceLoader.load(ServletContainerInitializer.class)) { HandlesTypes types = initializer.getClass().getAnnotation(HandlesTypes.class); infos.add(new ServletContainerInitializerInfo( initializer.getClass(), new ImmediateInstanceFactory<>(initializer), types == null ? Collections.emptySet() : new LinkedHashSet<>(Arrays.asList(types.value())))); } return infos; }
/** * Scan JARs for ServletContainerInitializer implementations. * Implementations will be added in web-fragment.xml priority order. */ protected void processServletContainerInitializers( Set<WebXml> fragments) { for (WebXml fragment : fragments) { URL url = fragment.getURL(); Jar jar = null; InputStream is = null; ServletContainerInitializer sci = null; try { if ("jar".equals(url.getProtocol())) { jar = JarFactory.newInstance(url); is = jar.getInputStream(SCI_LOCATION); } else if ("file".equals(url.getProtocol())) { String path = url.getPath(); File file = new File(path, SCI_LOCATION); if (file.exists()) { is = new FileInputStream(file); } } if (is != null) { sci = getServletContainerInitializer(is); } } catch (IOException ioe) { log.error(sm.getString( "contextConfig.servletContainerInitializerFail", url, context.getName())); ok = false; return; } finally { if (is != null) { try { is.close(); } catch (IOException e) { // Ignore } } if (jar != null) { jar.close(); } } if (sci == null) { continue; } initializerClassMap.put(sci, new HashSet<Class<?>>()); HandlesTypes ht = sci.getClass().getAnnotation(HandlesTypes.class); if (ht != null) { Class<?>[] types = ht.value(); if (types != null) { for (Class<?> type : types) { Set<ServletContainerInitializer> scis = typeInitializerMap.get(type); if (scis == null) { scis = new HashSet<ServletContainerInitializer>(); typeInitializerMap.put(type, scis); } scis.add(sci); } } } } }