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

changeset 7
598670d5b0b8
parent 6
da61a1646eba
child 8
2dfdb79b5344
--- a/src/java/de/uapcore/lightpit/ModuleManager.java	Sun Nov 26 18:09:23 2017 +0100
+++ b/src/java/de/uapcore/lightpit/ModuleManager.java	Tue Nov 28 18:59:13 2017 +0100
@@ -30,10 +30,10 @@
 
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.servlet.Registration;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
-import javax.servlet.ServletRegistration;
 import javax.servlet.annotation.WebListener;
 
 /**
@@ -66,20 +66,34 @@
         unloadAll();
     }
     
-    private boolean isRegisteredAsModule(ServletRegistration sr) {
+    private boolean isRegisteredAsModule(Registration reg) {
         try {
-            final Class scclass = Class.forName(sr.getClassName());
-            return scclass.isAnnotationPresent(LightPITModule.class);
+            final Class scclass = Class.forName(reg.getClassName());
+            
+            final boolean lpservlet = LightPITServlet.class.isAssignableFrom(scclass);
+            final boolean lpmodule = scclass.isAnnotationPresent(LightPITModule.class);
+            
+            if (lpservlet && !lpmodule) {
+                LOG.log(Level.WARNING,
+                    "Servlet is a LightPITServlet but is missing the module annotation: {0}",
+                    reg.getClassName());
+            } else if (!lpservlet && lpmodule) {
+                LOG.log(Level.WARNING,
+                    "Servlet is annotated as a LightPITModule but does not extend LightPITServlet: {0}",
+                    reg.getClassName());
+            }
+            
+            return lpservlet && lpmodule;
         } catch (ClassNotFoundException ex) {
             LOG.log(Level.SEVERE,
                     "Servlet registration refers to a class which cannot be found by the class loader: {0}",
-                    sr.getClassName());
+                    reg.getClassName());
             return false;
         }        
     }
     
-    private void handleServletRegistration(String name, ServletRegistration sr) {
-        if (isRegisteredAsModule(sr)) {
+    private void handleServletRegistration(String name, Registration reg) {
+        if (isRegisteredAsModule(reg)) {
             LOG.log(Level.CONFIG, "Module detected: {0}", name);
         } else {
             LOG.log(Level.FINE, "Servlet {0} is no module, skipping.", name);

mercurial