3 import javax.servlet.http.*;
8 import mir.storage.StorageObjectException;
9 import mir.storage.DatabaseAdaptor;
10 import com.codestudio.util.*;
14 * Description: Class that allows access to all Mir
16 * Copyright: Copyright (c) 2001
18 * @author mh <heckmann@hbe.ca>
24 * This class is a layer above the Configuration
25 * It manages access to config variables that are
26 * both generated on the fly and found in the config file.
29 public class MirConfig extends Configuration {
31 private static HashMap configHash = null;
32 private static HashMap brokerHash = new HashMap();
33 private static int instances=0;
36 * Initializes Configuration hash that contains all values.
37 * loads the properties-file and any other values
38 * @param uri, the root Uri of the install
39 * @param home, The absolute path if the install root.
40 * @param name, The name of the servlet (usually "Mir")
41 * @param confName, the name of the config file to load.
43 public static synchronized void initConfig(String home, String uri,
44 String name, String confName) {
45 initConfResource(confName);
46 configHash = new HashMap();
47 configHash.put("Home", home);
48 configHash.put("RootUri", uri);
50 Enumeration resKeys = getResourceKeys();
51 while(resKeys.hasMoreElements()) {
52 String keyNm = (String)resKeys.nextElement();
53 configHash.put(keyNm, getProperty(keyNm));
57 * Returns the property asked for by pulling it out a HashMap
58 * @param a String containing the property name (key)
59 * @return a String containing the prop. value
61 public static void setServletName(String servletName) {
62 configHash.put("ServletName",servletName);
66 * Returns the property asked for by pulling it out a HashMap
67 * @param a String containing the property name (key)
68 * @return a String containing the prop. value
70 public static String getProp(String propName) {
71 return (String)configHash.get(propName);
75 * Returns the property asked for by pulling it out a HashMap and
76 * appending it to configproperty "Home"
77 * @param a String containing the property name (key)
78 * @return a String containing the prop.value
80 public static String getPropWithHome(String propName) {
81 return (String)configHash.get("Home") +
82 (String)configHash.get(propName);
85 public static void initDbPool () throws StorageObjectException {
86 if (configHash == null) {
87 throw new StorageObjectException("MirConfig -- Trying initialize "+
88 "DB pool when system not yet "+
91 String dbUser=getProp("Database.Username");
92 String dbPassword=getProp("Database.Password");
93 String dbHost=getProp("Database.Host");
94 String dbAdapName=getProp("Database.Adaptor");
95 DatabaseAdaptor adaptor;
97 adaptor = (DatabaseAdaptor)Class.forName(dbAdapName).newInstance();
98 } catch (Exception e) {
99 throw new StorageObjectException("Could not load DB adapator: "+
102 String dbDriver=adaptor.getDriver();
103 String dbUrl=adaptor.getURL(dbUser,dbPassword, dbHost);
104 System.out.println("adding Broker with: " +dbDriver+":"+dbUrl );
105 addBroker( dbDriver, dbUrl);
108 public static void addBroker(String driver, String URL)
109 throws StorageObjectException {
111 if (configHash == null) {
112 throw new StorageObjectException("MirConfig -- Trying initialize "+
113 "DB pool when system not yet "+
116 String username,passwd,min,max,log,reset,dbname,dblogfile;
118 if(!brokerHash.containsKey("Pool.broker")){
119 username=getProp("Database.Username");
120 passwd=getProp("Database.Password");
121 min=getProp("Database.poolMin");
122 max=getProp("Database.poolMax");
123 dbname=getProp("Database.Name");
124 log=getProp("Home")+ configHash.get("Database.PoolLog");
125 reset=getProp("Database.poolResetTime");
126 dblogfile=getPropWithHome("Database.Logfile");
128 System.err.println("-- making Broker for -"
130 + " log " + log + " user "
131 + username + " pass: " + passwd);
133 JDBCPoolMetaData meta = new JDBCPoolMetaData();
134 meta.setDbname(dbname);
135 meta.setDriver(driver);
137 meta.setUserName(username);
138 meta.setPassword(passwd);
139 meta.setJNDIName("mir");
140 meta.setMaximumSize(Integer.parseInt(max));
141 meta.setMinimumSize(Integer.parseInt(min));
142 meta.setCacheEnabled(false);
143 meta.setCacheSize(15);
144 meta.setDebugging(false);
145 meta.setLogFile(dblogfile+".pool");
147 JDBCPool pool = SQLManager.getInstance().createPool(meta);
151 brokerHash.put("Pool.broker",pool);
160 public void finalize(){
164 } catch (Throwable t) {}