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();
}
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) {
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() {
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;
} 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();
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);
}
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);