summaryrefslogtreecommitdiff
path: root/same/src/main/java
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-03 17:05:19 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-03 17:05:19 +0100
commit3f0132826854d18c9ca49ab7ff5d9eb5fa11b0e4 (patch)
tree4bf253c1f9d42e92447646786df62eb4225cd34d /same/src/main/java
parent2a3c456255115d5975933e43a675701b68eff7d1 (diff)
Extend configuration.
– Shorter method names. – Add loadOrDie().
Diffstat (limited to 'same/src/main/java')
-rw-r--r--same/src/main/java/com/orbekk/same/config/Configuration.java22
1 files changed, 19 insertions, 3 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));
+ }
}