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