1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.jasperreports;
23
24 import com.opensymphony.xwork2.util.ValueStack;
25
26 import java.util.HashMap;
27 import java.util.Set;
28
29
30 /***
31 * Ported to Struts:
32 *
33 */
34 public class ValueStackShadowMap extends HashMap {
35
36 private static final long serialVersionUID = -167109778490907240L;
37
38 /***
39 * valueStack reference
40 */
41 ValueStack valueStack;
42
43 /***
44 * entries reference
45 */
46 Set entries;
47
48
49 /***
50 * Constructs an instance of ValueStackShadowMap.
51 *
52 * @param valueStack - the underlying valuestack
53 */
54 public ValueStackShadowMap(ValueStack valueStack) {
55 this.valueStack = valueStack;
56 }
57
58
59 /***
60 * Implementation of containsKey(), overriding HashMap implementation.
61 *
62 * @param key - The key to check in HashMap and if not found to check on valueStack.
63 * @return <tt>true</tt>, if conatins key, <tt>false</tt> otherwise.
64 * @see java.util.HashMap#containsKey
65 */
66 public boolean containsKey(Object key) {
67 boolean hasKey = super.containsKey(key);
68
69 if (!hasKey) {
70 if (valueStack.findValue((String) key) != null) {
71 hasKey = true;
72 }
73 }
74
75 return hasKey;
76 }
77
78 /***
79 * Implementation of get(), overriding HashMap implementation.
80 *
81 * @param key - The key to get in HashMap and if not found there from the valueStack.
82 * @return value - The object from HashMap or if null, from the valueStack.
83 * @see java.util.HashMap#get
84 */
85 public Object get(Object key) {
86 Object value = super.get(key);
87
88 if ((value == null) && key instanceof String) {
89 value = valueStack.findValue((String) key);
90 }
91
92 return value;
93 }
94 }