Commit | Line | Data |
---|---|---|
36537ce8 FT |
1 | package dolda.jsvc.store; |
2 | ||
3 | import dolda.jsvc.*; | |
4 | import dolda.jsvc.util.Misc; | |
5 | import java.io.*; | |
6 | import java.security.*; | |
7 | import java.security.cert.Certificate; | |
8 | import java.util.*; | |
9 | ||
10 | public class Store { | |
11 | private static Map<Package, Store> interned = new WeakHashMap<Package, Store>(); | |
12 | private final Package pkg; | |
13 | private final File base; | |
14 | ||
b1f70a1c | 15 | private Store(Package pkg, File root) { |
36537ce8 FT |
16 | this.pkg = pkg; |
17 | String nm = pkg.getName(); | |
18 | File base = root; | |
36537ce8 FT |
19 | int p = 0; |
20 | int p2; | |
21 | while((p2 = nm.indexOf('.', p)) >= 0) { | |
22 | base = new File(base, nm.substring(p, p2)); | |
23 | p = p2 + 1; | |
24 | } | |
25 | this.base = new File(base, nm.substring(p)); | |
26 | } | |
27 | ||
28 | private static File getstoreroot() { | |
29 | ThreadContext ctx = ThreadContext.current(); | |
30 | if(ctx == null) | |
31 | throw(new RuntimeException("Not running in jsvc context")); | |
32 | String bn = ctx.server().config("jsvc.storage"); | |
33 | if(bn == null) | |
34 | throw(new RuntimeException("No storage root has been configured")); | |
35 | return(new File(bn)); | |
36 | } | |
37 | ||
38 | public static Store forclass(final Class<?> cl) { | |
39 | Package pkg = cl.getPackage(); | |
40 | File root = getstoreroot(); | |
41 | Store s; | |
42 | synchronized(interned) { | |
43 | s = interned.get(pkg); | |
44 | if(s == null) { | |
b1f70a1c | 45 | s = new Store(pkg, root); |
36537ce8 FT |
46 | interned.put(pkg, s); |
47 | } | |
48 | } | |
49 | return(s); | |
50 | } | |
51 | } |