Search in sources :

Example 1 with HandlesTypes

use of jakarta.servlet.annotation.HandlesTypes in project tomcat by apache.

the class ContextConfig method processServletContainerInitializers.

/**
 * Scan JARs for ServletContainerInitializer implementations.
 */
protected void processServletContainerInitializers() {
    List<ServletContainerInitializer> detectedScis;
    try {
        WebappServiceLoader<ServletContainerInitializer> loader = new WebappServiceLoader<>(context);
        detectedScis = loader.load(ServletContainerInitializer.class);
    } catch (IOException e) {
        log.error(sm.getString("contextConfig.servletContainerInitializerFail", context.getName()), e);
        ok = false;
        return;
    }
    for (ServletContainerInitializer sci : detectedScis) {
        initializerClassMap.put(sci, new HashSet<>());
        HandlesTypes ht;
        try {
            ht = sci.getClass().getAnnotation(HandlesTypes.class);
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.info(sm.getString("contextConfig.sci.debug", sci.getClass().getName()), e);
            } else {
                log.info(sm.getString("contextConfig.sci.info", sci.getClass().getName()));
            }
            continue;
        }
        if (ht == null) {
            continue;
        }
        Class<?>[] types = ht.value();
        if (types == null) {
            continue;
        }
        for (Class<?> type : types) {
            if (type.isAnnotation()) {
                handlesTypesAnnotations = true;
            } else {
                handlesTypesNonAnnotations = true;
            }
            Set<ServletContainerInitializer> scis = typeInitializerMap.get(type);
            if (scis == null) {
                scis = new HashSet<>();
                typeInitializerMap.put(type, scis);
            }
            scis.add(sci);
        }
    }
}
Also used : ServletContainerInitializer(jakarta.servlet.ServletContainerInitializer) JavaClass(org.apache.tomcat.util.bcel.classfile.JavaClass) IOException(java.io.IOException) HandlesTypes(jakarta.servlet.annotation.HandlesTypes) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException)

Aggregations

ServletContainerInitializer (jakarta.servlet.ServletContainerInitializer)1 HandlesTypes (jakarta.servlet.annotation.HandlesTypes)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ClassFormatException (org.apache.tomcat.util.bcel.classfile.ClassFormatException)1 JavaClass (org.apache.tomcat.util.bcel.classfile.JavaClass)1 SAXParseException (org.xml.sax.SAXParseException)1