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.jetspeed.container.invoker;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletRequestWrapper;
24  
25  /***
26   * Local servlet request wrapper. The purpose of this wrapper is to hold 
27   * attribute information that is need for each request.  In a threaded environment, 
28   * each thread needs to have its own copy of this information so that there is 
29   * not a timing issue with the original request object.  
30   * Also, since the original request is no longer "holding" the attributes, 
31   * there is no reason to remove them in the finally block.  
32   * The LocalServletRequest object is automatically garbage collected at then 
33   * end of this method.
34   *
35   * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
36   * @author <a href="">David Gurney</a>
37   * @version $Id: $
38   */
39  public class LocalServletRequest extends HttpServletRequestWrapper
40  {
41      private Map attributeMap = new HashMap();
42  
43      private HttpServletRequest originalRequest = null;
44  
45      public LocalServletRequest(HttpServletRequest request)
46      {
47          super(request);
48          originalRequest = request;
49      }
50  
51      public Object getAttribute(String p_sKey)
52      {
53          Object a_oValue = attributeMap.get(p_sKey);
54          if (a_oValue == null)
55          {
56              a_oValue = originalRequest.getAttribute(p_sKey);
57          }
58  
59          return a_oValue;
60      }
61  
62      public void removeAttribute(String key)
63      {
64          Object value = attributeMap.remove(key);
65          if (value == null)
66          {
67              originalRequest.removeAttribute(key);
68          }
69      }
70  
71      public void setAttribute(String key, Object value)
72      {
73          attributeMap.put(key, value);
74      }
75  
76  }