KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > context > servlet > SessionMap


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.myfaces.context.servlet;
17
18 import org.apache.myfaces.util.NullEnumeration;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpSession JavaDoc;
22 import java.util.Enumeration JavaDoc;
23
24 /**
25  * HttpSession attibutes as Map.
26  *
27  * @author Anton Koinov (latest modification by $Author: matze $)
28  * @version $Revision: 1.13 $ $Date: 2004/10/13 11:51:00 $
29  * $Log: SessionMap.java,v $
30  * Revision 1.13 2004/10/13 11:51:00 matze
31  * renamed packages to org.apache
32  *
33  * Revision 1.12 2004/07/01 22:05:04 mwessendorf
34  * ASF switch
35  *
36  * Revision 1.11 2004/04/16 15:35:59 manolito
37  * Log
38  *
39  */

40 public class SessionMap extends AbstractAttributeMap
41 {
42     private final HttpServletRequest JavaDoc _httpRequest;
43
44     SessionMap(HttpServletRequest JavaDoc httpRequest)
45     {
46         _httpRequest = httpRequest;
47     }
48
49     protected Object JavaDoc getAttribute(String JavaDoc key)
50     {
51         HttpSession JavaDoc httpSession = getSession();
52         return (httpSession == null)
53             ? null : httpSession.getAttribute(key.toString());
54     }
55
56     protected void setAttribute(String JavaDoc key, Object JavaDoc value)
57     {
58         _httpRequest.getSession(true).setAttribute(key, value);
59     }
60
61     protected void removeAttribute(String JavaDoc key)
62     {
63         HttpSession JavaDoc httpSession = getSession();
64         if (httpSession != null)
65         {
66             httpSession.removeAttribute(key);
67         }
68     }
69
70     protected Enumeration getAttributeNames()
71     {
72         HttpSession JavaDoc httpSession = getSession();
73         return (httpSession == null)
74             ? NullEnumeration.instance()
75             : httpSession.getAttributeNames();
76     }
77     
78     private HttpSession JavaDoc getSession()
79     {
80         return _httpRequest.getSession(false);
81     }
82 }
Popular Tags