Improved the configuration structure.
[jsvc.git] / src / dolda / jsvc / j2ee / J2eeContext.java
index 696e32b..84ce918 100644 (file)
@@ -3,24 +3,44 @@ package dolda.jsvc.j2ee;
 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 {
-    private ServletConfig cfg;
-    private HttpServletRequest req;
-    private HttpServletResponse resp;
+public abstract class J2eeContext implements ServerContext {
+    private final ServletConfig sc;
+    private final long ctime;
+    protected final Properties sysconfig, libconfig;
     
-    J2eeContext(ServletConfig cfg, HttpServletRequest req, HttpServletResponse resp) {
-       this.cfg = cfg;
-       this.req = req;
-       this.resp = resp;
+    protected J2eeContext(ServletConfig sc) {
+       this.sc = sc;
+       this.ctime = System.currentTimeMillis();
+       sysconfig = new Properties();
+       libconfig = new Properties();
     }
     
-    public String rootpath() {
-       return("/" + Misc.stripslashes(req.getContextPath(), true, true));
+    static J2eeContext create(ServletConfig sc) {
+       if(TomcatContext.tomcatp(sc))
+           return(new TomcatContext(sc));
+       return(new StandardContext(sc));
     }
     
     public long starttime() {
-       return((Long)cfg.getServletContext().getAttribute("jsvc.starttime"));
+       return(ctime);
+    }
+    
+    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);
     }
 }