postgresql.jar for the OID hack
[mir.git] / source / mir / misc / MirConfig.java
1 package  mir.misc;
2
3 import  javax.servlet.http.*;
4 import  java.net.*;
5 import  java.io.*;
6 import  java.util.*;
7 import  java.lang.*;
8 import  mir.storage.StorageObjectException;
9 import com.codestudio.util.*;
10
11 /**
12  * Title:        Mir
13  * Description:  Class that allows access to all Mir
14  *               config values
15  * Copyright:    Copyright (c) 2001
16  * Company:      Indymedia
17  * @author       mh <heckmann@hbe.ca>
18  * @version 0.1
19  */
20
21
22 /**
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.
26  */
27
28 public class MirConfig extends Configuration {
29
30   private static HashMap configHash = new HashMap();
31   private static HashMap brokerHash = new HashMap();
32   private static int      instances=0;
33
34   /**
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.
41    */
42   public static void initConfig(String home, String uri, String name, String confName) {
43     initConfResource(confName);
44
45     configHash.put("Home", home);
46     configHash.put("RootUri", uri);
47
48     Enumeration resKeys = getResourceKeys();
49     while(resKeys.hasMoreElements()) {
50       String keyNm = (String)resKeys.nextElement();
51       configHash.put(keyNm, getProperty(keyNm));
52     }
53   }
54   /**
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
58    */
59   public static void setServletName(String servletName) {
60     configHash.put("ServletName",servletName);
61   }
62
63   /**
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
67    */
68   public static String getProp(String propName) {
69     return (String)configHash.get(propName);
70   }
71
72   /**
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
77    */
78   public static String getPropWithHome(String propName) {
79     return (String)configHash.get("Home") +
80            (String)configHash.get(propName);
81   }
82
83   public static void addBroker(String driver, String URL) throws StorageObjectException {
84
85     String username,passwd,min,max,log,reset,dbname,dblogfile;
86
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");
94       reset=getProp("Database.poolResetTime");
95       dblogfile=getPropWithHome("Database.Logfile");
96
97       System.err.println("-- making Broker for -"
98                           +driver+" - " +URL
99                           + " log " + log + " user "
100                           + username + " pass: " + passwd);
101
102       JDBCPoolMetaData meta = new JDBCPoolMetaData();
103       meta.setDbname(dbname);
104       meta.setDriver(driver);
105       meta.setURL(URL);
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+".pool");
114
115       JDBCPool pool = SQLManager.getInstance().createPool(meta);
116
117       if (pool!=null){
118         instances++;
119         brokerHash.put("Pool.broker",pool);
120       }
121
122     } // end if
123   }
124
125   /**
126    * Finalize method
127    */
128   public void finalize(){
129     instances --;
130     try {
131       super.finalize();
132     } catch (Throwable t) {}
133   }
134
135 }