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

Generated on Mon Jan 14 17:29:49 2008 for OpenMobileIS by  doxygen 1.5.4