KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > scoping > internal > ScopedSession


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  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.scoping.internal;
19
20 import javax.servlet.http.HttpSession JavaDoc;
21 import javax.servlet.http.HttpSessionContext JavaDoc;
22 import javax.servlet.ServletContext JavaDoc;
23 import java.io.Serializable JavaDoc;
24
25
26 /**
27  * A wrapper around HttpSession, associated with a given scope-key. All calls to setAttribute,
28  * getAttribute, removeAttribute, etc. are scoped to this object, while most other functionality
29  * delegates to the wrapped HttpSession.
30  */

31 public class ScopedSession
32         extends ScopedAttributeContainer
33         implements HttpSession JavaDoc, Serializable JavaDoc
34 {
35     private transient HttpSession JavaDoc _session;
36     private transient ServletContext JavaDoc _servletContext;
37
38     /**
39      * This constructor exists only for deserialization.
40      */

41     public ScopedSession()
42     {
43         super( null );
44     }
45
46     public ScopedSession( HttpSession JavaDoc session, ServletContext JavaDoc cxt, Object JavaDoc scopeKey )
47     {
48         super( scopeKey );
49         _session = session;
50         _servletContext = cxt;
51     }
52
53     public long getCreationTime()
54     {
55         return _session.getCreationTime();
56     }
57
58     public String JavaDoc getId()
59     {
60         return getScopedName( _session.getId() );
61     }
62
63     public long getLastAccessedTime()
64     {
65         return _session.getLastAccessedTime();
66     }
67
68     public ServletContext JavaDoc getServletContext()
69     {
70         return _servletContext;
71     }
72
73     public void setMaxInactiveInterval( int i )
74     {
75         _session.setMaxInactiveInterval( i );
76     }
77
78     public int getMaxInactiveInterval()
79     {
80         return _session.getMaxInactiveInterval();
81     }
82
83     public HttpSessionContext JavaDoc getSessionContext()
84     {
85         return _session.getSessionContext();
86     }
87
88     public Object JavaDoc getValue( String JavaDoc s )
89     {
90         return getAttribute( s );
91     }
92
93     public String JavaDoc[] getValueNames()
94     {
95         return getAttributeNamesArray();
96     }
97
98     public void putValue( String JavaDoc s, Object JavaDoc o )
99     {
100         setAttribute( s, o );
101     }
102
103     public void removeValue( String JavaDoc s )
104     {
105         removeAttribute( s );
106     }
107
108     public void invalidate()
109     {
110         removeAllAttributes();
111     }
112
113     public boolean isNew()
114     {
115         return _session.isNew();
116     }
117     
118     /**
119      * Since _session is transient, this method is called by {@link ScopedRequestImpl#getSession}
120      * to reinitialize it each time.
121      */

122     void setSession( HttpSession JavaDoc session, ServletContext JavaDoc cxt )
123     {
124         _session = session;
125         _servletContext = cxt;
126     }
127     
128     /**
129      * Returns the real (outer) HttpSession.
130      */

131     public HttpSession JavaDoc getOuterSession()
132     {
133         return _session;
134     }
135 }
136
Popular Tags