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

changeset 8
2dfdb79b5344
parent 7
598670d5b0b8
child 9
20a9b2bc9063
equal deleted inserted replaced
7:598670d5b0b8 8:2dfdb79b5344
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 * 27 *
28 */ 28 */
29 package de.uapcore.lightpit; 29 package de.uapcore.lightpit;
30 30
31 import java.util.logging.Level;
32 import java.util.logging.Logger;
33 import javax.servlet.Registration; 31 import javax.servlet.Registration;
34 import javax.servlet.ServletContext; 32 import javax.servlet.ServletContext;
35 import javax.servlet.ServletContextEvent; 33 import javax.servlet.ServletContextEvent;
36 import javax.servlet.ServletContextListener; 34 import javax.servlet.ServletContextListener;
37 import javax.servlet.annotation.WebListener; 35 import javax.servlet.annotation.WebListener;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 38
39 /** 39 /**
40 * Scans registered servlets for LightPIT modules. 40 * Scans registered servlets for LightPIT modules.
41 */ 41 */
42 @WebListener 42 @WebListener
43 public class ModuleManager implements ServletContextListener { 43 public class ModuleManager implements ServletContextListener {
44 44
45 private static final Logger LOG = Logger.getLogger(ModuleManager.class.getName()); 45 private static final Logger LOG = LoggerFactory.getLogger(ModuleManager.class);
46 46
47 /** 47 /**
48 * The attribute name in the servlet context under which an instance of this class can be found. 48 * The attribute name in the servlet context under which an instance of this class can be found.
49 */ 49 */
50 public static final String SC_ATTR_NAME = ModuleManager.class.getName(); 50 public static final String SC_ATTR_NAME = ModuleManager.class.getName();
72 72
73 final boolean lpservlet = LightPITServlet.class.isAssignableFrom(scclass); 73 final boolean lpservlet = LightPITServlet.class.isAssignableFrom(scclass);
74 final boolean lpmodule = scclass.isAnnotationPresent(LightPITModule.class); 74 final boolean lpmodule = scclass.isAnnotationPresent(LightPITModule.class);
75 75
76 if (lpservlet && !lpmodule) { 76 if (lpservlet && !lpmodule) {
77 LOG.log(Level.WARNING, 77 LOG.warn(
78 "Servlet is a LightPITServlet but is missing the module annotation: {0}", 78 "Servlet is a LightPITServlet but is missing the module annotation: {}",
79 reg.getClassName()); 79 reg.getClassName()
80 );
80 } else if (!lpservlet && lpmodule) { 81 } else if (!lpservlet && lpmodule) {
81 LOG.log(Level.WARNING, 82 LOG.warn(
82 "Servlet is annotated as a LightPITModule but does not extend LightPITServlet: {0}", 83 "Servlet is annotated as a LightPITModule but does not extend LightPITServlet: {}",
83 reg.getClassName()); 84 reg.getClassName()
85 );
84 } 86 }
85 87
86 return lpservlet && lpmodule; 88 return lpservlet && lpmodule;
87 } catch (ClassNotFoundException ex) { 89 } catch (ClassNotFoundException ex) {
88 LOG.log(Level.SEVERE, 90 LOG.error(
89 "Servlet registration refers to a class which cannot be found by the class loader: {0}", 91 "Servlet registration refers to a class which cannot be found by the class loader: {}",
90 reg.getClassName()); 92 reg.getClassName()
93 );
91 return false; 94 return false;
92 } 95 }
93 } 96 }
94 97
95 private void handleServletRegistration(String name, Registration reg) { 98 private void handleServletRegistration(String name, Registration reg) {
96 if (isRegisteredAsModule(reg)) { 99 if (isRegisteredAsModule(reg)) {
97 LOG.log(Level.CONFIG, "Module detected: {0}", name); 100 LOG.info("Module detected: {}", name);
98 } else { 101 } else {
99 LOG.log(Level.FINE, "Servlet {0} is no module, skipping.", name); 102 LOG.debug("Servlet {} is no module, skipping.", name);
100 } 103 }
101 } 104 }
102 105
103 /** 106 /**
104 * Scans for modules and reloads them all. 107 * Scans for modules and reloads them all.

mercurial