summaryrefslogtreecommitdiff
path: root/same
diff options
context:
space:
mode:
Diffstat (limited to 'same')
-rw-r--r--same/src/main/java/com/orbekk/same/config/Configuration.java22
-rw-r--r--same/src/test/java/com/orbekk/same/config/ConfigurationTest.java2
2 files changed, 20 insertions, 4 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
index dce9dee..43b77e5 100644
--- a/same/src/main/java/com/orbekk/same/config/Configuration.java
+++ b/same/src/main/java/com/orbekk/same/config/Configuration.java
@@ -13,24 +13,35 @@ public class Configuration {
public final static String configurationProperty =
"com.orbekk.same.config.file";
- Logger logger = LoggerFactory.getLogger(getClass());
+ static final Logger logger = LoggerFactory.getLogger(Configuration.class);
Properties configuration = new Properties();
private Configuration() {
// Use factory methods.
}
+ public static Configuration loadOrDie() {
+ Configuration configuration = new Configuration();
+ boolean status = configuration.loadDefault();
+ if (!status) {
+ logger.error("Could not load configurotion.");
+ System.exit(1);
+ }
+ return configuration;
+ }
+
public static Configuration load() {
Configuration configuration = new Configuration();
configuration.loadDefault();
return configuration;
}
- public void loadDefault() {
+ public boolean loadDefault() {
String filename = System.getProperty(configurationProperty);
if (filename != null) {
try {
configuration.load(new FileReader(filename));
+ return true;
} catch (FileNotFoundException e) {
logger.error("Failed to load configuration. {}", e);
logger.error("Failed to load configuration. {}={}",
@@ -44,9 +55,14 @@ public class Configuration {
logger.error("Failed to load configuration. {}={}",
configurationProperty, filename);
}
+ return false;
}
- public String getProperty(String name) {
+ public String get(String name) {
return configuration.getProperty(name);
}
+
+ public int getInt(String name) {
+ return Integer.valueOf(get(name));
+ }
}
diff --git a/same/src/test/java/com/orbekk/same/config/ConfigurationTest.java b/same/src/test/java/com/orbekk/same/config/ConfigurationTest.java
index e5b42aa..f73d8b5 100644
--- a/same/src/test/java/com/orbekk/same/config/ConfigurationTest.java
+++ b/same/src/test/java/com/orbekk/same/config/ConfigurationTest.java
@@ -11,7 +11,7 @@ public class ConfigurationTest {
resources + "com/orbekk/same/config/test.properties");
Configuration configuration = Configuration.load();
assertEquals("Test Value",
- configuration.getProperty("testProperty"));
+ configuration.get("testProperty"));
}
}