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}init parameters as 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 InitParameterMap 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 InitParameterMap(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.getInitParameter(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 throw new UnsupportedOperationException("Cannot set PortletContext InitParameter");
79 }
80
81 /***
82 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#removeAttribute(java.lang.String)
83 */
84 public void removeAttribute(String key)
85 {
86 throw new UnsupportedOperationException("Cannot remove PortletContext InitParameter");
87 }
88
89 /***
90 * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttributeNames()
91 */
92 public Enumeration getAttributeNames()
93 {
94 if (null != this.portletContext)
95 {
96 return this.portletContext.getInitParameterNames();
97 }
98 else
99 {
100 throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
101 }
102 }
103 }