KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > http > MockHttpSession


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package javax.servlet.http;
5
6 import java.util.Enumeration JavaDoc;
7 import java.util.Hashtable JavaDoc;
8
9 import javax.servlet.ServletContext JavaDoc;
10
11 public class MockHttpSession implements HttpSession JavaDoc {
12
13   private final Hashtable JavaDoc attributes = new Hashtable JavaDoc();
14   private long createMillis = 0;
15   private String JavaDoc id;
16   private long lastAccessTime;
17   private int maxIntactiveSeconds;
18   private boolean isNew;
19
20   public MockHttpSession(String JavaDoc id) {
21     this.id = id;
22   }
23
24   public Object JavaDoc getAttribute(String JavaDoc s) {
25     return attributes.get(s);
26   }
27
28   public Enumeration JavaDoc getAttributeNames() {
29     return attributes.keys();
30   }
31
32   public long getCreationTime() {
33     return createMillis;
34   }
35
36   public String JavaDoc getId() {
37     return id;
38   }
39
40   public long getLastAccessedTime() {
41     return lastAccessTime;
42   }
43
44   public int getMaxInactiveInterval() {
45     return maxIntactiveSeconds;
46   }
47
48   public ServletContext JavaDoc getServletContext() {
49     return null;
50   }
51
52   public HttpSessionContext JavaDoc getSessionContext() {
53     return null;
54   }
55
56   public Object JavaDoc getValue(String JavaDoc s) {
57     return getAttribute(s);
58   }
59
60   public String JavaDoc[] getValueNames() {
61     return (String JavaDoc[]) attributes.keySet().toArray(new String JavaDoc[attributes.size()]);
62   }
63
64   public void invalidate() {
65     // NOTE: implement
66
}
67
68   public boolean isNew() {
69     return isNew;
70   }
71
72   public void putValue(String JavaDoc s, Object JavaDoc obj) {
73     setAttribute(s, obj);
74   }
75
76   public void removeAttribute(String JavaDoc s) {
77     attributes.remove(s);
78   }
79
80   public void removeValue(String JavaDoc s) {
81     removeAttribute(s);
82   }
83
84   public void setAttribute(String JavaDoc s, Object JavaDoc obj) {
85     attributes.put(s, obj);
86   }
87
88   public void setMaxInactiveInterval(int i) {
89     this.maxIntactiveSeconds = i;
90   }
91
92 }
93
Popular Tags