From 80d07bdbf2dfec3f9de5d5b552539807dd1be383 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Mon, 7 Dec 2015 21:56:52 +0100 Subject: [PATCH] Added property methods to HalContext Former-commit-id: 2d2d1877ea892be4013fdb35394fe94eba91f58a --- src/se/koc/hal/HalContext.java | 16 +++++++++++++--- src/se/koc/hal/PowerChallenge.java | 3 +-- .../hal/deamon/DataSynchronizationDaemon.java | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/se/koc/hal/HalContext.java b/src/se/koc/hal/HalContext.java index 6259d59b..59532de6 100755 --- a/src/se/koc/hal/HalContext.java +++ b/src/se/koc/hal/HalContext.java @@ -12,7 +12,7 @@ public class HalContext { // Variables private static DBConnection db; - public static Properties conf; + private static Properties fileConf; private static Properties defaultConf; @@ -28,9 +28,9 @@ public class HalContext { public static void initialize(){ try { // Read conf - conf = new Properties(defaultConf); + fileConf = new Properties(defaultConf); FileReader in = new FileReader(CONF_FILE); - conf.load(in); + fileConf.load(in); in.close(); // Init DB @@ -41,6 +41,16 @@ public class HalContext { } + public static String getStringProperty(String key){ + String value = fileConf.getProperty(key); + //if(value == null) // TODO: DB property + // value = dbConf.getProperty(key); + return value; + } + public static int getIntegerProperty(String key){ + return Integer.parseInt(getStringProperty(key)); + } + public static DBConnection getDB(){ return db; } diff --git a/src/se/koc/hal/PowerChallenge.java b/src/se/koc/hal/PowerChallenge.java index a2def8ab..4813c70c 100755 --- a/src/se/koc/hal/PowerChallenge.java +++ b/src/se/koc/hal/PowerChallenge.java @@ -41,8 +41,7 @@ public class PowerChallenge { daemon.initiate(daemonTimer); } - HttpServer http = new HttpServer( - Integer.parseInt(HalContext.conf.getProperty("http_port"))); + HttpServer http = new HttpServer(HalContext.getIntegerProperty("http_port")); http.setDefaultPage(new HttpFilePage(FileUtil.find("web-resource/"))); http.setPage("/", new PCOverviewHttpPage()); http.setPage("/configure", new PCConfigureHttpPage()); diff --git a/src/se/koc/hal/deamon/DataSynchronizationDaemon.java b/src/se/koc/hal/deamon/DataSynchronizationDaemon.java index 1cadd510..be469917 100755 --- a/src/se/koc/hal/deamon/DataSynchronizationDaemon.java +++ b/src/se/koc/hal/deamon/DataSynchronizationDaemon.java @@ -24,7 +24,7 @@ public class DataSynchronizationDaemon extends ThreadedTCPNetworkServer implemen public DataSynchronizationDaemon() { - super(Integer.parseInt(HalContext.conf.getProperty("sync_port"))); + super(HalContext.getIntegerProperty("sync_port")); } @Override