import java.io.*;
import java.util.*;
import java.lang.*;
-import com.javaexchange.dbConnectionBroker.*;
/**
*/
public class Configuration {
+ private static int instances=0;
+
private static HashMap confs = new HashMap(); // key: conffilename, confHash
- private static HashMap c = new HashMap();
private String confFilename;
+
private static String defaultconfFilename;
- private static int instances=0;
static ResourceBundle conf;
- public static void initConfig(String confName) {
+ protected static void initConfResource(String confName) {
conf = ResourceBundle.getBundle(confName);
confs.put("confname",confName);
}
- public static void addBroker(String driver, String URL){
-
- System.err.println("--trying to add broker");
- String username,passwd,min,max,log,reset;
-
- if(!c.containsKey("Pool.broker")){
- username=conf.getString("Database.Username");
- passwd=conf.getString("Database.Password");
- min=conf.getString("Database.poolMin");
- max=conf.getString("Database.poolMax");
- log=conf.getString("Home") + conf.getString("Database.PoolLog");
- reset=conf.getString("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++;
- c.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
+ protected static Enumeration getResourceKeys() {
+ return conf.getKeys();
}
* Fragt ab, ob das Betriebssystem Windows ist.
* @return true wenn ja, sonst false.
*/
- public static boolean isWindows() {
+ protected static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;
}
* @param propName
* @return Wert der Property
*/
- public static String getProperty(String propName) { // default
+ protected static String getProperty(String propName) { // default
return conf.getString(propName);
}
+
+ /**
+ * Checks if open posting should be direct or indirect
+ * @return true if open posting should be direct
+ */
+ protected static boolean directOp() {
+ String op = conf.getString("DirectOpenposting");
+ if(op.equals("yes") || op.equals("Yes") || op.equals("y") || op.equals("Y")){
+ return true;
+ }
+ return false;
+ }
/**
* Liest eine Property eines Modules aus der Konfiguration
* @param propName
* @return Wert der Property
*/
- public String getProperty(String filename ,String theModule, String propName) {
+ protected String getProperty(String filename ,String theModule, String propName) {
return getProperty(filename, theModule + "." + propName);
}
* @param propName
* @return Wert der Property
*/
- public static String getProperty(String filename, String propName) {
+ protected static String getProperty(String filename, String propName) {
if (filename != null) {
String prop = null;
HashMap conf = ((HashMap)confs.get("confname"));
}
/**
- * Liefert DBConnectionBroker einer Configuration zurueck
- * @param confFilename
- * @return DBConnectionBroker
- */
- public static DbConnectionBroker getBroker() {
- DbConnectionBroker broker=null;
- broker=(DbConnectionBroker)c.get("Pool.broker");
- if (broker==null) {
- System.err.println("Konnte kein ConnectionPoolBroker initialisiert werden");
- }
- return broker;
- }
-
- /**
* Liefert Hashtabel mit den Konfigurationen
* @return
*/
return confs;
}
- public static DbConnectionBroker getBrokerInfo(){
- return (DbConnectionBroker)c.get("Pool.broker");
- }
-
/**
* Finalize Methode
*/
- public void finalize(){
+ protected void finalize(){
instances --;
try {
super.finalize();
} catch (Throwable t) {}
}
- /**
- * Liefert Anzahl der Instantiierten DBConnectionBroker zurueck
- * @return
- */
- public static int getBrokerInstances() {
- return instances;
- }
} //end of class