View Javadoc

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.portals.bridges.jsf;
17  
18  import java.util.Enumeration;
19  
20  import javax.portlet.PortletContext;
21  import javax.portlet.PortletRequest;
22  
23  import org.apache.portals.bridges.jsf.AbstractAttributeMap;
24  
25  /***
26   * <p>{@link PortletRequest} attributes Map.</p>
27   * <p>
28   * See MyFaces project for servlet implementation.
29   * </p>
30   * 
31   * @author <a href="dlestrat@apache.org">David Le Strat</a>
32   */
33  public class RequestMap extends AbstractAttributeMap
34  {
35  	/*** Illegal argument exception message. */
36  	final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
37  	/*** The {@link PortletContext}. */
38  	private final PortletRequest portletRequest;
39  
40      /***
41       * @param request The request.
42       */
43      public RequestMap(Object request)
44      {
45          if (request instanceof PortletRequest)
46          {
47          	this.portletRequest = (PortletRequest) request;
48          }
49          else
50          {
51          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
52          }
53      }
54  
55      /***
56       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttribute(java.lang.String)
57       */
58      public Object getAttribute(String key)
59      {
60          if (null != this.portletRequest)
61          {
62          	return this.portletRequest.getAttribute(key);
63          }
64          else
65          {
66          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
67          }
68      }
69  
70      /***
71       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#setAttribute(java.lang.String, java.lang.Object)
72       */
73      public void setAttribute(String key, Object value)
74      {
75      	if (null != this.portletRequest)
76          {
77      		this.portletRequest.setAttribute(key, value);
78          }
79      }
80  
81      /***
82       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#removeAttribute(java.lang.String)
83       */
84      public void removeAttribute(String key)
85      {
86      	if (null != this.portletRequest)
87          {
88      		this.portletRequest.removeAttribute(key);
89          }
90      }
91  
92      /***
93       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttributeNames()
94       */
95      public Enumeration getAttributeNames()
96      {
97      	if (null != this.portletRequest)
98          {
99      		return this.portletRequest.getAttributeNames();
100         }
101     	else
102         {
103         	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
104         }
105     }
106 }