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