KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > view > servlet > utils > DatabaseSettingsInitialiser


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * 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 JavaDoc;
26
27 import javax.servlet.ServletContext JavaDoc;
28 import javax.servlet.ServletContextEvent JavaDoc;
29 import javax.servlet.ServletContextListener JavaDoc;
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 ServletContextListener JavaDoc {
40
41     private Logger JavaDoc logger = Logger.getLogger(DatabaseSettingsInitialiser.class.getName());
42     
43     /**
44      * Injects database connection parameters into <code>DatabaseSettings</code> on
45      * servlet context initialisation.
46      *
47      * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
48      */

49     public void contextInitialized(ServletContextEvent JavaDoc event) {
50         ServletContext JavaDoc ctx = event.getServletContext();
51         String JavaDoc DB_URL = ctx.getInitParameter("DB_URL");
52         //assert DB_URL != null;
53
String JavaDoc DB_USR = ctx.getInitParameter("DB_USR");
54         //assert DB_USR != null;
55
String JavaDoc DB_PWD = ctx.getInitParameter("DB_PWD");
56         //assert DB_PWD != null;
57
String JavaDoc DB_DRIVERNAME = ctx.getInitParameter("DB_DRIVERNAME");
58         //assert DB_DRIVERNAME != null;
59
String JavaDoc DSI_CLASS = ctx.getInitParameter("DSI_CLASS");
60         //assert DSI_CLASS != null;
61

62         try {
63             DatabaseSettings.createDatabaseSettings(DB_USR, DB_PWD, DB_URL, DB_DRIVERNAME, DSI_CLASS);
64         }
65         catch (ConfigException ce) {
66             logger.warning("Could not initialise database settings!");
67         }
68     }
69
70     /* (non-Javadoc)
71      * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
72      */

73     public void contextDestroyed(ServletContextEvent JavaDoc arg0) {
74         // TODO Auto-generated method stub
75

76     }
77
78 }
79
Popular Tags