1 6 package org.logicalcobwebs.proxool.configuration; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 import org.logicalcobwebs.proxool.ProxoolException; 11 import org.logicalcobwebs.proxool.ProxoolFacade; 12 13 import javax.servlet.ServletConfig ; 14 import javax.servlet.ServletException ; 15 import javax.servlet.http.HttpServlet ; 16 import java.io.File ; 17 import java.util.Enumeration ; 18 import java.util.Properties ; 19 20 90 public class ServletConfigurator extends HttpServlet { 91 92 private static final Log LOG = LogFactory.getLog(ServletConfigurator.class); 93 94 private static final String XML_FILE_PROPERTY = "xmlFile"; 95 96 private static final String PROPERTY_FILE_PROPERTY = "propertyFile"; 97 98 private static final String AUTO_SHUTDOWN_PROPERTY = "autoShutdown"; 99 100 private boolean autoShutdown = true; 101 102 public void init(ServletConfig servletConfig) throws ServletException { 103 super.init(servletConfig); 104 105 String appDir = servletConfig.getServletContext().getRealPath("/"); 106 107 Properties properties = new Properties (); 108 109 Enumeration names = servletConfig.getInitParameterNames(); 110 while (names.hasMoreElements()) { 111 String name = (String ) names.nextElement(); 112 String value = servletConfig.getInitParameter(name); 113 114 if (name.equals(XML_FILE_PROPERTY)) { 115 try { 116 File file = new File (value); 117 if (file.isAbsolute()) { 118 JAXPConfigurator.configure(value, false); 119 } else { 120 JAXPConfigurator.configure(appDir + File.separator + value, false); 121 } 122 } catch (ProxoolException e) { 123 LOG.error("Problem configuring " + value, e); 124 } 125 } else if (name.equals(PROPERTY_FILE_PROPERTY)) { 126 try { 127 File file = new File (value); 128 if (file.isAbsolute()) { 129 PropertyConfigurator.configure(value); 130 } else { 131 PropertyConfigurator.configure(appDir + File.separator + value); 132 } 133 } catch (ProxoolException e) { 134 LOG.error("Problem configuring " + value, e); 135 } 136 } else if (name.equals(AUTO_SHUTDOWN_PROPERTY)) { 137 autoShutdown = Boolean.valueOf(value).booleanValue(); 138 } else if (name.startsWith(PropertyConfigurator.PREFIX)) { 139 properties.setProperty(name, value); 140 } 141 } 142 143 if (properties.size() > 0) { 144 try { 145 PropertyConfigurator.configure(properties); 146 } catch (ProxoolException e) { 147 LOG.error("Problem configuring using init properties", e); 148 } 149 } 150 } 151 152 162 public void destroy() { 163 if (autoShutdown) { 164 ProxoolFacade.shutdown(0); 165 } 166 } 167 } 168 169 170 | Popular Tags |