View Javadoc

    1   /*
    2    * $Id: ValueStackShadowMap.java 471756 2006-11-06 15:01:43Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    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  }