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