Extended SCGI DirServer with some logging.
[jsvc.git] / src / dolda / jsvc / util / SimpleContext.java
1 package dolda.jsvc.util;
2
3 import java.io.*;
4 import java.util.*;
5 import dolda.jsvc.*;
6
7 public class SimpleContext implements ServerContext {
8     private final long ctime;
9     private final String name;
10     public final ClassLoader loader;
11     protected final Properties sysconfig, libconfig;
12     
13     private void loadconfig() {
14         try {
15             InputStream pi = loader.getResourceAsStream("jsvc.properties");
16             if(pi != null) {
17                 try {
18                     libconfig.load(pi);
19                 } finally {
20                     pi.close();
21                 }
22             }
23         } catch(IOException e) {
24             throw(new Error(e));
25         }
26     }
27
28     public SimpleContext(ClassLoader cl, String name) {
29         this.ctime = System.currentTimeMillis();
30         this.name = name;
31         this.loader = cl;
32         sysconfig = new Properties();
33         libconfig = new Properties();
34         
35         loadconfig();
36     }
37     
38     public long starttime() {
39         return(ctime);
40     }
41     
42     public String name() {
43         return(name);
44     }
45
46     public String sysconfig(String key, String def) {
47         return(sysconfig.getProperty(key, def));
48     }
49     
50     public String libconfig(String key, String def) {
51         return(libconfig.getProperty(key, def));
52     }
53     
54     public RequestThread worker(Responder root, Request req, ThreadGroup tg, String name) {
55         return(new RequestThread(root, req, tg, name));
56     }
57 }