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.PortletContext;
21 import javax.portlet.PortletRequest;
22
23 import org.apache.portals.bridges.jsf.AbstractAttributeMap;
24
25 /***
26 * <p>{@link PortletRequest} attributes Map.</p>
27 * <p>
28 * See MyFaces project for servlet implementation.
29 * </p>
30 *
31 * @author <a href="dlestrat@apache.org">David Le Strat</a>
32 */
33 public class RequestMap extends AbstractAttributeMap
34 {
35 /*** Illegal argument exception message. */
36 final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
37 /*** The {@link PortletContext}. */
38 private final PortletRequest portletRequest;
39
40 /***
41 * @param request The request.
42 */
43 public RequestMap(Object request)
44 {
45 if (request instanceof PortletRequest)
46 {
47 this.portletRequest = (PortletRequest) request;
48 }
49 else
50 {
51 throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
52 }
53 }
54
55 /***
56 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttribute(java.lang.String)
57 */
58 public Object getAttribute(String key)
59 {
60 if (null != this.portletRequest)
61 {
62 return this.portletRequest.getAttribute(key);
63 }
64 else
65 {
66 throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
67 }
68 }
69
70 /***
71 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#setAttribute(java.lang.String, java.lang.Object)
72 */
73 public void setAttribute(String key, Object value)
74 {
75 if (null != this.portletRequest)
76 {
77 this.portletRequest.setAttribute(key, value);
78 }
79 }
80
81 /***
82 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#removeAttribute(java.lang.String)
83 */
84 public void removeAttribute(String key)
85 {
86 if (null != this.portletRequest)
87 {
88 this.portletRequest.removeAttribute(key);
89 }
90 }
91
92 /***
93 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttributeNames()
94 */
95 public Enumeration getAttributeNames()
96 {
97 if (null != this.portletRequest)
98 {
99 return this.portletRequest.getAttributeNames();
100 }
101 else
102 {
103 throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
104 }
105 }
106 }