View Javadoc

1   /*
2    * $Id: ValueStackShadowMap.java 451544 2006-09-30 05:38:02Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  }