--- /dev/null
+/*
+ * put your module comment here
+ */
+
+
+package mir.misc;
+
+import javax.servlet.http.*;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+import java.lang.*;
+import com.javaexchange.dbConnectionBroker.*;
+
+/**
+ * Title: Mir
+ * Description: Class that allows access to all Mir
+ * config values
+ * Copyright: Copyright (c) 2001
+ * Company: Indymedia
+ * @author mh <heckmann@hbe.ca>
+ * @version 0.1
+ */
+
+
+/**
+ * This class is a layer above the Configuration
+ * It manages access to config variables that are
+ * both generated on the fly and found in the config file.
+ */
+
+public class MirConfig extends Configuration {
+
+ private static HashMap configHash = new HashMap();
+ private static HashMap brokerHash = new HashMap();
+
+ private static int instances=0;
+
+ /**
+ * Initializes Configuration hash that contains all values.
+ * loads the config.properties file and any other values
+ * @param Uri, the root Uri of the install
+ * @param Home, The absolute path if the install root.
+ * @param Name, The name of the servlet (usually "Mir")
+ * @param confName, the name of the config file to load.
+ */
+ public static void initConfig(String Home, String Uri, String Name, String confName) {
+ initConfResource(confName);
+
+ configHash.put("Home", Home);
+ configHash.put("RootUri", Uri);
+ configHash.put("ServletName", Name);
+
+ Enumeration ResKeys = getResourceKeys();
+ while(ResKeys.hasMoreElements()) {
+ String keyNm = (String)ResKeys.nextElement();
+ configHash.put(keyNm, getProperty(keyNm));
+ }
+ }
+
+ /**
+ * Returns the property asked for by pulling it out a HashMap
+ * @param a String containing the property name (key)
+ * @return a String containing the prop. value
+ */
+ public static String getProp(String PropName) {
+ return (String)configHash.get(PropName);
+ }
+
+ public static void addBroker(String driver, String URL){
+
+ System.err.println("--trying to add broker");
+ String username,passwd,min,max,log,reset;
+
+ if(!brokerHash.containsKey("Pool.broker")){
+ username=getProp("Database.Username");
+ passwd=getProp("Database.Password");
+ min=getProp("Database.poolMin");
+ max=getProp("Database.poolMax");
+ log=getProp("Home") + configHash.get("Database.PoolLog");
+ reset=getProp("Database.poolResetTime");
+
+ try{
+ System.err.println("-- making Broker for -"
+ +driver+" - " +URL
+ + " log " + log + " user "
+ + username + " pass: " + passwd);
+
+ DbConnectionBroker br = new DbConnectionBroker(driver,URL,username,passwd,(new Integer(min)).intValue(),
+ (new Integer(max)).intValue(),log,(new Float(reset)).floatValue());
+ if (br!=null){
+ instances++;
+ brokerHash.put("Pool.broker",br);
+ } else {
+ throw new Exception();
+ }
+ } catch(Exception e){
+ System.err.println("Der ConnectionBroker konnte nicht initializiert werden"+ e.toString());e.printStackTrace();
+ }
+ } // end if
+ }
+
+ /**
+ * Liefert DBConnectionBroker einer Configuration zurueck
+ * @param confFilename
+ * @return DBConnectionBroker
+ */
+ public static DbConnectionBroker getBroker() {
+ DbConnectionBroker broker=null;
+ broker=(DbConnectionBroker)brokerHash.get("Pool.broker");
+ if (broker==null) {
+ System.err.println("Konnte kein ConnectionPoolBroker initialisiert werden");
+ }
+ return broker;
+ }
+
+ /**
+ * Liefert Anzahl der Instantiierten DBConnectionBroker zurueck
+ * @return
+ */
+ public static int getBrokerInstances() {
+ return instances;
+ }
+
+ public static DbConnectionBroker getBrokerInfo(){
+ return (DbConnectionBroker)brokerHash.get("Pool.broker");
+ }
+
+ /**
+ * Finalize Methode
+ */
+ public void finalize(){
+ instances --;
+ try {
+ super.finalize();
+ } catch (Throwable t) {}
+ }
+
+
+}