Author: lukaszlenart Date: Thu Feb 18 13:45:08 2010 New Revision: 911398 URL: http://svn.apache.org/viewvc?rev=911398&view=rev Log: Solved WW-3385 - proper implementation of put() method to reflect Map interface specification
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ApplicationMap.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/RequestMap.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ApplicationMap.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ApplicationMap.java?rev=911398&r1=911397&r2=911398&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ApplicationMap.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ApplicationMap.java Thu Feb 18 13:45:08 2010 @@ -21,6 +21,7 @@ package org.apache.struts2.dispatcher; +import javax.servlet.ServletContext; import java.io.Serializable; import java.util.AbstractMap; import java.util.Enumeration; @@ -28,15 +29,12 @@ import java.util.Map; import java.util.Set; -import javax.servlet.ServletContext; - /** * A simple implementation of the {...@link java.util.Map} interface to handle a collection of attributes and * init parameters in a {...@link javax.servlet.ServletContext} object. The {...@link #entrySet()} method * enumerates over all servlet context attributes and init parameters and returns a collection of both. * Note, this will occur lazily - only when the entry set is asked for. - * */ public class ApplicationMap extends AbstractMap implements Serializable { @@ -87,7 +85,7 @@ entries.add(new Map.Entry() { public boolean equals(Object obj) { if (!(obj instanceof Map.Entry)) { - return false; + return false; } Map.Entry entry = (Map.Entry) obj; @@ -123,7 +121,7 @@ entries.add(new Map.Entry() { public boolean equals(Object obj) { if (!(obj instanceof Map.Entry)) { - return false; + return false; } Map.Entry entry = (Map.Entry) obj; @@ -178,10 +176,10 @@ * @return the attribute that was just set. */ public Object put(Object key, Object value) { + Object oldValue = get(key); entries = null; context.setAttribute(key.toString(), value); - - return get(key); + return oldValue; } /** Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/RequestMap.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/RequestMap.java?rev=911398&r1=911397&r2=911398&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/RequestMap.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/RequestMap.java Thu Feb 18 13:45:08 2010 @@ -21,14 +21,13 @@ package org.apache.struts2.dispatcher; +import javax.servlet.http.HttpServletRequest; import java.io.Serializable; import java.util.AbstractMap; import java.util.Enumeration; import java.util.HashSet; import java.util.Set; -import javax.servlet.http.HttpServletRequest; - /** * A simple implementation of the {...@link java.util.Map} interface to handle a collection of request attributes. @@ -81,7 +80,7 @@ entries.add(new Entry() { public boolean equals(Object obj) { if (!(obj instanceof Entry)) { - return false; + return false; } Entry entry = (Entry) obj; @@ -130,10 +129,10 @@ * @return the object that was just set. */ public Object put(Object key, Object value) { + Object oldValue = get(key); entries = null; request.setAttribute(key.toString(), value); - - return get(key); + return oldValue; } /** Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java?rev=911398&r1=911397&r2=911398&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java Thu Feb 18 13:45:08 2010 @@ -21,6 +21,8 @@ package org.apache.struts2.dispatcher; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import java.io.Serializable; import java.util.AbstractMap; import java.util.Collections; @@ -29,22 +31,18 @@ import java.util.Map; import java.util.Set; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; - /** * A simple implementation of the {...@link java.util.Map} interface to handle a collection of HTTP session * attributes. The {...@link #entrySet()} method enumerates over all session attributes and creates a Set of entries. * Note, this will occur lazily - only when the entry set is asked for. - * */ -public class SessionMap<K, V> extends AbstractMap<K,V> implements Serializable { +public class SessionMap<K, V> extends AbstractMap<K, V> implements Serializable { private static final long serialVersionUID = 4678843241638046854L; protected HttpSession session; - protected Set<Map.Entry<K,V>> entries; + protected Set<Map.Entry<K, V>> entries; protected HttpServletRequest request; @@ -82,14 +80,14 @@ * map. */ public void clear() { - if (session == null ) { + if (session == null) { return; } synchronized (session) { entries = null; Enumeration<String> attributeNamesEnum = session.getAttributeNames(); - while(attributeNamesEnum.hasMoreElements()) { + while (attributeNamesEnum.hasMoreElements()) { session.removeAttribute(attributeNamesEnum.nextElement()); } } @@ -101,24 +99,24 @@ * * @return a Set of attributes from the http session. */ - public Set<java.util.Map.Entry<K,V>> entrySet() { + public Set<java.util.Map.Entry<K, V>> entrySet() { if (session == null) { return Collections.emptySet(); } synchronized (session) { if (entries == null) { - entries = new HashSet<Map.Entry<K,V>>(); + entries = new HashSet<Map.Entry<K, V>>(); Enumeration<? extends Object> enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { final String key = enumeration.nextElement().toString(); final Object value = session.getAttribute(key); - entries.add(new Map.Entry<K,V>() { + entries.add(new Map.Entry<K, V>() { public boolean equals(Object obj) { if (!(obj instanceof Map.Entry)) { - return false; + return false; } Map.Entry<K, V> entry = (Map.Entry<K, V>) obj; @@ -179,12 +177,11 @@ session = request.getSession(true); } } - synchronized (session) { + V oldValue = get(key); entries = null; session.setAttribute(key.toString(), value); - - return get(key); + return oldValue; } } @@ -209,7 +206,7 @@ } } - + /** * Checks if the specified session attribute with the given key exists. *