This project has retired. For details please refer to its
Attic page.
PortletInitParamMap xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.portlet.context;
22
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Enumeration;
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32
33 import javax.portlet.PortletContext;
34
35 import org.apache.tiles.context.MapEntry;
36
37 /***
38 * <p>Private implementation of <code>Map</code> for portlet context
39 * init parameters.</p>
40 *
41 * @version $Rev: 789695 $ $Date: 2009-06-30 14:43:14 +0200 (mar, 30 giu 2009) $
42 */
43
44 final class PortletInitParamMap implements Map<String, String> {
45
46
47 /***
48 * Constructor.
49 *
50 * @param context The portlet context to use.
51 */
52 public PortletInitParamMap(PortletContext context) {
53 this.context = context;
54 }
55
56
57 /***
58 * The portlet context to use.
59 */
60 private PortletContext context = null;
61
62
63 /*** {@inheritDoc} */
64 public void clear() {
65 throw new UnsupportedOperationException();
66 }
67
68
69 /*** {@inheritDoc} */
70 public boolean containsKey(Object key) {
71 return (context.getInitParameter(key(key)) != null);
72 }
73
74
75 /*** {@inheritDoc} */
76 public boolean containsValue(Object value) {
77 Iterator<String> values = values().iterator();
78 while (values.hasNext()) {
79 if (value.equals(values.next())) {
80 return (true);
81 }
82 }
83 return (false);
84 }
85
86
87 /*** {@inheritDoc} */
88 public Set<Map.Entry<String, String>> entrySet() {
89 Set<Map.Entry<String, String>> set = new HashSet<Map.Entry<String, String>>();
90 Enumeration<String> keys = context.getInitParameterNames();
91 while (keys.hasMoreElements()) {
92 String key = keys.nextElement();
93 set.add(new MapEntry<String, String>(key, context
94 .getInitParameter(key), false));
95 }
96 return (set);
97 }
98
99
100 /*** {@inheritDoc} */
101 public boolean equals(Object o) {
102 PortletContext otherContext = ((PortletInitParamMap) o).context;
103 boolean retValue = true;
104 synchronized (context) {
105 for (Enumeration<String> attribs = context.getInitParameterNames(); attribs
106 .hasMoreElements()
107 && retValue;) {
108 String parameterName = attribs.nextElement();
109 retValue = context.getInitParameter(parameterName).equals(
110 otherContext.getInitParameter(parameterName));
111 }
112 }
113
114 return retValue;
115 }
116
117
118 /*** {@inheritDoc} */
119 public String get(Object key) {
120 return (context.getInitParameter(key(key)));
121 }
122
123
124 /*** {@inheritDoc} */
125 public int hashCode() {
126 return (context.hashCode());
127 }
128
129
130 /*** {@inheritDoc} */
131 public boolean isEmpty() {
132 return (size() < 1);
133 }
134
135
136 /*** {@inheritDoc} */
137 public Set<String> keySet() {
138 Set<String> set = new HashSet<String>();
139 Enumeration<String> keys = context.getInitParameterNames();
140 while (keys.hasMoreElements()) {
141 set.add(keys.nextElement());
142 }
143 return (set);
144 }
145
146
147 /*** {@inheritDoc} */
148 public String put(String key, String value) {
149 throw new UnsupportedOperationException();
150 }
151
152
153 /*** {@inheritDoc} */
154 public void putAll(Map<? extends String, ? extends String> map) {
155 throw new UnsupportedOperationException();
156 }
157
158
159 /*** {@inheritDoc} */
160 public String remove(Object key) {
161 throw new UnsupportedOperationException();
162 }
163
164
165 /*** {@inheritDoc} */
166 public int size() {
167 int n = 0;
168 Enumeration<String> keys = context.getInitParameterNames();
169 while (keys.hasMoreElements()) {
170 keys.nextElement();
171 n++;
172 }
173 return (n);
174 }
175
176
177 /*** {@inheritDoc} */
178 public Collection<String> values() {
179 List<String> list = new ArrayList<String>();
180 Enumeration<String> keys = context.getInitParameterNames();
181 while (keys.hasMoreElements()) {
182 list.add(context.getInitParameter(keys.nextElement()));
183 }
184 return (list);
185 }
186
187
188 /***
189 * Returns the string representation of the key.
190 *
191 * @param key The key.
192 * @return The string representation of the key.
193 * @throws IllegalArgumentException If the key is <code>null</code>.
194 */
195 private String key(Object key) {
196 if (key == null) {
197 throw new IllegalArgumentException();
198 } else if (key instanceof String) {
199 return ((String) key);
200 } else {
201 return (key.toString());
202 }
203 }
204
205
206 }