1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.context.portlet; |
20 | |
|
21 | |
import org.apache.myfaces.shared_impl.util.NullEnumeration; |
22 | |
import org.apache.myfaces.util.AbstractAttributeMap; |
23 | |
|
24 | |
import java.util.Enumeration; |
25 | |
import java.util.Map; |
26 | |
import javax.portlet.PortletRequest; |
27 | |
import javax.portlet.PortletSession; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class SessionMap extends AbstractAttributeMap<Object> |
36 | |
{ |
37 | |
private final PortletRequest _portletRequest; |
38 | |
|
39 | |
SessionMap(PortletRequest portletRequest) |
40 | 0 | { |
41 | 0 | _portletRequest = portletRequest; |
42 | 0 | } |
43 | |
|
44 | |
@Override |
45 | |
protected Object getAttribute(String key) |
46 | |
{ |
47 | 0 | PortletSession portletSession = getSession(); |
48 | 0 | return (portletSession == null) |
49 | |
? null : portletSession.getAttribute(key, PortletSession.PORTLET_SCOPE); |
50 | |
} |
51 | |
|
52 | |
@Override |
53 | |
protected void setAttribute(String key, Object value) |
54 | |
{ |
55 | 0 | _portletRequest.getPortletSession(true).setAttribute(key, value, PortletSession.PORTLET_SCOPE); |
56 | 0 | } |
57 | |
|
58 | |
@Override |
59 | |
protected void removeAttribute(String key) |
60 | |
{ |
61 | 0 | PortletSession portletSession = getSession(); |
62 | 0 | if (portletSession != null) |
63 | |
{ |
64 | 0 | portletSession.removeAttribute(key, PortletSession.PORTLET_SCOPE); |
65 | |
} |
66 | 0 | } |
67 | |
|
68 | |
@Override |
69 | |
@SuppressWarnings("unchecked") |
70 | |
protected Enumeration<String> getAttributeNames() |
71 | |
{ |
72 | 0 | PortletSession portletSession = getSession(); |
73 | 0 | return (portletSession == null) |
74 | |
? NullEnumeration.instance() |
75 | |
: portletSession.getAttributeNames(PortletSession.PORTLET_SCOPE); |
76 | |
} |
77 | |
|
78 | |
private PortletSession getSession() |
79 | |
{ |
80 | 0 | return _portletRequest.getPortletSession(false); |
81 | |
} |
82 | |
|
83 | |
@Override |
84 | |
public void putAll(Map t) |
85 | |
{ |
86 | 0 | throw new UnsupportedOperationException(); |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
@Override |
95 | |
public void clear() |
96 | |
{ |
97 | 0 | PortletSession session = getSession(); |
98 | 0 | if (session == null) return; |
99 | 0 | for (Enumeration attributeNames = session.getAttributeNames(PortletSession.PORTLET_SCOPE); |
100 | 0 | attributeNames.hasMoreElements(); ) { |
101 | 0 | String attributeName = (String)attributeNames.nextElement(); |
102 | 0 | session.removeAttribute(attributeName); |
103 | 0 | } |
104 | 0 | } |
105 | |
} |