org.chwf.servlet
Class RequestParameterMap

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.HashMap
              |
              +--org.chwf.servlet.RequestParameterMap
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class RequestParameterMap
extends java.util.HashMap

A Map class to that caches servlet request data. Internally, this map holds arrays of strings (to handle request parameters with multiple values), but its get() method returns individual string objects (the first string in the array). This class overrides the put() and remove() methods to disable them.

This object does not keep a reference to the request, so it is safe to cache this object in the session or to serialize it.

Author:
Paul Strack
See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
static java.lang.String CACHING_NAME
          Name used to cache the map in the request or session.
 
Constructor Summary
RequestParameterMap(javax.servlet.ServletRequest request)
          Constructor that initializes the map from the request.
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Overrides the Map method to return a single string.
 java.lang.String getParameter(java.lang.String name)
          Returns a single parameter value for the given name.
 java.lang.String[] getParameterValues(java.lang.String name)
          Returns all parameter values for the given name.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Throws UnsupportedOperationException.
 java.lang.Object remove(java.lang.Object key)
          Throws UnsupportedOperationException.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

CACHING_NAME

public static final java.lang.String CACHING_NAME
Name used to cache the map in the request or session.
Constructor Detail

RequestParameterMap

public RequestParameterMap(javax.servlet.ServletRequest request)
Constructor that initializes the map from the request.

Parameters:
request - The request.
Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Throws UnsupportedOperationException.

Overrides:
put in class java.util.HashMap
Parameters:
key - The key.
value - The value.
Returns:
The original value.

remove

public java.lang.Object remove(java.lang.Object key)
Throws UnsupportedOperationException.

Overrides:
remove in class java.util.HashMap
Parameters:
key - The key.
Returns:
The original value.

get

public java.lang.Object get(java.lang.Object key)
Overrides the Map method to return a single string.

Overrides:
get in class java.util.HashMap
Parameters:
key - The key.
Returns:
The value.

getParameter

public java.lang.String getParameter(java.lang.String name)
Returns a single parameter value for the given name.

Parameters:
name - The parameter name.
Returns:
The value as a String or null if not found.

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Returns all parameter values for the given name.

Parameters:
name - The parameter name.
Returns:
The values in an array of Strings or null if not found.


Copyright © 2002-2004, Paul Strack. All Rights Reserved.