KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > mock > MockHttpSession


1 /**
2  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3  * Licensed under the Common Development and Distribution 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.sun.com/cddl/
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
12  * implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */

15
16 package com.sun.facelets.mock;
17
18 import java.util.Enumeration JavaDoc;
19 import java.util.Hashtable JavaDoc;
20
21 import javax.servlet.ServletContext JavaDoc;
22 import javax.servlet.http.HttpSession JavaDoc;
23 import javax.servlet.http.HttpSessionContext JavaDoc;
24
25 /**
26  *
27  * @author Jacob Hookom
28  * @version $Id: MockHttpSession.java,v 1.2 2005/07/19 00:49:02 jhook Exp $
29  */

30 public class MockHttpSession implements HttpSession JavaDoc {
31
32     private final Hashtable JavaDoc attributes = new Hashtable JavaDoc();
33     private final long creationTime;
34     private String JavaDoc id;
35     private long lastAccessedTime;
36     private final ServletContext JavaDoc servletContext;
37     private int maxInactiveInterval = 20;
38     
39     public MockHttpSession(ServletContext JavaDoc servletContext) {
40         this.servletContext = servletContext;
41         this.creationTime = System.currentTimeMillis();
42         this.id = "" + this.creationTime;
43         this.lastAccessedTime = this.creationTime;
44     }
45
46     public long getCreationTime() {
47         return this.creationTime;
48     }
49
50     public String JavaDoc getId() {
51         return this.id;
52     }
53
54     public long getLastAccessedTime() {
55         return this.lastAccessedTime;
56     }
57
58     public ServletContext JavaDoc getServletContext() {
59         return this.servletContext;
60     }
61
62     public void setMaxInactiveInterval(int interval) {
63         this.maxInactiveInterval = interval;
64     }
65
66     public int getMaxInactiveInterval() {
67         return this.maxInactiveInterval;
68     }
69
70     public HttpSessionContext JavaDoc getSessionContext() {
71         throw new UnsupportedOperationException JavaDoc();
72     }
73
74     public Object JavaDoc getAttribute(String JavaDoc name) {
75         return this.attributes.get(name);
76     }
77
78     public Object JavaDoc getValue(String JavaDoc name) {
79         throw new UnsupportedOperationException JavaDoc();
80     }
81
82     public Enumeration JavaDoc getAttributeNames() {
83         return this.attributes.keys();
84     }
85
86     public String JavaDoc[] getValueNames() {
87         throw new UnsupportedOperationException JavaDoc();
88     }
89
90     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
91         this.attributes.put(name, value);
92     }
93
94     public void putValue(String JavaDoc arg0, Object JavaDoc arg1) {
95         throw new UnsupportedOperationException JavaDoc();
96
97     }
98
99     public void removeAttribute(String JavaDoc name) {
100         this.attributes.remove(name);
101     }
102
103     public void removeValue(String JavaDoc arg0) {
104         throw new UnsupportedOperationException JavaDoc();
105     }
106
107     public void invalidate() {
108
109     }
110
111     public boolean isNew() {
112         return false;
113     }
114
115 }
116
Popular Tags