01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * See the License for the specific language governing rights and
10: * limitations under the License.
11: *
12: * The Initial Developer of the Original Code is Simulacra Media Ltd.
13: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14: *
15: * All Rights Reserved.
16: *
17: * Contributor(s):
18: *
19: * Created: 29-Nov-2004 by jejking
20: * Version: $Revision: 1.1 $
21: * Last Updated: $Date: 2004/12/07 12:26:45 $
22: */
23: package org.openharmonise.rm.view.servlet.utils;
24:
25: import java.util.logging.Logger;
26:
27: import javax.servlet.ServletContext;
28: import javax.servlet.ServletContextEvent;
29: import javax.servlet.ServletContextListener;
30:
31: import org.openharmonise.rm.config.ConfigException;
32: import org.openharmonise.rm.dsi.*;
33:
34: /**
35: *
36: *
37: * @author jejking
38: */
39: public class DatabaseSettingsInitialiser implements
40: ServletContextListener {
41:
42: private Logger logger = Logger
43: .getLogger(DatabaseSettingsInitialiser.class.getName());
44:
45: /**
46: * Injects database connection parameters into <code>DatabaseSettings</code> on
47: * servlet context initialisation.
48: *
49: * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
50: */
51: public void contextInitialized(ServletContextEvent event) {
52: ServletContext ctx = event.getServletContext();
53: String DB_URL = ctx.getInitParameter("DB_URL");
54: //assert DB_URL != null;
55: String DB_USR = ctx.getInitParameter("DB_USR");
56: //assert DB_USR != null;
57: String DB_PWD = ctx.getInitParameter("DB_PWD");
58: //assert DB_PWD != null;
59: String DB_DRIVERNAME = ctx.getInitParameter("DB_DRIVERNAME");
60: //assert DB_DRIVERNAME != null;
61: String DSI_CLASS = ctx.getInitParameter("DSI_CLASS");
62: //assert DSI_CLASS != null;
63:
64: try {
65: DatabaseSettings.createDatabaseSettings(DB_USR, DB_PWD,
66: DB_URL, DB_DRIVERNAME, DSI_CLASS);
67: } catch (ConfigException ce) {
68: logger.warning("Could not initialise database settings!");
69: }
70: }
71:
72: /* (non-Javadoc)
73: * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
74: */
75: public void contextDestroyed(ServletContextEvent arg0) {
76: // TODO Auto-generated method stub
77:
78: }
79:
80: }
|