Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/StackFrames.java @ 4594:2970046fcdca
Doc.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 29 Nov 2012 11:48:20 +0100 |
parents | de0c2bbb27f9 |
children | 4d1e2a0c283a 142ed3c62765 |
comparison
equal
deleted
inserted
replaced
4593:047c965ea542 | 4594:2970046fcdca |
---|---|
11 | 11 |
12 import javax.xml.namespace.QName; | 12 import javax.xml.namespace.QName; |
13 | 13 |
14 import org.apache.log4j.Logger; | 14 import org.apache.log4j.Logger; |
15 | 15 |
16 | |
17 /** | |
18 * Maintains stack of 'frames' which are maps from string to object. | |
19 * Used for variables in datacage/meta-data system. | |
20 */ | |
16 public class StackFrames | 21 public class StackFrames |
17 implements XPathVariableResolver | 22 implements XPathVariableResolver |
18 { | 23 { |
19 private static Logger log = Logger.getLogger(StackFrames.class); | 24 private static Logger log = Logger.getLogger(StackFrames.class); |
20 | 25 |
26 /** The frames (used like a stack). */ | |
21 protected List<Map<String, Object>> frames; | 27 protected List<Map<String, Object>> frames; |
22 | 28 |
23 public StackFrames() { | 29 public StackFrames() { |
24 frames = new ArrayList<Map<String, Object>>(); | 30 frames = new ArrayList<Map<String, Object>>(); |
25 } | 31 } |
29 if (initialFrame != null) { | 35 if (initialFrame != null) { |
30 frames.add(new HashMap<String, Object>(initialFrame)); | 36 frames.add(new HashMap<String, Object>(initialFrame)); |
31 } | 37 } |
32 } | 38 } |
33 | 39 |
40 /** Push a new String->Object map. */ | |
34 public void enter() { | 41 public void enter() { |
35 frames.add(new HashMap<String, Object>()); | 42 frames.add(new HashMap<String, Object>()); |
36 } | 43 } |
37 | 44 |
45 /** Pop/Remove last String->Object map. */ | |
38 public void leave() { | 46 public void leave() { |
39 frames.remove(frames.size()-1); | 47 frames.remove(frames.size()-1); |
40 } | 48 } |
41 | 49 |
50 /** Put Key/Value in last String->Object map. */ | |
42 public void put(String key, Object value) { | 51 public void put(String key, Object value) { |
43 int N = frames.size(); | 52 int N = frames.size(); |
44 if (N > 0) { | 53 if (N > 0) { |
45 frames.get(N-1).put(key, value); | 54 frames.get(N-1).put(key, value); |
46 } | 55 } |
47 } | 56 } |
48 | 57 |
58 /** Put multiple Key/Values in last String->Object map. */ | |
49 public void put(String [] keys, Object [] values) { | 59 public void put(String [] keys, Object [] values) { |
50 Map<String, Object> top = frames.get(frames.size()-1); | 60 Map<String, Object> top = frames.get(frames.size()-1); |
51 for (int i = 0; i < keys.length; ++i) { | 61 for (int i = 0; i < keys.length; ++i) { |
52 top.put(keys[i], values[i]); | 62 top.put(keys[i], values[i]); |
53 } | 63 } |
54 } | 64 } |
55 | 65 |
66 /** Check last frame (string->object map) for key. */ | |
56 public boolean containsKey(String key) { | 67 public boolean containsKey(String key) { |
57 key = key.toUpperCase(); | 68 key = key.toUpperCase(); |
58 for (int i = frames.size()-1; i >= 0; --i) { | 69 for (int i = frames.size()-1; i >= 0; --i) { |
59 if (frames.get(i).containsKey(key)) { | 70 if (frames.get(i).containsKey(key)) { |
60 return true; | 71 return true; |
71 */ | 82 */ |
72 public Object get(String key) { | 83 public Object get(String key) { |
73 return get(key, null); | 84 return get(key, null); |
74 } | 85 } |
75 | 86 |
87 /** result[0] is modified with value when true returned. | |
88 * @return false if key not found in any frame. */ | |
76 public boolean getStore(String key, Object [] result) { | 89 public boolean getStore(String key, Object [] result) { |
77 | 90 |
78 key = key.toUpperCase(); | 91 key = key.toUpperCase(); |
79 | 92 |
80 for (int i = frames.size()-1; i >= 0; --i) { | 93 for (int i = frames.size()-1; i >= 0; --i) { |