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);
47 Enumeration resKeys = getResourceKeys();
48 while(resKeys.hasMoreElements()) {
49 String keyNm = (String)resKeys.nextElement();
50 configHash.put(keyNm, getProperty(keyNm));
54 * Returns the property asked for by pulling it out a HashMap
55 * @param a String containing the property name (key)
56 * @return a String containing the prop. value
58 public static void setServletName(String servletName) {
59 configHash.put("ServletName",servletName);
63 * Returns the property asked for by pulling it out a HashMap
64 * @param a String containing the property name (key)
65 * @return a String containing the prop. value
67 public static String getProp(String propName) {
68 return (String)configHash.get(propName);
72 * Returns the property asked for by pulling it out a HashMap and
73 * appending it to configproperty "Home"
74 * @param a String containing the property name (key)
75 * @return a String containing the prop.value
77 public static String getPropWithHome(String propName) {
78 return (String)configHash.get("Home") +
79 (String)configHash.get(propName);
82 public static void addBroker(String driver, String URL){
84 String username,passwd,min,max,log,reset;
86 if(!brokerHash.containsKey("Pool.broker")){
87 username=getProp("Database.Username");
88 passwd=getProp("Database.Password");
89 min=getProp("Database.poolMin");
90 max=getProp("Database.poolMax");
91 log=getProp("Home") + configHash.get("Database.PoolLog");
92 reset=getProp("Database.poolResetTime");
95 System.err.println("-- making Broker for -"
97 + " log " + log + " user "
98 + username + " pass: " + passwd);
100 DbConnectionBroker br = new DbConnectionBroker(driver,URL,username,passwd,(new Integer(min)).intValue(),
101 (new Integer(max)).intValue(),log,(new Float(reset)).floatValue());
104 brokerHash.put("Pool.broker",br);
106 throw new Exception();
108 } catch(Exception e){
109 System.err.println("Der ConnectionBroker konnte nicht initializiert werden"+ e.toString());e.printStackTrace();
115 * Liefert DBConnectionBroker einer Configuration zurueck
116 * @param confFilename
117 * @return DBConnectionBroker
119 public static DbConnectionBroker getBroker() {
120 DbConnectionBroker broker=null;
121 broker=(DbConnectionBroker)brokerHash.get("Pool.broker");
123 System.err.println("Konnte kein ConnectionPoolBroker initialisiert werden");
129 * Liefert Anzahl der Instantiierten DBConnectionBroker zurueck
132 public static int getBrokerInstances() {
136 public static DbConnectionBroker getBrokerInfo(){
137 return (DbConnectionBroker)brokerHash.get("Pool.broker");
143 public void finalize(){
147 } catch (Throwable t) {}