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