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-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     namesMap = 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     // TODO Auto-generated method stub
00097     return null;
00098   }
00099 
00100 
00101   public void setMaxInactiveInterval(int arg0) {
00102     MaxInactiveInterval = arg0;
00103   }
00104 
00105 
00106   public int getMaxInactiveInterval() { 
00107     return MaxInactiveInterval;
00108   }
00109 
00110 
00111   public HttpSessionContext getSessionContext() {
00112     // TODO Auto-generated method stub
00113     return null;
00114   }
00115 
00116   public Object getAttribute(String attributName) {
00117     if (attributName != null) {
00118       return attributMap.get(attributName);
00119     }
00120     return null;
00121   }
00122 
00123 
00124   //Deprecated. As of Version 2.2, this method is replaced by getAttribute(java.lang.String).
00125   public Object getValue(String name) {
00126     if (name != null) {
00127       return namesMap.get(name);
00128     }
00129     return null;
00130   }
00131 
00132 
00133   public Enumeration getAttributeNames() {
00134     return namesMap.keys();
00135   }
00136 
00137   //Deprecated. As of Version 2.2, this method is replaced by getAttributeNames()
00138   public String[] getValueNames() {
00139    
00140    Enumeration enum = namesMap.keys();
00141    String[] names = new String[10];
00142    int i = 0;
00143    while(enum.hasMoreElements()){
00144       names[i] = enum.toString();
00145       enum.nextElement();
00146       i++;
00147     }
00148     return names;    
00149   }
00150 
00151 
00152   public void setAttribute(String attributName, Object attribut) {
00153     if ((attributName != null) && (attribut != null))  {
00154       attributMap.put(attributName, attribut);
00155     }
00156   }
00157 
00158   //Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
00159   public void putValue(String name, Object obj) {
00160     if ((name != null) && (obj != null))  {
00161       namesMap.put(name, obj);
00162     }
00163   }
00164 
00165 
00166   public void removeAttribute(String attributName) {
00167     if (attributName != null)  {
00168       attributMap.remove(attributName);
00169     }
00170   }
00171 
00172   //Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
00173   public void removeValue(String name) {
00174     if (name != null)  {
00175       namesMap.remove(name);
00176     }
00177   }
00182   public void clearAttribute()  {
00183     
00184   }
00185 
00186 
00187   public void invalidate() {
00188     SessionContextManager.getManager().invalidateSession(sessionId);
00189   }
00190   
00191   public void SetIsNew(boolean bool){
00192     isNew = bool;
00193   }
00194   
00195   public boolean isNew() {
00196     return isNew;
00197   }
00198 
00199   public UserTerminal getTerminal() {
00200     return terminal;
00201   }
00202 
00203   public void setTerminal(UserTerminal terminal) {
00204     this.terminal = terminal;
00205   }
00206 
00207   public String getUserLocale() {
00208     return userLocale;
00209   }
00210 
00211   public void setUserLocale(String userLocal) {
00212     this.userLocale = userLocal;
00213   }
00214 
00215 }

Generated on Mon Jul 10 10:29:32 2006 for OpenMobileIS by  doxygen 1.4.4