KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > web > ServletWebSession


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.web;
16
17 import java.util.List JavaDoc;
18
19 import javax.servlet.http.HttpSession JavaDoc;
20
21 import org.apache.hivemind.util.Defense;
22 import org.apache.tapestry.describe.DescriptionReceiver;
23
24 /**
25  * Adapts {@link javax.servlet.http.HttpSession}  as
26  * {@link org.apache.tapestry.web.WebSession}.
27  *
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31 public class ServletWebSession implements WebSession
32 {
33     private final HttpSession JavaDoc _httpSession;
34
35     public ServletWebSession(HttpSession JavaDoc session)
36     {
37         Defense.notNull(session, "session");
38
39         _httpSession = session;
40     }
41
42     public void describeTo(DescriptionReceiver receiver)
43     {
44         receiver.describeAlternate(_httpSession);
45     }
46     
47     public List JavaDoc getAttributeNames()
48     {
49         return WebUtils.toSortedList(_httpSession.getAttributeNames());
50     }
51
52     public Object JavaDoc getAttribute(String JavaDoc name)
53     {
54         return _httpSession.getAttribute(name);
55     }
56
57     public void setAttribute(String JavaDoc name, Object JavaDoc attribute)
58     {
59         if (attribute == null)
60             _httpSession.removeAttribute(name);
61         else
62             _httpSession.setAttribute(name, attribute);
63     }
64
65     public String JavaDoc getId()
66     {
67         return _httpSession.getId();
68     }
69
70     public boolean isNew()
71     {
72         return _httpSession.isNew();
73     }
74 }
Popular Tags