import dolda.jsvc.*;
import dolda.jsvc.util.*;
import javax.servlet.*;
-import javax.servlet.http.*;
import java.util.*;
import java.io.*;
-public class J2eeContext implements ServerContext {
+public abstract class J2eeContext implements ServerContext {
private final ServletConfig sc;
private final long ctime;
- private final Properties config;
+ protected final Properties sysconfig, libconfig;
- J2eeContext(ServletConfig sc) {
+ protected J2eeContext(ServletConfig sc) {
this.sc = sc;
this.ctime = System.currentTimeMillis();
- config = readconfig(sc);
- }
-
- private static void loadprops(Properties props, File pfile) {
- if(!pfile.exists())
- return;
- try {
- InputStream in = new FileInputStream(pfile);
- try {
- props.load(in);
- } finally {
- in.close();
- }
- } catch(IOException e) {
- throw(new RuntimeException(e));
- }
+ sysconfig = new Properties();
+ libconfig = new Properties();
}
-
- private static Properties readconfig(ServletConfig sc) {
- /* This only works on Tomcat now, but that's because I've no
- * idea how other J2EE servers work. I don't even know if they
- * _have_ any reasonable place to put configuration and
- * storage. */
- Properties cfg = new Properties();
- String basename = System.getProperty("catalina.base");
- if(basename != null) {
- File base = new File(basename);
- cfg.put("jsvc.storage", new File(new File(base, "work"), "jsvc").getPath());
- File cdir = new File(base, "conf");
- loadprops(cfg, new File(cdir, "jsvc.properties"));
- }
- return(cfg);
+
+ static J2eeContext create(ServletConfig sc) {
+ if(TomcatContext.tomcatp(sc))
+ return(new TomcatContext(sc));
+ return(new StandardContext(sc));
}
public long starttime() {
return(ctime);
}
- public Properties config() {
- return(config);
+ 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() {
return(sc);
}
+
+ public RequestThread worker(Responder root, Request req, ThreadGroup tg, String name) {
+ return(new RequestThread(root, req, tg, name));
+ }
}