00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 package org.openmobileis.common.context;
00030
00031 import java.util.Calendar;
00032 import java.util.Enumeration;
00033 import java.util.Hashtable;
00034
00035 import javax.servlet.ServletContext;
00036 import javax.servlet.http.HttpSession;
00037 import javax.servlet.http.HttpSessionContext;
00038
00039 public class SessionContext implements HttpSession {
00040
00041 private String sessionId;
00042 private Hashtable attributMap = null;
00043 private Hashtable namesMap = null;
00044 private long lastAccessTime;
00045 private int MaxInactiveInterval;
00046 private boolean isNew = false;
00047 private long creationTime;
00048
00049
00050 public SessionContext(String id) {
00051 sessionId = id;
00052 attributMap = new Hashtable(10);
00053 namesMap = new Hashtable(10);
00054 this.creationTime = Calendar.getInstance().getTime().getTime();
00055 }
00056
00057 public long getCreationTime() {
00058 return creationTime;
00059 }
00060
00061
00062 public String getId() {
00063 return sessionId;
00064 }
00065
00066
00067 public long getLastAccessedTime() {
00068 return lastAccessTime;
00069 }
00070
00071
00072 public ServletContext getServletContext() {
00073
00074 return null;
00075 }
00076
00077
00078 public void setMaxInactiveInterval(int arg0) {
00079 MaxInactiveInterval = arg0;
00080 }
00081
00082
00083 public int getMaxInactiveInterval() {
00084 return MaxInactiveInterval;
00085 }
00086
00087
00088 public HttpSessionContext getSessionContext() {
00089
00090 return null;
00091 }
00092
00093 public Object getAttribute(String attributName) {
00094 if (attributName != null) {
00095 return attributMap.get(attributName);
00096 }
00097 return null;
00098 }
00099
00100
00101
00102 public Object getValue(String name) {
00103 if (name != null) {
00104 return namesMap.get(name);
00105 }
00106 return null;
00107 }
00108
00109
00110 public Enumeration getAttributeNames() {
00111 return namesMap.keys();
00112 }
00113
00114
00115 public String[] getValueNames() {
00116
00117 Enumeration enum = namesMap.keys();
00118 String[] names = new String[10];
00119 int i = 0;
00120 while(enum.hasMoreElements()){
00121 names[i] = enum.toString();
00122 enum.nextElement();
00123 i++;
00124 }
00125 return names;
00126 }
00127
00128
00129 public void setAttribute(String attributName, Object attribut) {
00130 if ((attributName != null) && (attribut != null)) {
00131 attributMap.put(attributName, attribut);
00132 }
00133 }
00134
00135
00136 public void putValue(String name, Object obj) {
00137 if ((name != null) && (obj != null)) {
00138 namesMap.put(name, obj);
00139 }
00140 }
00141
00142
00143 public void removeAttribute(String attributName) {
00144 if (attributName != null) {
00145 attributMap.remove(attributName);
00146 }
00147 }
00148
00149
00150 public void removeValue(String name) {
00151 if (name != null) {
00152 namesMap.remove(name);
00153 }
00154 }
00155
00156
00157 public void invalidate() {
00158 SessionContextManager.getManager().invalidateSession(sessionId);
00159 }
00160
00161 public void SetIsNew(boolean bool){
00162 isNew = bool;
00163 }
00164
00165 public boolean isNew() {
00166 return isNew;
00167 }
00168
00169 }