public class Config
{
- static Config instance;
- Properties config = new Properties();
-
- public static String get(String key, String defaultValue)
- {
- load();
-
- if (instance == null)
- return defaultValue;
- else {
- String rv = instance.config.getProperty(key);
- if (rv == null)
- return defaultValue;
- return rv;
- }
- }
-
- public static String get(String key)
- {
- String rv = get(key, null);
- if (rv == null)
- throw new ConfigurationException("missing configuration parameter: " + key);
- return rv;
- }
-
- static void load()
- {
- if (instance == null)
- try {
- instance = new Config();
- }
- catch (InvalidPropertiesFormatException e) {}
- catch (FileNotFoundException e) {}
- catch (IOException e) {}
- }
-
- Config()
- throws InvalidPropertiesFormatException, FileNotFoundException, IOException
- {
- config.loadFromXML(new FileInputStream("config.xml"));
- }
-
+ static Config instance;
+ Properties config = new Properties();
+
+ public static String get(String key, String defaultValue)
+ {
+ load();
+
+ if (instance == null) return defaultValue;
+ else {
+ String rv = instance.config.getProperty(key);
+ if (rv == null) return defaultValue;
+ return rv;
+ }
+ }
+
+ public static String get(String key)
+ {
+ String rv = get(key, null);
+ if (rv == null) throw new ConfigurationException(
+ "missing configuration parameter: " + key);
+ return rv;
+ }
+
+ static void load()
+ {
+ if (instance == null) try {
+ instance = new Config();
+ }
+ catch (InvalidPropertiesFormatException e) {}
+ catch (FileNotFoundException e) {}
+ catch (IOException e) {}
+ }
+
+ Config() throws InvalidPropertiesFormatException, FileNotFoundException,
+ IOException
+ {
+ config.loadFromXML(new FileInputStream("config.xml"));
+ }
+
}