1 16 package org.apache.myfaces.context.servlet; 17 18 import org.apache.myfaces.util.NullEnumeration; 19 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpSession ; 22 import java.util.Enumeration ; 23 24 40 public class SessionMap extends AbstractAttributeMap 41 { 42 private final HttpServletRequest _httpRequest; 43 44 SessionMap(HttpServletRequest httpRequest) 45 { 46 _httpRequest = httpRequest; 47 } 48 49 protected Object getAttribute(String key) 50 { 51 HttpSession httpSession = getSession(); 52 return (httpSession == null) 53 ? null : httpSession.getAttribute(key.toString()); 54 } 55 56 protected void setAttribute(String key, Object value) 57 { 58 _httpRequest.getSession(true).setAttribute(key, value); 59 } 60 61 protected void removeAttribute(String key) 62 { 63 HttpSession httpSession = getSession(); 64 if (httpSession != null) 65 { 66 httpSession.removeAttribute(key); 67 } 68 } 69 70 protected Enumeration getAttributeNames() 71 { 72 HttpSession httpSession = getSession(); 73 return (httpSession == null) 74 ? NullEnumeration.instance() 75 : httpSession.getAttributeNames(); 76 } 77 78 private HttpSession getSession() 79 { 80 return _httpRequest.getSession(false); 81 } 82 } | Popular Tags |