KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > chain > web > portlet > PortletParamValuesMap


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.chain.web.portlet;
17
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Set JavaDoc;
27 import javax.portlet.PortletRequest;
28
29
30 /**
31  * <p>Private implementation of <code>Map</code> for portlet parameter
32  * name-values[].</p>
33  *
34  * @author Craig R. McClanahan
35  * @version $Revision: 1.3 $ $Date: 2004/02/25 00:01:06 $
36  */

37
38 final class PortletParamValuesMap implements Map JavaDoc {
39
40
41     public PortletParamValuesMap(PortletRequest request) {
42         this.request = request;
43     }
44
45
46     private PortletRequest request = null;
47
48
49     public void clear() {
50         throw new UnsupportedOperationException JavaDoc();
51     }
52
53
54     public boolean containsKey(Object JavaDoc key) {
55         return (request.getParameter(key(key)) != null);
56     }
57
58
59     public boolean containsValue(Object JavaDoc value) {
60         Iterator JavaDoc values = values().iterator();
61         while (values.hasNext()) {
62             if (value.equals(values.next())) {
63                 return (true);
64             }
65         }
66         return (false);
67     }
68
69
70     public Set JavaDoc entrySet() {
71         Set JavaDoc set = new HashSet JavaDoc();
72         Enumeration JavaDoc keys = request.getParameterNames();
73         while (keys.hasMoreElements()) {
74             set.add(request.getParameterValues((String JavaDoc) keys.nextElement()));
75         }
76         return (set);
77     }
78
79
80     public boolean equals(Object JavaDoc o) {
81         return (request.equals(o));
82     }
83
84
85     public Object JavaDoc get(Object JavaDoc key) {
86         return (request.getParameterValues(key(key)));
87     }
88
89
90     public int hashCode() {
91         return (request.hashCode());
92     }
93
94
95     public boolean isEmpty() {
96         return (size() < 1);
97     }
98
99
100     public Set JavaDoc keySet() {
101         Set JavaDoc set = new HashSet JavaDoc();
102         Enumeration JavaDoc keys = request.getParameterNames();
103         while (keys.hasMoreElements()) {
104             set.add(keys.nextElement());
105         }
106         return (set);
107     }
108
109
110     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
111         throw new UnsupportedOperationException JavaDoc();
112     }
113
114
115     public void putAll(Map JavaDoc map) {
116         throw new UnsupportedOperationException JavaDoc();
117     }
118
119
120     public Object JavaDoc remove(Object JavaDoc key) {
121         throw new UnsupportedOperationException JavaDoc();
122     }
123
124
125     public int size() {
126         int n = 0;
127         Enumeration JavaDoc keys = request.getParameterNames();
128         while (keys.hasMoreElements()) {
129             keys.nextElement();
130             n++;
131         }
132         return (n);
133     }
134
135
136     public Collection JavaDoc values() {
137         List JavaDoc list = new ArrayList JavaDoc();
138         Enumeration JavaDoc keys = request.getParameterNames();
139         while (keys.hasMoreElements()) {
140             list.add(request.getParameterValues((String JavaDoc) keys.nextElement()));
141         }
142         return (list);
143     }
144
145
146     private String JavaDoc key(Object JavaDoc key) {
147         if (key == null) {
148             throw new IllegalArgumentException JavaDoc();
149         } else if (key instanceof String JavaDoc) {
150             return ((String JavaDoc) key);
151         } else {
152             return (key.toString());
153         }
154     }
155
156
157 }
158
Popular Tags