View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.portals.bridges.jsf;
18  
19  import java.util.Enumeration;
20  
21  import javax.portlet.PortletContext;
22  import javax.portlet.PortletRequest;
23  
24  import org.apache.portals.bridges.jsf.AbstractAttributeMap;
25  
26  /***
27   * <p>{@link PortletRequest} attributes Map.</p>
28   * <p>
29   * See MyFaces project for servlet implementation.
30   * </p>
31   * 
32   * @author <a href="dlestrat@apache.org">David Le Strat</a>
33   */
34  public class RequestMap extends AbstractAttributeMap
35  {
36  	/*** Illegal argument exception message. */
37  	final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
38  	/*** The {@link PortletContext}. */
39  	private final PortletRequest portletRequest;
40  
41      /***
42       * @param request The request.
43       */
44      public RequestMap(Object request)
45      {
46          if (request instanceof PortletRequest)
47          {
48          	this.portletRequest = (PortletRequest) request;
49          }
50          else
51          {
52          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
53          }
54      }
55  
56      /***
57       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttribute(java.lang.String)
58       */
59      public Object getAttribute(String key)
60      {
61          if (null != this.portletRequest)
62          {
63          	return this.portletRequest.getAttribute(key);
64          }
65          else
66          {
67          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
68          }
69      }
70  
71      /***
72       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#setAttribute(java.lang.String, java.lang.Object)
73       */
74      public void setAttribute(String key, Object value)
75      {
76      	if (null != this.portletRequest)
77          {
78      		this.portletRequest.setAttribute(key, value);
79          }
80      }
81  
82      /***
83       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#removeAttribute(java.lang.String)
84       */
85      public void removeAttribute(String key)
86      {
87      	if (null != this.portletRequest)
88          {
89      		this.portletRequest.removeAttribute(key);
90          }
91      }
92  
93      /***
94       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttributeNames()
95       */
96      public Enumeration getAttributeNames()
97      {
98      	if (null != this.portletRequest)
99          {
100     		return this.portletRequest.getAttributeNames();
101         }
102     	else
103         {
104         	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
105         }
106     }
107 }