1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.portals.bridges.jsf;
17
18 import java.util.Enumeration;
19
20 import javax.portlet.PortletRequest;
21 import javax.portlet.PortletSession;
22
23 import org.apache.portals.bridges.jsf.AbstractAttributeMap;
24 import org.apache.portals.bridges.jsf.NullEnumeration;
25
26 /***
27 * <p>
28 * Session attibutes as Map.
29 * </p>
30 * <p>
31 * See MyFaces project for servlet implementation.
32 * </p>
33 *
34 * @author <a href="dlestrat@apache.org">David Le Strat </a>
35 */
36 public class SessionMap extends AbstractAttributeMap
37 {
38 /*** Illegal argument exception message. */
39 final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
40
41 /*** The {@link PortletRequest}. */
42 private final PortletRequest portletRequest;
43
44 /***
45 * @param request The request.
46 */
47 public SessionMap(Object request)
48 {
49 if (request instanceof PortletRequest)
50 {
51 this.portletRequest = (PortletRequest) request;
52 }
53 else
54 {
55 throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
56 }
57 }
58
59 /***
60 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttribute(java.lang.String)
61 */
62 protected Object getAttribute(String key)
63 {
64 if (null != this.portletRequest)
65 {
66 PortletSession portletSession = this.portletRequest.getPortletSession(false);
67 return (portletSession == null) ? null : portletSession.getAttribute(key.toString());
68 }
69 else
70 {
71 throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
72 }
73 }
74
75 /***
76 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#setAttribute(java.lang.String,
77 * java.lang.Object)
78 */
79 protected void setAttribute(String key, Object value)
80 {
81 if (null != this.portletRequest)
82 {
83 this.portletRequest.getPortletSession(true).setAttribute(key, value);
84 }
85 }
86
87 /***
88 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#removeAttribute(java.lang.String)
89 */
90 protected void removeAttribute(String key)
91 {
92 if (null != this.portletRequest)
93 {
94 PortletSession portletSession = this.portletRequest.getPortletSession(false);
95 ;
96 if (null != portletSession)
97 {
98 portletSession.removeAttribute(key);
99 }
100 }
101 }
102
103 /***
104 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttributeNames()
105 */
106 protected Enumeration getAttributeNames()
107 {
108 if (null != this.portletRequest)
109 {
110 PortletSession portletSession = this.portletRequest.getPortletSession(false);
111 ;
112 return (portletSession == null) ? NullEnumeration.instance() : portletSession.getAttributeNames();
113 }
114 else
115 {
116 throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
117 }
118 }
119
120 }