1 7 package org.exoplatform.services.wsrp.producer.impl.helpers; 8 9 import java.util.Enumeration ; 10 import java.util.HashMap ; 11 import java.util.Iterator ; 12 import java.util.Map ; 13 import java.util.Collections ; 14 import java.util.Set ; 15 16 import javax.servlet.ServletContext ; 17 import javax.servlet.http.HttpSession ; 18 import javax.servlet.http.HttpSessionContext ; 19 20 24 public class WSRPHttpSession implements HttpSession { 25 26 private String sessionID; 27 private Map attributsMap = new HashMap (); 28 private long creationTime; 29 private long lastAccessTime; 30 private int maxInactiveInterval = 900; 31 private boolean isNew = false; 32 private boolean invalidated = false; 33 34 public WSRPHttpSession(String sessionID, int maxInactiveInterval) { 35 creationTime = System.currentTimeMillis(); 36 this.sessionID = sessionID; 37 this.maxInactiveInterval = maxInactiveInterval; 38 isNew = true; 39 } 40 41 public long getCreationTime() { 42 if(invalidated) 43 throw new IllegalStateException (); 44 return creationTime; 45 } 46 47 public String getId() { 48 if(invalidated) 49 throw new IllegalStateException (); 50 return sessionID; 51 } 52 53 public long getLastAccessedTime() { 54 if(invalidated) 55 throw new IllegalStateException (); 56 return lastAccessTime; 57 } 58 59 public void setLastAccessTime(long lastAccessTime){ 60 this.lastAccessTime = lastAccessTime; 61 } 62 63 public ServletContext getServletContext() { 64 if(invalidated) 65 throw new IllegalStateException (); 66 return null; 67 } 68 69 public void setMaxInactiveInterval(int arg0) { 70 if(invalidated) 71 throw new IllegalStateException (); 72 maxInactiveInterval = arg0; 73 } 74 75 public int getMaxInactiveInterval() { 76 if(invalidated) 77 throw new IllegalStateException (); 78 return maxInactiveInterval; 79 } 80 81 public Object getAttribute(String arg0) { 82 if(invalidated) 83 throw new IllegalStateException (); 84 return attributsMap.get(arg0); 85 } 86 87 public Enumeration getAttributeNames() { 88 if(invalidated) 89 throw new IllegalStateException (); 90 return Collections.enumeration(attributsMap.keySet()); 91 } 92 93 public void setAttribute(String arg0, Object arg1) { 94 if(invalidated) 95 throw new IllegalStateException (); 96 attributsMap.put(arg0, arg1); 97 } 98 99 public void removeAttribute(String arg0) { 100 if(invalidated) 101 throw new IllegalStateException (); 102 attributsMap.remove(arg0); 103 } 104 105 public void invalidate() { 106 Set keys = attributsMap.entrySet(); 107 for (Iterator iter = keys.iterator(); iter.hasNext();) { 108 String key = (String ) iter.next(); 109 attributsMap.remove(key); 110 } 111 invalidated = true; 112 } 113 114 public boolean isInvalidated(){ 115 return invalidated; 116 } 117 118 public boolean isNew() { 119 if(invalidated) 120 throw new IllegalStateException (); 121 return false; 122 } 123 124 public void setNew(boolean isNew){ 125 this.isNew = isNew; 126 } 127 128 public void removeValue(String arg0) { 130 } 131 132 public void putValue(String arg0, Object arg1) { 133 } 134 135 public String [] getValueNames() { 136 return null; 137 } 138 139 public Object getValue(String arg0) { 140 return null; 141 } 142 143 public HttpSessionContext getSessionContext() { 144 return null; 145 } 146 } 147 | Popular Tags |