SessionContext.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
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 import org.openmobileis.common.intl.IntlResourceManager;
00040 
00041 public class SessionContext implements HttpSession {
00042 
00043   private String sessionId;
00044   private Hashtable attributMap = null;
00045  // private Hashtable namesMap = null;
00046   private long lastAccessTime;
00047   private int MaxInactiveInterval;
00048   private boolean isNew = false;
00049   private long creationTime;
00050   private UserTerminal terminal;
00051   private String userId;
00052   private String userGroup;
00053   private String userLocale;
00054 
00055   
00056   public String getUserGroup() {
00057     return userGroup;
00058   }
00059 
00060   public void setUserGroup(String userGroup) {
00061     this.userGroup = userGroup;
00062   }
00063 
00064   public String getUserId() {
00065     return userId;
00066   }
00067 
00068   public void setUserId(String userId) {
00069     this.userId = userId;
00070   }
00071 
00072   public SessionContext(String id) {
00073     sessionId = id;
00074     attributMap = new Hashtable(10);
00075     this.creationTime = Calendar.getInstance().getTime().getTime();
00076     userLocale = IntlResourceManager.DEFAULT;
00077   }
00078 
00079   public long getCreationTime() {
00080     return creationTime;
00081   }
00082 
00083 
00084   public String getId() {
00085     return sessionId;
00086   }
00087 
00088 
00089   public long getLastAccessedTime() {
00090     return lastAccessTime;
00091   }
00092 
00093 
00094   public ServletContext getServletContext() {
00095     // TODO Auto-generated method stub
00096     return null;
00097   }
00098 
00099 
00100   public void setMaxInactiveInterval(int arg0) {
00101     MaxInactiveInterval = arg0;
00102   }
00103 
00104 
00105   public int getMaxInactiveInterval() { 
00106     return MaxInactiveInterval;
00107   }
00108 
00109 
00110   public HttpSessionContext getSessionContext() {
00111     // TODO Auto-generated method stub
00112     return null;
00113   }
00114 
00115   public Object getAttribute(String attributName) {
00116     if (attributName != null) {
00117       return attributMap.get(attributName);
00118     }
00119     return null;
00120   }
00121 
00122 
00123   //Deprecated. As of Version 2.2, this method is replaced by getAttribute(java.lang.String).
00124   public Object getValue(String name) {
00125     if (name != null) {
00126       return attributMap.get(name);
00127     }
00128     return null;
00129   }
00130 
00131 
00132   public Enumeration getAttributeNames() {
00133     return attributMap.keys();
00134   }
00135 
00136   //Deprecated. As of Version 2.2, this method is replaced by getAttributeNames()
00137   public String[] getValueNames() {
00138    
00139    Enumeration enums = attributMap.keys();
00140    String[] names = new String[10];
00141    int i = 0;
00142    while(enums.hasMoreElements()){
00143       names[i] = enums.toString();
00144       enums.nextElement();
00145       i++;
00146     }
00147     return names;    
00148   }
00149 
00150 
00151   public void setAttribute(String attributName, Object attribut) {
00152     if ((attributName != null) && (attribut != null))  {
00153       attributMap.put(attributName, attribut);
00154     }
00155   }
00156 
00157   //Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
00158   public void putValue(String name, Object obj) {
00159     if ((name != null) && (obj != null))  {
00160         attributMap.put(name, obj);
00161     }
00162   }
00163 
00164 
00165   public void removeAttribute(String attributName) {
00166     if (attributName != null)  {
00167       attributMap.remove(attributName);
00168     }
00169   }
00170 
00171   //Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
00172   public void removeValue(String name) {
00173     if (name != null)  {
00174         attributMap.remove(name);
00175     }
00176   }
00181   public void clearAttribute()  {
00182     
00183   }
00184 
00185 
00186   public void invalidate() {
00187     SessionContextManager.getManager().invalidateSession(sessionId);
00188   }
00189   
00190   public void SetIsNew(boolean bool){
00191     isNew = bool;
00192   }
00193   
00194   public boolean isNew() {
00195     return isNew;
00196   }
00197 
00198   public UserTerminal getTerminal() {
00199     return terminal;
00200   }
00201 
00202   public void setTerminal(UserTerminal terminal) {
00203     this.terminal = terminal;
00204   }
00205 
00206   public String getUserLocale() {
00207     return userLocale;
00208   }
00209 
00210   public void setUserLocale(String userLocal) {
00211     this.userLocale = userLocal;
00212   }
00213 
00214 }

Generated on Mon Dec 4 11:03:30 2006 for OpenMobileIS by  doxygen 1.5.1-p1