3 import javax.servlet.http.*;
8 import com.javaexchange.dbConnectionBroker.*;
9 import mir.storage.StorageObjectException;
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 = new HashMap();
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 void initConfig(String home, String uri, String name, String confName) {
44 initConfResource(confName);
46 configHash.put("Home", home);
47 configHash.put("RootUri", uri);
49 Enumeration resKeys = getResourceKeys();
50 while(resKeys.hasMoreElements()) {
51 String keyNm = (String)resKeys.nextElement();
52 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 void setServletName(String servletName) {
61 configHash.put("ServletName",servletName);
65 * Returns the property asked for by pulling it out a HashMap
66 * @param a String containing the property name (key)
67 * @return a String containing the prop. value
69 public static String getProp(String propName) {
70 return (String)configHash.get(propName);
74 * Returns the property asked for by pulling it out a HashMap and
75 * appending it to configproperty "Home"
76 * @param a String containing the property name (key)
77 * @return a String containing the prop.value
79 public static String getPropWithHome(String propName) {
80 return (String)configHash.get("Home") +
81 (String)configHash.get(propName);
84 public static void addBroker(String driver, String URL) throws StorageObjectException {
86 String username,passwd,min,max,log,reset;
88 if(!brokerHash.containsKey("Pool.broker")){
89 username=getProp("Database.Username");
90 passwd=getProp("Database.Password");
91 min=getProp("Database.poolMin");
92 max=getProp("Database.poolMax");
93 log=getProp("Home") + configHash.get("Database.PoolLog");
94 reset=getProp("Database.poolResetTime");
96 System.err.println("-- making Broker for -"
98 + " log " + log + " user "
99 + username + " pass: " + passwd);
101 JDBCPoolMetaData meta = new JDBCPoolMetaData();
102 meta.setDbname("mir");
103 meta.setDriver(driver);
105 meta.setUserName(username);
106 meta.setPassword(passwd);
107 meta.setJNDIName("mir");
108 meta.setMaximumSize(Integer.parseInt(max));
109 meta.setMinimumSize(Integer.parseInt(min));
111 JDBCPool pool = SQLManager.getInstance().createPool(meta);
112 SQLManager.getInstance().addPool("mir",pool);
116 brokerHash.put("Pool.broker",pool);
122 public static void addBroker2(String driver, String URL) throws StorageObjectException {
124 String username,passwd,min,max,log,reset;
126 if(!brokerHash.containsKey("Pool.broker")){
127 username=getProp("Database.Username");
128 passwd=getProp("Database.Password");
129 min=getProp("Database.poolMin");
130 max=getProp("Database.poolMax");
131 log=getProp("Home") + configHash.get("Database.PoolLog");
132 reset=getProp("Database.poolResetTime");
135 System.err.println("-- making Broker for -"
137 + " log " + log + " user "
138 + username + " pass: " + passwd);
140 DbConnectionBroker br = new DbConnectionBroker(driver,URL,username,passwd,(new Integer(min)).intValue(),
141 (new Integer(max)).intValue(),log,(new Float(reset)).floatValue());
144 brokerHash.put("Pool.broker",br);
146 } catch(IOException e){
147 System.err.println("Der ConnectionBroker konnte nicht initializiert werden"+ e.toString());e.printStackTrace();
148 throw new StorageObjectException(e.toString());
156 public void finalize(){
160 } catch (Throwable t) {}