src/java/de/uapcore/lightpit/ModuleManager.java

changeset 7
598670d5b0b8
parent 6
da61a1646eba
child 8
2dfdb79b5344
     1.1 --- a/src/java/de/uapcore/lightpit/ModuleManager.java	Sun Nov 26 18:09:23 2017 +0100
     1.2 +++ b/src/java/de/uapcore/lightpit/ModuleManager.java	Tue Nov 28 18:59:13 2017 +0100
     1.3 @@ -30,10 +30,10 @@
     1.4  
     1.5  import java.util.logging.Level;
     1.6  import java.util.logging.Logger;
     1.7 +import javax.servlet.Registration;
     1.8  import javax.servlet.ServletContext;
     1.9  import javax.servlet.ServletContextEvent;
    1.10  import javax.servlet.ServletContextListener;
    1.11 -import javax.servlet.ServletRegistration;
    1.12  import javax.servlet.annotation.WebListener;
    1.13  
    1.14  /**
    1.15 @@ -66,20 +66,34 @@
    1.16          unloadAll();
    1.17      }
    1.18      
    1.19 -    private boolean isRegisteredAsModule(ServletRegistration sr) {
    1.20 +    private boolean isRegisteredAsModule(Registration reg) {
    1.21          try {
    1.22 -            final Class scclass = Class.forName(sr.getClassName());
    1.23 -            return scclass.isAnnotationPresent(LightPITModule.class);
    1.24 +            final Class scclass = Class.forName(reg.getClassName());
    1.25 +            
    1.26 +            final boolean lpservlet = LightPITServlet.class.isAssignableFrom(scclass);
    1.27 +            final boolean lpmodule = scclass.isAnnotationPresent(LightPITModule.class);
    1.28 +            
    1.29 +            if (lpservlet && !lpmodule) {
    1.30 +                LOG.log(Level.WARNING,
    1.31 +                    "Servlet is a LightPITServlet but is missing the module annotation: {0}",
    1.32 +                    reg.getClassName());
    1.33 +            } else if (!lpservlet && lpmodule) {
    1.34 +                LOG.log(Level.WARNING,
    1.35 +                    "Servlet is annotated as a LightPITModule but does not extend LightPITServlet: {0}",
    1.36 +                    reg.getClassName());
    1.37 +            }
    1.38 +            
    1.39 +            return lpservlet && lpmodule;
    1.40          } catch (ClassNotFoundException ex) {
    1.41              LOG.log(Level.SEVERE,
    1.42                      "Servlet registration refers to a class which cannot be found by the class loader: {0}",
    1.43 -                    sr.getClassName());
    1.44 +                    reg.getClassName());
    1.45              return false;
    1.46          }        
    1.47      }
    1.48      
    1.49 -    private void handleServletRegistration(String name, ServletRegistration sr) {
    1.50 -        if (isRegisteredAsModule(sr)) {
    1.51 +    private void handleServletRegistration(String name, Registration reg) {
    1.52 +        if (isRegisteredAsModule(reg)) {
    1.53              LOG.log(Level.CONFIG, "Module detected: {0}", name);
    1.54          } else {
    1.55              LOG.log(Level.FINE, "Servlet {0} is no module, skipping.", name);

mercurial