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

changeset 7
598670d5b0b8
parent 6
da61a1646eba
child 8
2dfdb79b5344
equal deleted inserted replaced
6:da61a1646eba 7:598670d5b0b8
28 */ 28 */
29 package de.uapcore.lightpit; 29 package de.uapcore.lightpit;
30 30
31 import java.util.logging.Level; 31 import java.util.logging.Level;
32 import java.util.logging.Logger; 32 import java.util.logging.Logger;
33 import javax.servlet.Registration;
33 import javax.servlet.ServletContext; 34 import javax.servlet.ServletContext;
34 import javax.servlet.ServletContextEvent; 35 import javax.servlet.ServletContextEvent;
35 import javax.servlet.ServletContextListener; 36 import javax.servlet.ServletContextListener;
36 import javax.servlet.ServletRegistration;
37 import javax.servlet.annotation.WebListener; 37 import javax.servlet.annotation.WebListener;
38 38
39 /** 39 /**
40 * Scans registered servlets for LightPIT modules. 40 * Scans registered servlets for LightPIT modules.
41 */ 41 */
64 assert sc != null && sc.equals(sce.getServletContext()); 64 assert sc != null && sc.equals(sce.getServletContext());
65 sc.removeAttribute(SC_ATTR_NAME); 65 sc.removeAttribute(SC_ATTR_NAME);
66 unloadAll(); 66 unloadAll();
67 } 67 }
68 68
69 private boolean isRegisteredAsModule(ServletRegistration sr) { 69 private boolean isRegisteredAsModule(Registration reg) {
70 try { 70 try {
71 final Class scclass = Class.forName(sr.getClassName()); 71 final Class scclass = Class.forName(reg.getClassName());
72 return scclass.isAnnotationPresent(LightPITModule.class); 72
73 final boolean lpservlet = LightPITServlet.class.isAssignableFrom(scclass);
74 final boolean lpmodule = scclass.isAnnotationPresent(LightPITModule.class);
75
76 if (lpservlet && !lpmodule) {
77 LOG.log(Level.WARNING,
78 "Servlet is a LightPITServlet but is missing the module annotation: {0}",
79 reg.getClassName());
80 } else if (!lpservlet && lpmodule) {
81 LOG.log(Level.WARNING,
82 "Servlet is annotated as a LightPITModule but does not extend LightPITServlet: {0}",
83 reg.getClassName());
84 }
85
86 return lpservlet && lpmodule;
73 } catch (ClassNotFoundException ex) { 87 } catch (ClassNotFoundException ex) {
74 LOG.log(Level.SEVERE, 88 LOG.log(Level.SEVERE,
75 "Servlet registration refers to a class which cannot be found by the class loader: {0}", 89 "Servlet registration refers to a class which cannot be found by the class loader: {0}",
76 sr.getClassName()); 90 reg.getClassName());
77 return false; 91 return false;
78 } 92 }
79 } 93 }
80 94
81 private void handleServletRegistration(String name, ServletRegistration sr) { 95 private void handleServletRegistration(String name, Registration reg) {
82 if (isRegisteredAsModule(sr)) { 96 if (isRegisteredAsModule(reg)) {
83 LOG.log(Level.CONFIG, "Module detected: {0}", name); 97 LOG.log(Level.CONFIG, "Module detected: {0}", name);
84 } else { 98 } else {
85 LOG.log(Level.FINE, "Servlet {0} is no module, skipping.", name); 99 LOG.log(Level.FINE, "Servlet {0} is no module, skipping.", name);
86 } 100 }
87 } 101 }

mercurial