summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-03 16:52:07 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-03 16:52:07 +0100
commit1be8d7ee97a96f79e75f43710f8322611c5a1e24 (patch)
treedce84f10c9db94bad9530bc71a0d638f5f5409cd /same/src/main/java/com
parent1c7bbed107d0767536c93a092dbf192a6a45a620 (diff)
Add Configuration system.
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r--same/src/main/java/com/orbekk/same/config/Configuration.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/same/config/Configuration.java b/same/src/main/java/com/orbekk/same/config/Configuration.java
new file mode 100644
index 0000000..dce9dee
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/config/Configuration.java
@@ -0,0 +1,52 @@
+package com.orbekk.same.config;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Configuration {
+ public final static String configurationProperty =
+ "com.orbekk.same.config.file";
+
+ Logger logger = LoggerFactory.getLogger(getClass());
+ Properties configuration = new Properties();
+
+ private Configuration() {
+ // Use factory methods.
+ }
+
+ public static Configuration load() {
+ Configuration configuration = new Configuration();
+ configuration.loadDefault();
+ return configuration;
+ }
+
+ public void loadDefault() {
+ String filename = System.getProperty(configurationProperty);
+ if (filename != null) {
+ try {
+ configuration.load(new FileReader(filename));
+ } catch (FileNotFoundException e) {
+ logger.error("Failed to load configuration. {}", e);
+ logger.error("Failed to load configuration. {}={}",
+ configurationProperty, filename);
+ } catch (IOException e) {
+ logger.error("Failed to load configuration. {}", e);
+ logger.error("Failed to load configuration. {}={}",
+ configurationProperty, filename);
+ }
+ } else {
+ logger.error("Failed to load configuration. {}={}",
+ configurationProperty, filename);
+ }
+ }
+
+ public String getProperty(String name) {
+ return configuration.getProperty(name);
+ }
+}