Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

SessionContext.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
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     // TODO Auto-generated method stub
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     // TODO Auto-generated method stub
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   //Deprecated. As of Version 2.2, this method is replaced by getAttribute(java.lang.String).
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   //Deprecated. As of Version 2.2, this method is replaced by getAttributeNames()
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   //Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
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   //Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
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 }

Generated on Thu Oct 6 10:06:33 2005 for OpenMobileIS by  doxygen 1.4.3