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