3 import javax.servlet.http.*;
8 import com.javaexchange.dbConnectionBroker.*;
12 * Description: Class that allows access to all Mir
14 * Copyright: Copyright (c) 2001
16 * @author mh <heckmann@hbe.ca>
22 * This class is a layer above the Configuration
23 * It manages access to config variables that are
24 * both generated on the fly and found in the config file.
27 public class MirConfig extends Configuration {
29 private static HashMap configHash = new HashMap();
30 private static HashMap brokerHash = new HashMap();
31 private static int instances=0;
34 * Initializes Configuration hash that contains all values.
35 * loads the properties-file and any other values
36 * @param uri, the root Uri of the install
37 * @param home, The absolute path if the install root.
38 * @param name, The name of the servlet (usually "Mir")
39 * @param confName, the name of the config file to load.
41 public static void initConfig(String home, String uri, String name, String confName) {
42 initConfResource(confName);
44 configHash.put("Home", home);
45 configHash.put("RootUri", uri);
46 configHash.put("ServletName", name);
48 Enumeration resKeys = getResourceKeys();
49 while(resKeys.hasMoreElements()) {
50 String keyNm = (String)resKeys.nextElement();
51 configHash.put(keyNm, getProperty(keyNm));
56 * Returns the property asked for by pulling it out a HashMap
57 * @param a String containing the property name (key)
58 * @return a String containing the prop. value
60 public static String getProp(String PropName) {
61 return (String)configHash.get(PropName);
64 public static void addBroker(String driver, String URL){
66 System.err.println("--trying to add broker");
67 String username,passwd,min,max,log,reset;
69 if(!brokerHash.containsKey("Pool.broker")){
70 username=getProp("Database.Username");
71 passwd=getProp("Database.Password");
72 min=getProp("Database.poolMin");
73 max=getProp("Database.poolMax");
74 log=getProp("Home") + configHash.get("Database.PoolLog");
75 reset=getProp("Database.poolResetTime");
78 System.err.println("-- making Broker for -"
80 + " log " + log + " user "
81 + username + " pass: " + passwd);
83 DbConnectionBroker br = new DbConnectionBroker(driver,URL,username,passwd,(new Integer(min)).intValue(),
84 (new Integer(max)).intValue(),log,(new Float(reset)).floatValue());
87 brokerHash.put("Pool.broker",br);
89 throw new Exception();
92 System.err.println("Der ConnectionBroker konnte nicht initializiert werden"+ e.toString());e.printStackTrace();
98 * Liefert DBConnectionBroker einer Configuration zurueck
100 * @return DBConnectionBroker
102 public static DbConnectionBroker getBroker() {
103 DbConnectionBroker broker=null;
104 broker=(DbConnectionBroker)brokerHash.get("Pool.broker");
106 System.err.println("Konnte kein ConnectionPoolBroker initialisiert werden");
112 * Liefert Anzahl der Instantiierten DBConnectionBroker zurueck
115 public static int getBrokerInstances() {
119 public static DbConnectionBroker getBrokerInfo(){
120 return (DbConnectionBroker)brokerHash.get("Pool.broker");
126 public void finalize(){
130 } catch (Throwable t) {}