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