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