1 21 22 package org.opensubsystems.core.www; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 29 import javax.servlet.ServletContext ; 30 import javax.servlet.ServletContextEvent ; 31 import javax.servlet.ServletContextListener ; 32 33 import org.opensubsystems.core.error.OSSException; 34 import org.opensubsystems.core.util.Log; 35 36 59 public class WebModuleListener implements ServletContextListener 60 { 61 63 66 private static Logger s_logger = Log.getInstance(WebModuleListener.class); 67 68 70 76 public static final String WEBCLIENT_MODULE_PREFIX = "oss.webclient.module."; 77 78 83 public static final String WEBCLIENT_MODULE_URL_PREFIX = WEBCLIENT_MODULE_PREFIX + "url."; 84 85 87 90 public void contextInitialized( 91 ServletContextEvent servletContextEvent 92 ) 93 { 94 s_logger.entering(this.getClass().getName(), "contextInitialized"); 95 try 96 { 97 ServletContext scContext; 100 String strModuleClassName; 101 String strModuleURL; 102 int iIndex = 0; 103 WebModule module; 104 Method methodGetInstance; 105 WebModuleDefinitionManager manager; 106 107 scContext = servletContextEvent.getServletContext(); 108 109 try 110 { 111 manager = WebModuleDefinitionManager.getInstance(); 112 do 113 { 114 strModuleClassName = WebUtils.readProperty(scContext, 116 WEBCLIENT_MODULE_PREFIX + iIndex, null, true); 117 if ((strModuleClassName != null) && (strModuleClassName.length() > 0)) 118 { 119 s_logger.fine("Read web module name " + strModuleClassName); 120 methodGetInstance = Class.forName( 121 strModuleClassName).getMethod("getInstance", null); 122 module = (WebModule)methodGetInstance.invoke(null, null); 123 s_logger.fine("Instantiated web module " + strModuleClassName); 124 125 strModuleURL = WebUtils.readProperty(scContext, 127 WEBCLIENT_MODULE_URL_PREFIX + iIndex, null, true); 128 if ((strModuleURL != null) && (strModuleURL.length() > 0)) 129 { 130 s_logger.fine("Read web module URL " + strModuleURL); 131 module.setURL(strModuleURL); 133 } 134 manager.add(module); 135 iIndex++; 136 } 137 } 138 while (strModuleClassName != null); 139 } 140 catch (OSSException ossExc) 141 { 142 s_logger.log(Level.SEVERE, "Unexpected exception.", ossExc); 144 throw new RuntimeException ("Unexpected exception.", ossExc); 145 } 146 catch (SecurityException eSec) 147 { 148 s_logger.log(Level.SEVERE, "Unexpected exception.", eSec); 149 throw new RuntimeException ("Unexpected exception.", eSec); 150 } 151 catch (NoSuchMethodException eNoMeth) 152 { 153 s_logger.log(Level.SEVERE, "Unexpected exception.", eNoMeth); 154 throw new RuntimeException ("Unexpected exception.", eNoMeth); 155 } 156 catch (ClassNotFoundException eNoClass) 157 { 158 s_logger.log(Level.SEVERE, "Unexpected exception.", eNoClass); 159 throw new RuntimeException ("Unexpected exception.", eNoClass); 160 } 161 catch (IllegalArgumentException eIllArg) 162 { 163 s_logger.log(Level.SEVERE, "Unexpected exception.", eIllArg); 164 throw new RuntimeException ("Unexpected exception.", eIllArg); 165 } 166 catch (IllegalAccessException eIllAcc) 167 { 168 s_logger.log(Level.SEVERE, "Unexpected exception.", eIllAcc); 169 throw new RuntimeException ("Unexpected exception.", eIllAcc); 170 } 171 catch (InvocationTargetException eInvoTarg) 172 { 173 s_logger.log(Level.SEVERE, "Unexpected exception.", eInvoTarg); 174 throw new RuntimeException ("Unexpected exception.", eInvoTarg); 175 } 176 catch (Throwable thr) 179 { 180 s_logger.log(Level.SEVERE, "Unexpected exception.", thr); 182 throw new RuntimeException ("Unexpected exception.", thr); 183 } 184 } 185 finally 186 { 187 s_logger.exiting(this.getClass().getName(), "contextInitialized"); 188 } 189 } 190 191 194 public void contextDestroyed( 195 ServletContextEvent servletContextEvent 196 ) 197 { 198 s_logger.entering(this.getClass().getName(), "contextDestroyed"); 199 try 200 { 201 } 203 finally 204 { 205 s_logger.exiting(this.getClass().getName(), "contextDestroyed"); 206 } 207 } 208 } 209 | Popular Tags |