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: 581978 $ $Date: 2007-10-04 19:59:41 +0200 (gio, 04 ott 2007) $
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 @SuppressWarnings("unchecked")
89 public Set<Map.Entry<String, String>> entrySet() {
90 Set<Map.Entry<String, String>> set = new HashSet<Map.Entry<String, String>>();
91 Enumeration<String> keys = context.getInitParameterNames();
92 while (keys.hasMoreElements()) {
93 String key = keys.nextElement();
94 set.add(new MapEntry<String, String>(key, context
95 .getInitParameter(key), false));
96 }
97 return (set);
98 }
99
100
101 /*** {@inheritDoc} */
102 @SuppressWarnings("unchecked")
103 public boolean equals(Object o) {
104 PortletContext otherContext = ((PortletInitParamMap) o).context;
105 boolean retValue = true;
106 synchronized (context) {
107 for (Enumeration<String> attribs = context.getInitParameterNames(); attribs
108 .hasMoreElements()
109 && retValue;) {
110 String parameterName = attribs.nextElement();
111 retValue = context.getInitParameter(parameterName).equals(
112 otherContext.getInitParameter(parameterName));
113 }
114 }
115
116 return retValue;
117 }
118
119
120 /*** {@inheritDoc} */
121 public String get(Object key) {
122 return (context.getInitParameter(key(key)));
123 }
124
125
126 /*** {@inheritDoc} */
127 public int hashCode() {
128 return (context.hashCode());
129 }
130
131
132 /*** {@inheritDoc} */
133 public boolean isEmpty() {
134 return (size() < 1);
135 }
136
137
138 /*** {@inheritDoc} */
139 @SuppressWarnings("unchecked")
140 public Set<String> keySet() {
141 Set<String> set = new HashSet<String>();
142 Enumeration<String> keys = context.getInitParameterNames();
143 while (keys.hasMoreElements()) {
144 set.add(keys.nextElement());
145 }
146 return (set);
147 }
148
149
150 /*** {@inheritDoc} */
151 public String put(String key, String value) {
152 throw new UnsupportedOperationException();
153 }
154
155
156 /*** {@inheritDoc} */
157 public void putAll(Map<? extends String, ? extends String> map) {
158 throw new UnsupportedOperationException();
159 }
160
161
162 /*** {@inheritDoc} */
163 public String remove(Object key) {
164 throw new UnsupportedOperationException();
165 }
166
167
168 /*** {@inheritDoc} */
169 @SuppressWarnings("unchecked")
170 public int size() {
171 int n = 0;
172 Enumeration<String> keys = context.getInitParameterNames();
173 while (keys.hasMoreElements()) {
174 keys.nextElement();
175 n++;
176 }
177 return (n);
178 }
179
180
181 /*** {@inheritDoc} */
182 @SuppressWarnings("unchecked")
183 public Collection<String> values() {
184 List<String> list = new ArrayList<String>();
185 Enumeration<String> keys = context.getInitParameterNames();
186 while (keys.hasMoreElements()) {
187 list.add(context.getInitParameter(keys.nextElement()));
188 }
189 return (list);
190 }
191
192
193 /***
194 * Returns the string representation of the key.
195 *
196 * @param key The key.
197 * @return The string representation of the key.
198 * @throws IllegalArgumentException If the key is <code>null</code>.
199 */
200 private String key(Object key) {
201 if (key == null) {
202 throw new IllegalArgumentException();
203 } else if (key instanceof String) {
204 return ((String) key);
205 } else {
206 return (key.toString());
207 }
208 }
209
210
211 }