KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > test > mock > MockSession


1 // Copyright 2004, 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.test.mock;
16
17 import javax.servlet.ServletContext JavaDoc;
18 import javax.servlet.http.HttpSession JavaDoc;
19 import javax.servlet.http.HttpSessionBindingEvent JavaDoc;
20 import javax.servlet.http.HttpSessionBindingListener JavaDoc;
21 import javax.servlet.http.HttpSessionContext JavaDoc;
22
23 /**
24  * Mock implementation of {@link javax.servlet.http.HttpSession}.
25  *
26  *
27  * @author Howard Lewis Ship
28  * @since 4.0
29  */

30
31 public class MockSession extends AttributeHolder implements HttpSession JavaDoc
32 {
33     private MockContext _context;
34     private String JavaDoc _id;
35
36     public MockSession(MockContext context, String JavaDoc id)
37     {
38         _context = context;
39         _id = id;
40     }
41
42     public long getCreationTime()
43     {
44         return 0;
45     }
46
47     public String JavaDoc getId()
48     {
49         return _id;
50     }
51
52     public long getLastAccessedTime()
53     {
54         return 0;
55     }
56
57     public ServletContext JavaDoc getServletContext()
58     {
59         return _context;
60     }
61
62     public void setMaxInactiveInterval(int arg0)
63     {
64     }
65
66     public int getMaxInactiveInterval()
67     {
68         return 0;
69     }
70
71     public HttpSessionContext JavaDoc getSessionContext()
72     {
73         return null;
74     }
75
76     public Object JavaDoc getValue(String JavaDoc name)
77     {
78         return getAttribute(name);
79     }
80
81     public String JavaDoc[] getValueNames()
82     {
83         return getAttributeNamesArray();
84     }
85
86     public void putValue(String JavaDoc name, Object JavaDoc value)
87     {
88         setAttribute(name, value);
89     }
90
91     public void removeValue(String JavaDoc name)
92     {
93         removeAttribute(name);
94     }
95
96     public void invalidate()
97     {
98     }
99
100     public boolean isNew()
101     {
102         return false;
103     }
104
105     public void setAttribute(String JavaDoc name, Object JavaDoc value)
106     {
107         super.setAttribute(name, value);
108
109         if (value instanceof HttpSessionBindingListener JavaDoc)
110         {
111             HttpSessionBindingListener JavaDoc listener = (HttpSessionBindingListener JavaDoc) value;
112             HttpSessionBindingEvent JavaDoc event = new HttpSessionBindingEvent JavaDoc(this, name);
113
114             listener.valueBound(event);
115         }
116     }
117
118 }
119
Popular Tags