FileDocCategorySizeDatePackage
RequestMap.javaAPI DocExample4838Mon Jul 23 13:26:38 BST 2007org.apache.struts2.dispatcher

RequestMap

public class RequestMap extends AbstractMap implements Serializable
A simple implementation of the {@link java.util.Map} interface to handle a collection of request attributes.

Fields Summary
private static final long
serialVersionUID
private Set
entries
private HttpServletRequest
request
Constructors Summary
public RequestMap(HttpServletRequest request)
Saves the request to use as the backing for getting and setting values

param
request the http servlet request.



                            
        
        this.request = request;
    
Methods Summary
public voidclear()
Removes all attributes from the request as well as clears entries in this map.

        entries = null;
        Enumeration keys = request.getAttributeNames();

        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            request.removeAttribute(key);
        }
    
public java.util.SetentrySet()
Returns a Set of attributes from the http request.

return
a Set of attributes from the http request.

        if (entries == null) {
            entries = new HashSet<Object>();

            Enumeration enumeration = request.getAttributeNames();

            while (enumeration.hasMoreElements()) {
                final String key = enumeration.nextElement().toString();
                final Object value = request.getAttribute(key);
                entries.add(new Entry() {
                    public boolean equals(Object obj) {
                        Entry entry = (Entry) obj;

                        return ((key == null) ? (entry.getKey() == null) : key.equals(entry.getKey())) && ((value == null) ? (entry.getValue() == null) : value.equals(entry.getValue()));
                    }

                    public int hashCode() {
                        return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode());
                    }

                    public Object getKey() {
                        return key;
                    }

                    public Object getValue() {
                        return value;
                    }

                    public Object setValue(Object obj) {
                        request.setAttribute(key.toString(), obj);

                        return value;
                    }
                });
            }
        }

        return entries;
    
public java.lang.Objectget(java.lang.Object key)
Returns the request attribute associated with the given key or null if it doesn't exist.

param
key the name of the request attribute.
return
the request attribute or null if it doesn't exist.

        return request.getAttribute(key.toString());
    
public java.lang.Objectput(java.lang.Object key, java.lang.Object value)
Saves an attribute in the request.

param
key the name of the request attribute.
param
value the value to set.
return
the object that was just set.

        entries = null;
        request.setAttribute(key.toString(), value);

        return get(key);
    
public java.lang.Objectremove(java.lang.Object key)
Removes the specified request attribute.

param
key the name of the attribute to remove.
return
the value that was removed or null if the value was not found (and hence, not removed).

        entries = null;

        Object value = get(key);
        request.removeAttribute(key.toString());

        return value;