View Javadoc

1   /*
2    * Copyright 2000-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 com.ibatis.struts.httpmap;
17  
18  import com.ibatis.struts.httpmap.BaseHttpMap;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpSession;
22  import java.util.Enumeration;
23  
24  /***
25   * Map to wrap session scope attributes.
26   * <p/>
27   * Date: Mar 11, 2004 10:35:42 PM
28   *
29   * @author Clinton Begin
30   */
31  public class SessionMap extends BaseHttpMap {
32  
33    private HttpSession session;
34  
35    public SessionMap(HttpServletRequest request) {
36      this.session = request.getSession();
37    }
38  
39    protected Enumeration getNames() {
40      return session.getAttributeNames();
41    }
42  
43    protected Object getValue(Object key) {
44      return session.getAttribute(String.valueOf(key));
45    }
46  
47    protected void putValue(Object key, Object value) {
48      session.setAttribute(String.valueOf(key), value);
49    }
50  
51    protected void removeValue(Object key) {
52      session.removeAttribute(String.valueOf(key));
53    }
54  
55  }