3 import javax.servlet.http.*;
8 import mir.storage.StorageObjectException;
9 import com.codestudio.util.*;
13 * Description: Class that allows access to all Mir
15 * Copyright: Copyright (c) 2001
17 * @author mh <heckmann@hbe.ca>
23 * This class is a layer above the Configuration
24 * It manages access to config variables that are
25 * both generated on the fly and found in the config file.
28 public class MirConfig extends Configuration {
30 private static HashMap configHash = new HashMap();
31 private static HashMap brokerHash = new HashMap();
32 private static int instances=0;
35 * Initializes Configuration hash that contains all values.
36 * loads the properties-file and any other values
37 * @param uri, the root Uri of the install
38 * @param home, The absolute path if the install root.
39 * @param name, The name of the servlet (usually "Mir")
40 * @param confName, the name of the config file to load.
42 public static void initConfig(String home, String uri, String name, String confName) {
43 initConfResource(confName);
45 configHash.put("Home", home);
46 configHash.put("RootUri", uri);
48 Enumeration resKeys = getResourceKeys();
49 while(resKeys.hasMoreElements()) {
50 String keyNm = (String)resKeys.nextElement();
51 configHash.put(keyNm, getProperty(keyNm));
55 * Returns the property asked for by pulling it out a HashMap
56 * @param a String containing the property name (key)
57 * @return a String containing the prop. value
59 public static void setServletName(String servletName) {
60 configHash.put("ServletName",servletName);
64 * Returns the property asked for by pulling it out a HashMap
65 * @param a String containing the property name (key)
66 * @return a String containing the prop. value
68 public static String getProp(String propName) {
69 return (String)configHash.get(propName);
73 * Returns the property asked for by pulling it out a HashMap and
74 * appending it to configproperty "Home"
75 * @param a String containing the property name (key)
76 * @return a String containing the prop.value
78 public static String getPropWithHome(String propName) {
79 return (String)configHash.get("Home") +
80 (String)configHash.get(propName);
83 public static void addBroker(String driver, String URL) throws StorageObjectException {
85 String username,passwd,min,max,log,reset,dbname,dblogfile;
87 if(!brokerHash.containsKey("Pool.broker")){
88 username=getProp("Database.Username");
89 passwd=getProp("Database.Password");
90 min=getProp("Database.poolMin");
91 max=getProp("Database.poolMax");
92 dbname=getProp("Database.Name");
93 log=getProp("Home")+ configHash.get("Database.PoolLog" + ".pool");
94 reset=getProp("Database.poolResetTime");
95 dblogfile=getPropWithHome("Database.Logfile");
97 System.err.println("-- making Broker for -"
99 + " log " + log + " user "
100 + username + " pass: " + passwd);
102 JDBCPoolMetaData meta = new JDBCPoolMetaData();
103 meta.setDbname(dbname);
104 meta.setDriver(driver);
106 meta.setUserName(username);
107 meta.setPassword(passwd);
108 meta.setJNDIName("mir");
109 meta.setMaximumSize(Integer.parseInt(max));
110 meta.setMinimumSize(Integer.parseInt(min));
111 meta.setCacheEnabled(true);
112 //meta.setDebugging(true);
113 meta.setLogFile(dblogfile);
115 JDBCPool pool = SQLManager.getInstance().createPool(meta);
119 brokerHash.put("Pool.broker",pool);
128 public void finalize(){
132 } catch (Throwable t) {}