3 import javax.servlet.http.*;
8 import com.javaexchange.dbConnectionBroker.*;
9 import mir.storage.StorageObjectException;
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;
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 log=getProp("Home") + configHash.get("Database.PoolLog");
93 reset=getProp("Database.poolResetTime");
96 System.err.println("-- making Broker for -"
98 + " log " + log + " user "
99 + username + " pass: " + passwd);
101 DbConnectionBroker br = new DbConnectionBroker(driver,URL,username,passwd,(new Integer(min)).intValue(),
102 (new Integer(max)).intValue(),log,(new Float(reset)).floatValue());
105 brokerHash.put("Pool.broker",br);
107 } catch(IOException e){
108 System.err.println("Der ConnectionBroker konnte nicht initializiert werden"+ e.toString());e.printStackTrace();
109 throw new StorageObjectException(e.toString());
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) {}