KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > context > portlet > RequestHeaderValuesMap


1 /*
2  * Copyright 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.myfaces.context.portlet;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Enumeration JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23 import javax.portlet.PortletRequest;
24
25 import org.apache.myfaces.context.servlet.AbstractAttributeMap;
26
27 /**
28  * PortletRequest header values (multi-value headers) as Map of String[].
29  *
30  * @author Stan Silvert (latest modification by $Author: matzew $)
31  * @version $Revision: 1.1 $ $Date: 2005/01/26 17:03:09 $
32  * $Log: RequestHeaderValuesMap.java,v $
33  * Revision 1.1 2005/01/26 17:03:09 matzew
34  * MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
35  *
36  */

37 public class RequestHeaderValuesMap extends AbstractAttributeMap
38 {
39     private final PortletRequest _portletRequest;
40     private final Map JavaDoc _valueCache = new HashMap JavaDoc();
41
42     RequestHeaderValuesMap(PortletRequest portletRequest)
43     {
44         _portletRequest = portletRequest;
45     }
46
47     protected Object JavaDoc getAttribute(String JavaDoc key)
48     {
49         Object JavaDoc ret = _valueCache.get(key);
50         if (ret == null)
51         {
52             _valueCache.put(key, ret = toArray(_portletRequest
53                 .getProperties(key)));
54         }
55
56         return ret;
57     }
58
59     protected void setAttribute(String JavaDoc key, Object JavaDoc value)
60     {
61         throw new UnsupportedOperationException JavaDoc(
62             "Cannot set PortletRequest Properties");
63     }
64
65     protected void removeAttribute(String JavaDoc key)
66     {
67         throw new UnsupportedOperationException JavaDoc(
68             "Cannot remove PortletRequest Properties");
69     }
70
71     protected Enumeration JavaDoc getAttributeNames()
72     {
73         return _portletRequest.getPropertyNames();
74     }
75
76     private String JavaDoc[] toArray(Enumeration JavaDoc e)
77     {
78         List JavaDoc ret = new ArrayList JavaDoc();
79
80         while (e.hasMoreElements())
81         {
82             ret.add(e.nextElement());
83         }
84
85         return (String JavaDoc[]) ret.toArray(new String JavaDoc[ret.size()]);
86     }
87 }
Popular Tags