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

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   private UserTerminal terminal;
00049   private String userId;
00050   private String userGroup;
00051 
00052   
00053   public String getUserGroup() {
00054     return userGroup;
00055   }
00056 
00057   public void setUserGroup(String userGroup) {
00058     this.userGroup = userGroup;
00059   }
00060 
00061   public String getUserId() {
00062     return userId;
00063   }
00064 
00065   public void setUserId(String userId) {
00066     this.userId = userId;
00067   }
00068 
00069   public SessionContext(String id) {
00070     sessionId = id;
00071     attributMap = new Hashtable(10);
00072     namesMap = new Hashtable(10);
00073     this.creationTime = Calendar.getInstance().getTime().getTime();
00074   }
00075 
00076   public long getCreationTime() {
00077     return creationTime;
00078   }
00079 
00080 
00081   public String getId() {
00082     return sessionId;
00083   }
00084 
00085 
00086   public long getLastAccessedTime() {
00087     return lastAccessTime;
00088   }
00089 
00090 
00091   public ServletContext getServletContext() {
00092     // TODO Auto-generated method stub
00093     return null;
00094   }
00095 
00096 
00097   public void setMaxInactiveInterval(int arg0) {
00098     MaxInactiveInterval = arg0;
00099   }
00100 
00101 
00102   public int getMaxInactiveInterval() { 
00103     return MaxInactiveInterval;
00104   }
00105 
00106 
00107   public HttpSessionContext getSessionContext() {
00108     // TODO Auto-generated method stub
00109     return null;
00110   }
00111 
00112   public Object getAttribute(String attributName) {
00113     if (attributName != null) {
00114       return attributMap.get(attributName);
00115     }
00116     return null;
00117   }
00118 
00119 
00120   //Deprecated. As of Version 2.2, this method is replaced by getAttribute(java.lang.String).
00121   public Object getValue(String name) {
00122     if (name != null) {
00123       return namesMap.get(name);
00124     }
00125     return null;
00126   }
00127 
00128 
00129   public Enumeration getAttributeNames() {
00130     return namesMap.keys();
00131   }
00132 
00133   //Deprecated. As of Version 2.2, this method is replaced by getAttributeNames()
00134   public String[] getValueNames() {
00135    
00136    Enumeration enum = namesMap.keys();
00137    String[] names = new String[10];
00138    int i = 0;
00139    while(enum.hasMoreElements()){
00140       names[i] = enum.toString();
00141       enum.nextElement();
00142       i++;
00143     }
00144     return names;    
00145   }
00146 
00147 
00148   public void setAttribute(String attributName, Object attribut) {
00149     if ((attributName != null) && (attribut != null))  {
00150       attributMap.put(attributName, attribut);
00151     }
00152   }
00153 
00154   //Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
00155   public void putValue(String name, Object obj) {
00156     if ((name != null) && (obj != null))  {
00157       namesMap.put(name, obj);
00158     }
00159   }
00160 
00161 
00162   public void removeAttribute(String attributName) {
00163     if (attributName != null)  {
00164       attributMap.remove(attributName);
00165     }
00166   }
00167 
00168   //Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
00169   public void removeValue(String name) {
00170     if (name != null)  {
00171       namesMap.remove(name);
00172     }
00173   }
00178   public void clearAttribute()  {
00179     
00180   }
00181 
00182 
00183   public void invalidate() {
00184     SessionContextManager.getManager().invalidateSession(sessionId);
00185   }
00186   
00187   public void SetIsNew(boolean bool){
00188     isNew = bool;
00189   }
00190   
00191   public boolean isNew() {
00192     return isNew;
00193   }
00194 
00195   public UserTerminal getTerminal() {
00196     return terminal;
00197   }
00198 
00199   public void setTerminal(UserTerminal terminal) {
00200     this.terminal = terminal;
00201   }
00202 
00203 }

Generated on Wed Dec 14 21:05:35 2005 for OpenMobileIS by  doxygen 1.4.4