1 16 package org.springframework.webflow.context.servlet; 17 18 import java.util.Iterator ; 19 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpSession ; 22 23 import org.springframework.binding.collection.SharedMap; 24 import org.springframework.binding.collection.StringKeyedMapAdapter; 25 import org.springframework.web.util.WebUtils; 26 import org.springframework.webflow.core.collection.AttributeMapBindingListener; 27 import org.springframework.webflow.core.collection.CollectionUtils; 28 29 35 public class HttpSessionMap extends StringKeyedMapAdapter implements SharedMap { 36 37 40 private HttpServletRequest request; 41 42 45 public HttpSessionMap(HttpServletRequest request) { 46 this.request = request; 47 } 48 49 55 private HttpSession getSession() { 56 return request.getSession(false); 57 } 58 59 protected Object getAttribute(String key) { 60 HttpSession session = getSession(); 61 if (session == null) { 62 return null; 63 } 64 Object value = session.getAttribute(key); 65 if (value instanceof HttpSessionMapBindingListener) { 66 return ((HttpSessionMapBindingListener)value).getListener(); 68 } else { 69 return value; 70 } 71 } 72 73 protected void setAttribute(String key, Object value) { 74 HttpSession session = request.getSession(true); 76 if (value instanceof AttributeMapBindingListener) { 77 session.setAttribute(key, 79 new HttpSessionMapBindingListener((AttributeMapBindingListener)value, this)); 80 } 81 else { 82 session.setAttribute(key, value); 83 } 84 } 85 86 protected void removeAttribute(String key) { 87 HttpSession session = getSession(); 88 if (session != null) { 89 session.removeAttribute(key); 90 } 91 } 92 93 protected Iterator getAttributeNames() { 94 HttpSession session = getSession(); 95 return session == null ? CollectionUtils.EMPTY_ITERATOR : CollectionUtils.toIterator(session 96 .getAttributeNames()); 97 } 98 99 public Object getMutex() { 100 HttpSession session = request.getSession(true); 102 Object mutex = session.getAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE); 103 return mutex != null ? mutex : session; 104 } 105 } | Popular Tags |