1 16 package org.apache.cocoon.environment.mock; 17 18 import java.util.Enumeration ; 19 import java.util.Hashtable ; 20 21 import junit.framework.AssertionFailedError; 22 23 import org.apache.cocoon.environment.Session; 24 25 public class MockSession implements Session { 26 27 private long creationtime = System.currentTimeMillis(); 28 private String id = "MockSession"; 29 private long lastaccessedtime = System.currentTimeMillis(); 30 private int maxinactiveinterval = -1; 31 private Hashtable attributes = new Hashtable (); 32 private boolean valid = true; 33 34 public long getCreationTime() { 35 checkValid(); 36 return creationtime; 37 } 38 39 public void setId(String id) { 40 this.id = id; 41 } 42 43 public String getId() { 44 checkValid(); 45 return id; 46 } 47 48 public long getLastAccessedTime() { 49 checkValid(); 50 return lastaccessedtime; 51 } 52 53 public void setMaxInactiveInterval(int interval) { 54 checkValid(); 55 this.maxinactiveinterval = interval; 56 } 57 58 public int getMaxInactiveInterval() { 59 checkValid(); 60 return maxinactiveinterval; 61 } 62 63 public Object getAttribute(String name) { 64 checkValid(); 65 return attributes.get(name); 66 } 67 68 public Enumeration getAttributeNames() { 69 checkValid(); 70 return attributes.keys(); 71 } 72 73 public void setAttribute(String name, Object value) { 74 checkValid(); 75 attributes.put(name, value); 76 } 77 78 public void removeAttribute(String name) { 79 checkValid(); 80 attributes.remove(name); 81 } 82 83 public void invalidate() { 84 checkValid(); 85 this.valid = false; 86 } 87 88 public boolean isNew() { 89 checkValid(); 90 return false; 91 } 92 93 private void checkValid() throws IllegalStateException { 94 if (!valid) 95 throw new AssertionFailedError("session has been invalidated!"); 96 } 97 98 public boolean isValid() { 99 return valid; 100 } 101 } 102 103 | Popular Tags |