Commits

plightbo  committed acb4637

WW-560: only hold on to the session

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@424573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits c943b7e

Comments (0)

Files changed (1)

File src/java/com/opensymphony/webwork/dispatcher/SessionMap.java

  */
 package com.opensymphony.webwork.dispatcher;
 
-import java.io.Serializable;
-
-import java.util.AbstractMap;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
+import java.io.Serializable;
+import java.util.*;
 
 
 /**
 public class SessionMap extends AbstractMap implements Serializable {
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    HttpServletRequest request;
+    HttpSession session;
     Set entries;
 
     //~ Constructors ///////////////////////////////////////////////////////////
      * @param request the http servlet request object.
      */
     public SessionMap(HttpServletRequest request) {
-        this.request = request;
+        this.session = request.getSession();
     }
 
     //~ Methods ////////////////////////////////////////////////////////////////
      * Removes all attributes from the session as well as clears entries in this map.
      */
     public void clear() {
-        HttpSession session = request.getSession();
-
         synchronized (session) {
             entries = null;
             session.invalidate();
      * @return a Set of attributes from the http session.
      */
     public Set entrySet() {
-        HttpSession session = request.getSession();
-
         synchronized (session) {
             if (entries == null) {
                 entries = new HashSet();
                     final String key = enumeration.nextElement().toString();
                     final Object value = session.getAttribute(key);
                     entries.add(new Map.Entry() {
-                            public boolean equals(Object obj) {
-                                Map.Entry entry = (Map.Entry) obj;
+                        public boolean equals(Object obj) {
+                            Map.Entry entry = (Map.Entry) obj;
 
-                                return ((key == null) ? (entry.getKey() == null) : key.equals(entry.getKey())) && ((value == null) ? (entry.getValue() == null) : value.equals(entry.getValue()));
-                            }
+                            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 int hashCode() {
+                            return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode());
+                        }
 
-                            public Object getKey() {
-                                return key;
-                            }
+                        public Object getKey() {
+                            return key;
+                        }
 
-                            public Object getValue() {
-                                return value;
-                            }
+                        public Object getValue() {
+                            return value;
+                        }
 
-                            public Object setValue(Object obj) {
-                                request.getSession().setAttribute(key.toString(), obj);
+                        public Object setValue(Object obj) {
+                            session.setAttribute(key.toString(), obj);
 
-                                return value;
-                            }
-                        });
+                            return value;
+                        }
+                    });
                 }
             }
         }
      * @return the session attribute or <tt>null</tt> if it doesn't exist.
      */
     public Object get(Object key) {
-        HttpSession session = request.getSession();
-
         synchronized (session) {
             return session.getAttribute(key.toString());
         }
     /**
      * Saves an attribute in the session.
      *
-     * @param key the name of the session attribute.
+     * @param key   the name of the session attribute.
      * @param value the value to set.
      * @return the object that was just set.
      */
     public Object put(Object key, Object value) {
-        HttpSession session = request.getSession();
-
         synchronized (session) {
             entries = null;
             session.setAttribute(key.toString(), value);
 
     /**
      * Removes the specified session attribute.
+     *
      * @param key the name of the attribute to remove.
      * @return the value that was removed or <tt>null</tt> if the value was not found (and hence, not removed).
      */
     public Object remove(Object key) {
-        HttpSession session = request.getSession();
-
         synchronized (session) {
             entries = null;