KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > chain > web > servlet > MockHttpSession


1 /*
2  * Copyright 1999-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.commons.chain.web.servlet;
17
18
19 import org.apache.commons.chain.web.MockEnumeration;
20
21 import javax.servlet.ServletContext JavaDoc;
22 import javax.servlet.http.HttpSession JavaDoc;
23 import javax.servlet.http.HttpSessionContext JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import java.util.HashMap JavaDoc;
26
27
28
29 // Mock Object for HttpSession (Version 2.3)
30
public class MockHttpSession implements HttpSession JavaDoc {
31
32
33
34     public MockHttpSession() {
35         super();
36     }
37
38
39     public MockHttpSession(ServletContext JavaDoc servletContext) {
40         super();
41         setServletContext(servletContext);
42     }
43
44
45
46     protected HashMap JavaDoc attributes = new HashMap JavaDoc();
47     protected ServletContext JavaDoc servletContext = null;
48
49
50     // --------------------------------------------------------- Public Methods
51

52
53     public void setServletContext(ServletContext JavaDoc servletContext) {
54         this.servletContext = servletContext;
55     }
56
57
58     // ---------------------------------------------------- HttpSession Methods
59

60
61     public Object JavaDoc getAttribute(String JavaDoc name) {
62         return (attributes.get(name));
63     }
64
65
66     public Enumeration getAttributeNames() {
67         return (new MockEnumeration(attributes.keySet().iterator()));
68     }
69
70
71     public long getCreationTime() {
72         throw new UnsupportedOperationException JavaDoc();
73     }
74
75
76     public String JavaDoc getId() {
77         throw new UnsupportedOperationException JavaDoc();
78     }
79
80
81     public long getLastAccessedTime() {
82         throw new UnsupportedOperationException JavaDoc();
83     }
84
85
86     public int getMaxInactiveInterval() {
87         throw new UnsupportedOperationException JavaDoc();
88     }
89
90
91     public ServletContext JavaDoc getServletContext() {
92         return (this.servletContext);
93     }
94
95
96     public HttpSessionContext JavaDoc getSessionContext() {
97         throw new UnsupportedOperationException JavaDoc();
98     }
99
100
101     public Object JavaDoc getValue(String JavaDoc name) {
102         throw new UnsupportedOperationException JavaDoc();
103     }
104
105
106     public String JavaDoc[] getValueNames() {
107         throw new UnsupportedOperationException JavaDoc();
108     }
109
110
111     public void invalidate() {
112         throw new UnsupportedOperationException JavaDoc();
113     }
114
115
116     public boolean isNew() {
117         throw new UnsupportedOperationException JavaDoc();
118     }
119
120
121     public void putValue(String JavaDoc name, Object JavaDoc value) {
122         throw new UnsupportedOperationException JavaDoc();
123     }
124
125
126     public void removeAttribute(String JavaDoc name) {
127         attributes.remove(name);
128     }
129
130
131     public void removeValue(String JavaDoc name) {
132         throw new UnsupportedOperationException JavaDoc();
133     }
134
135
136     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
137         if (value == null) {
138             attributes.remove(name);
139         } else {
140             attributes.put(name, value);
141         }
142     }
143
144
145     public void setMaxInactiveInterval(int interval) {
146         throw new UnsupportedOperationException JavaDoc();
147     }
148
149
150 }
151
Popular Tags