01: /*
02: * Created on Nov 8, 2005
03: */
04: package uk.org.ponder.rsf.request;
05:
06: import java.util.ArrayList;
07: import java.util.HashMap;
08: import java.util.List;
09: import java.util.Map;
10:
11: import uk.org.ponder.beanutil.PathUtil;
12: import uk.org.ponder.stringutil.StringList;
13:
14: /**
15: * Takes responsibility for topological sorting of incoming EL in the request
16: * map (which may be arbitrarily disordered)
17: * @author Andrew Thornton (andrew@caret.cam.ac.uk)
18: * @author Antranig Basman (antranig@caret.cam.ac.uk)
19: *
20: */
21: public class ELDependencyMap {
22: public static final List VALID_LIST_MARKER = new ArrayList();
23:
24: public static final String WRITE = "write";
25: public static final String READ = "read";
26:
27: private HashMap writemap = new HashMap();
28: private HashMap readmap = new HashMap();
29:
30: private HashMap mapread = new HashMap();
31: public HashMap mapwrite = new HashMap();
32:
33: public static void recordMap(Map recordin, String upstring,
34: SubmittedValueEntry sve) {
35: ArrayList deps = (ArrayList) recordin.get(upstring);
36: if (deps == null) {
37: deps = new ArrayList();
38: recordin.put(upstring, deps);
39: }
40: deps.add(sve);
41: }
42:
43: public String getReadPath(SubmittedValueEntry sve) {
44: return (String) mapread.get(sve);
45: }
46:
47: public String getWritePath(SubmittedValueEntry sve) {
48: return (String) mapwrite.get(sve);
49: }
50:
51: public void recordWrite(String upstring, SubmittedValueEntry sve) {
52: recordMap(writemap, upstring, sve);
53: mapwrite.put(sve, upstring);
54: }
55:
56: public void recordRead(String upstring, SubmittedValueEntry sve) {
57: recordMap(readmap, upstring, sve);
58: mapread.put(sve, upstring);
59: }
60:
61: public List getReaders(String path) {
62: return (List) readmap.get(path);
63: }
64:
65: public List getWriters(String path) {
66: return (List) writemap.get(path);
67: }
68:
69: public void recordPathValid(String path) {
70: writemap.put(path, VALID_LIST_MARKER);
71: }
72:
73: /** Disused method */
74: public List getInvalidatingEntries(String path) {
75: ArrayList togo = new ArrayList();
76: String[] splitEL = PathUtil.splitPath(path);
77: StringList goup = new StringList();
78: for (int i = 0; i < splitEL.length; ++i) {
79: goup.add(splitEL[i]);
80: String upstring = PathUtil.buildPath(goup.toStringArray());
81: List deps = (List) writemap.get(upstring);
82: if (deps != null) {
83: togo.addAll(deps);
84: }
85: }
86: return togo;
87: }
88: }
|