From: Fredrik Tolf Date: Fri, 16 Oct 2009 15:29:37 +0000 (+0200) Subject: Improved the configuration structure. X-Git-Url: http://www.dolda2000.com/gitweb/?p=jsvc.git;a=commitdiff_plain;h=6a0cb6cbc9b46f7e220e27e08b9eaa8805e99d6d Improved the configuration structure. --- diff --git a/src/dolda/jsvc/ServerContext.java b/src/dolda/jsvc/ServerContext.java index acb27d6..423deba 100644 --- a/src/dolda/jsvc/ServerContext.java +++ b/src/dolda/jsvc/ServerContext.java @@ -2,6 +2,7 @@ package dolda.jsvc; public interface ServerContext { public long starttime(); - public String config(String key); + public String sysconfig(String key, String def); + public String libconfig(String key, String def); public String name(); } diff --git a/src/dolda/jsvc/j2ee/J2eeContext.java b/src/dolda/jsvc/j2ee/J2eeContext.java index bf1917c..84ce918 100644 --- a/src/dolda/jsvc/j2ee/J2eeContext.java +++ b/src/dolda/jsvc/j2ee/J2eeContext.java @@ -9,12 +9,13 @@ import java.io.*; public abstract class J2eeContext implements ServerContext { private final ServletConfig sc; private final long ctime; - protected final Properties config; + protected final Properties sysconfig, libconfig; protected J2eeContext(ServletConfig sc) { this.sc = sc; this.ctime = System.currentTimeMillis(); - config = new Properties(); + sysconfig = new Properties(); + libconfig = new Properties(); } static J2eeContext create(ServletConfig sc) { @@ -27,8 +28,16 @@ public abstract class J2eeContext implements ServerContext { return(ctime); } - public String config(String key) { - return((String)config.get(key)); + public String sysconfig(String key, String def) { + return(sysconfig.getProperty(key, def)); + } + + public String libconfig(String key, String def) { + return(libconfig.getProperty(key, def)); + } + + void loadconfig(InputStream in) throws IOException { + libconfig.load(in); } public ServletConfig j2eeconfig() { diff --git a/src/dolda/jsvc/j2ee/Servlet.java b/src/dolda/jsvc/j2ee/Servlet.java index d726474..082113c 100644 --- a/src/dolda/jsvc/j2ee/Servlet.java +++ b/src/dolda/jsvc/j2ee/Servlet.java @@ -11,18 +11,18 @@ public class Servlet extends HttpServlet { private ThreadContext tg; public void init(ServletConfig cfg) throws ServletException { - Properties sprop = new Properties(); + J2eeContext ctx = J2eeContext.create(cfg); try { InputStream pi = Servlet.class.getClassLoader().getResourceAsStream("jsvc.properties"); try { - sprop.load(pi); + ctx.loadconfig(pi); } finally { pi.close(); } } catch(IOException e) { throw(new Error(e)); } - String clnm = (String)sprop.get("jsvc.bootstrap"); + String clnm = ctx.libconfig("jsvc.bootstrap", null); if(clnm == null) throw(new ServletException("No JSvc bootstrapper specified")); Class bc; @@ -31,7 +31,6 @@ public class Servlet extends HttpServlet { } catch(ClassNotFoundException e) { throw(new ServletException("Invalid JSvc bootstrapper specified", e)); } - ServerContext ctx = J2eeContext.create(cfg); String tgn; if(ctx.name() != null) tgn = "JSvc service for " + ctx.name(); diff --git a/src/dolda/jsvc/j2ee/TomcatContext.java b/src/dolda/jsvc/j2ee/TomcatContext.java index bf6312b..8672d39 100644 --- a/src/dolda/jsvc/j2ee/TomcatContext.java +++ b/src/dolda/jsvc/j2ee/TomcatContext.java @@ -58,10 +58,10 @@ public class TomcatContext extends J2eeContext { logger.log(Level.WARNING, "no permissions to fetch Tomcat base directory while reading configuration", e); return; } - config.put("jsvc.storage", "file:" + new File(new File(base, "work"), "jsvc").getPath()); + sysconfig.put("jsvc.storage", "file:" + new File(new File(base, "work"), "jsvc").getPath()); File cdir = new File(base, "conf"); try { - loadprops(config, new File(cdir, "jsvc.properties")); + loadprops(sysconfig, new File(cdir, "jsvc.properties")); } catch(SecurityException e) { logger.log(Level.WARNING, "no permssions to read from Tomcat conf directory while reading configuration", e); } diff --git a/src/dolda/jsvc/store/Store.java b/src/dolda/jsvc/store/Store.java index 0664156..d32b3a2 100644 --- a/src/dolda/jsvc/store/Store.java +++ b/src/dolda/jsvc/store/Store.java @@ -24,7 +24,7 @@ public abstract class Store implements Iterable { ThreadContext ctx = ThreadContext.current(); if(ctx == null) throw(new RuntimeException("Not running in jsvc context")); - String bn = ctx.server().config("jsvc.storage"); + String bn = ctx.server().sysconfig("jsvc.storage", null); if(bn == null) throw(new RuntimeException("No storage root has been configured")); return(bn);