KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > server > SessionEdit


1 package org.enhydra.server;
2
3
4 import org.enhydra.util.ConfigFileInterface;
5
6 import com.lutris.util.Config;
7 import com.lutris.util.ConfigException;
8 import com.lutris.util.KeywordValueException;
9
10 /**
11  * <p>Title: </p>
12  * <p>Description: </p>
13  * <p>Copyright: Copyright (c) 2002</p>
14  * <p>Company: www.together.at</p>
15  * @author tufeX tufex@uns.ns.ac.yu
16  * @version 1.1
17  */

18
19 public class SessionEdit {
20
21   private String JavaDoc sessionLifetimeMax;
22   private String JavaDoc sessionIdleTimeMax;
23   private String JavaDoc sessionNoUserIdleTimeMax;
24   private String JavaDoc idleScanInterval;
25   private String JavaDoc randomizerIntervals[];
26   private String JavaDoc memoryPersistence;
27   private String JavaDoc mode;
28   private String JavaDoc maxSessions;
29   private String JavaDoc pageThreshold;
30   private String JavaDoc pageTimeThreshold;
31   private String JavaDoc pageWait;
32   private String JavaDoc saveOnRestart;
33   private String JavaDoc pageDir;
34   private String JavaDoc databaseName;
35   private String JavaDoc dBTableName;
36   private String JavaDoc sessionHomeClass;
37   private String JavaDoc sessionUserTableClass;
38
39   private String JavaDoc sessionEncodeUrlState;
40   private String JavaDoc sessionEncodeFirstUrl;
41   //Default values
42

43   private String JavaDoc sessionLifetimeMaxDefault = "0";
44   private String JavaDoc sessionIdleTimeMaxDefault = "30";
45   private String JavaDoc sessionNoUserIdleTimeMaxDefault = "30";
46   private String JavaDoc idleScanIntervalDefault = "30";
47   private String JavaDoc randomizerIntervalsDefault[] = {"301","1001","5003"};
48   private String JavaDoc memoryPersistenceDefault = "false";
49   private String JavaDoc modeDefault = "BASIC";
50   private String JavaDoc maxSessionsDefault = "-1";
51   private String JavaDoc pageThresholdDefault = "-1";
52   private String JavaDoc pageTimeThresholdDefault = "-1";
53   private String JavaDoc pageWaitDefault = "60000";
54   private String JavaDoc saveOnRestartDefault = "false";
55   private String JavaDoc pageDirDefault = "";
56   private String JavaDoc databaseNameDefault = "";
57   private String JavaDoc dBTableNameDefault = "PersistentSession";
58   private String JavaDoc sessionHomeClassDefault = "";
59   private String JavaDoc sessionUserTableClassDefault = "";
60
61   private String JavaDoc sessionEncodeUrlStateDefault = "Auto";
62   private String JavaDoc sessionEncodeFirstUrlDefault = "false";
63   
64
65   Config config;
66
67   private SessionEdit() {
68   }
69   /**
70    * One and only constructor, fill SessionManager parameters from application
71    * config file (or set default value if parameter doesn't exist).
72    * @param appConfig application Config
73    * @throws ConfigException
74    * @throws KeywordValueException
75    */

76   public SessionEdit(Config appConfig) throws ConfigException, KeywordValueException {
77     config = appConfig;
78     String JavaDoc temp;
79       if (config == null) throw new ConfigException("Exception in SessionEdit(), config == null");
80       //SessionManager.*
81
if(config.containsKey("SessionManager.Lifetime")){ // backwards compatibility
82
setSessionLifetimeMax(config.getString("SessionManager.Lifetime")); //set new parameter
83
config.remove("SessionManager.Lifetime"); //remove old parameter
84
}else sessionLifetimeMax = config.getString("SessionManager.SessionLifetimeMax",sessionLifetimeMaxDefault);
85
86       if(config.containsKey("SessionManager.MaxIdleTime")){ // backwards compatibility
87
setSessionIdleTimeMax(config.getString("SessionManager.MaxIdleTime")); //set new parameter
88
config.remove("SessionManager.MaxIdleTime"); //remove old parameter
89
}else sessionIdleTimeMax = config.getString("SessionManager.SessionIdleTimeMax",sessionIdleTimeMaxDefault);
90
91       if(config.containsKey("SessionManager.MaxNoUserIdleTime")){ // backwards compatibility
92
setSessionNoUserIdleTimeMax(config.getString("SessionManager.MaxNoUserIdleTime")); //set new parameter
93
config.remove("SessionManager.MaxNoUserIdleTime"); //remove old parameter
94
}else sessionNoUserIdleTimeMax = config.getString("SessionManager.SessionNoUserIdleTimeMax",sessionNoUserIdleTimeMaxDefault);
95
96       idleScanInterval = config.getString("SessionManager.IdleScanInterval",idleScanIntervalDefault);
97
98       randomizerIntervals = config.getStrings("SessionManager.RandomizerIntervals",randomizerIntervalsDefault);
99       memoryPersistence = config.getString("SessionManager.MemoryPersistence",memoryPersistenceDefault);
100
101       if(config.containsKey("SessionManager.EncodeUrlState")){ // backwards compatibility
102
setSessionEncodeUrlState(config.getString("SessionManager.EncodeUrlState")); //set new parameter
103
config.remove("SessionManager.EncodeUrlState"); //remove old parameter
104
}else sessionEncodeUrlState = config.getString("SessionManager.SessionEncodeUrlState",sessionEncodeUrlStateDefault);
105             
106       sessionEncodeFirstUrl = config.getString("SessionManager.SessionEncodeFirstUrl",sessionEncodeFirstUrlDefault);
107             
108       //SessionManager.SessionHome.*
109
mode = config.getString("SessionManager.SessionHome.Mode",modeDefault);
110       maxSessions = config.getString("SessionManager.SessionHome.MaxSessions",maxSessionsDefault);
111       pageThreshold = config.getString("SessionManager.SessionHome.PageThreshold",pageThresholdDefault);
112       pageTimeThreshold = config.getString("SessionManager.SessionHome.PageTimeThreshold",pageTimeThreshold);
113       pageWait = config.getString("SessionManager.SessionHome.PageWait",pageWaitDefault);
114       saveOnRestart = config.getString("SessionManager.SessionHome.SaveOnRestart",saveOnRestartDefault);
115       pageDir = config.getString("SessionManager.SessionHome.PageDir",pageDirDefault);
116       databaseName = config.getString("SessionManager.SessionHome.DatabaseName",databaseNameDefault);
117       dBTableName = config.getString("SessionManager.SessionHome.DBTableName",dBTableNameDefault);
118
119
120       sessionHomeClass = config.getString("SessionManager.SessionHome.Class",sessionHomeClassDefault);
121       sessionUserTableClass = config.getString("SessionManager.SessionUserTable.Class",sessionUserTableClassDefault);
122
123   }
124
125
126   public String JavaDoc getSessionLifetimeMax() {
127     return sessionLifetimeMax;
128   }
129   public void setSessionLifetimeMax(String JavaDoc lifetimeMax) throws KeywordValueException{
130     this.sessionLifetimeMax = lifetimeMax;
131     config.set("SessionManager.SessionLifetimeMax",lifetimeMax);
132   }
133
134   public String JavaDoc getSessionIdleTimeMax() {
135     return sessionIdleTimeMax;
136   }
137
138   public void setSessionIdleTimeMax(String JavaDoc idleTimeMax) throws KeywordValueException{
139     this.sessionIdleTimeMax = idleTimeMax;
140     config.set("SessionManager.SessionIdleTimeMax",idleTimeMax);
141   }
142
143   public String JavaDoc getSessionNoUserIdleTimeMax() {
144     return sessionNoUserIdleTimeMax;
145   }
146
147   public void setSessionNoUserIdleTimeMax(String JavaDoc noUserIdleTimeMax) throws KeywordValueException{
148     this.sessionNoUserIdleTimeMax = noUserIdleTimeMax;
149     config.set("SessionManager.SessionNoUserIdleTimeMax",noUserIdleTimeMax);
150   }
151
152   public String JavaDoc getIdleScanInterval() {
153     return idleScanInterval;
154   }
155
156   public void setIdleScanInterval(String JavaDoc idleScanInterval) throws KeywordValueException{
157     this.idleScanInterval = idleScanInterval;
158     config.set("SessionManager.IdleScanInterval",idleScanInterval);
159   }
160
161   public String JavaDoc[] getRandomizerIntervals() {
162     return randomizerIntervals;
163   }
164
165   public void setRandomizerIntervals(String JavaDoc[] randomizerIntervals) throws KeywordValueException{
166     this.randomizerIntervals = randomizerIntervals;
167     config.set("SessionManager.RandomizerIntervals",randomizerIntervals);
168   }
169
170   public String JavaDoc getMemoryPersistence() {
171     return memoryPersistence;
172   }
173
174   public void setMemoryPersistence(String JavaDoc memoryPersistence) throws KeywordValueException{
175     this.memoryPersistence = memoryPersistence;
176     config.set("SessionManager.MemoryPersistence",memoryPersistence);
177   }
178
179   public String JavaDoc getSessionEncodeUrlState(){
180     return sessionEncodeUrlState;
181   }
182
183   public void setSessionEncodeUrlState(String JavaDoc sessionEncodeUrlState) throws KeywordValueException{
184     this.sessionEncodeUrlState = sessionEncodeUrlState;
185     config.set("SessionManager.SessionEncodeUrlState",sessionEncodeUrlState);
186   }
187   
188   public String JavaDoc getSessionEncodeFirstUrl(){
189     return sessionEncodeFirstUrl;
190   }
191
192   public void setSessionEncodeFirstUrl(String JavaDoc sessionEncodeFirstUrl) throws KeywordValueException{
193     this.sessionEncodeFirstUrl = sessionEncodeFirstUrl;
194     config.set("SessionManager.SessionEncodeFirstUrl",sessionEncodeFirstUrl);
195   }
196
197   public String JavaDoc getMode() {
198     return mode;
199   }
200   
201   public void setMode(String JavaDoc mode) throws KeywordValueException{
202     this.mode = mode;
203     config.set("SessionManager.SessionHome.Mode",mode);
204   }
205
206   public String JavaDoc getMaxSessions() {
207     return maxSessions;
208   }
209
210   public void setMaxSessions(String JavaDoc maxSessions) throws KeywordValueException{
211     this.maxSessions = maxSessions;
212     config.set("SessionManager.SessionHome.MaxSessions",maxSessions);
213   }
214
215   public String JavaDoc getPageThreshold() {
216     return pageThreshold;
217   }
218
219   public void setPageThreshold(String JavaDoc pageThreshold) throws KeywordValueException{
220     this.pageThreshold = pageThreshold;
221     config.set("SessionManager.SessionHome.PageThreshold",pageThreshold);
222   }
223
224   public String JavaDoc getPageTimeThreshold() {
225     return pageTimeThreshold;
226   }
227
228   public void setPageTimeThreshold(String JavaDoc pageTimeThreshold) throws KeywordValueException{
229     this.pageTimeThreshold = pageTimeThreshold;
230     config.set("SessionManager.SessionHome.PageTimeThreshold",pageTimeThreshold);
231   }
232
233   public String JavaDoc getPageWait() {
234     return pageWait;
235   }
236
237   public void setPageWait(String JavaDoc pageWait) throws KeywordValueException{
238     this.pageWait = pageWait;
239     config.set("SessionManager.SessionHome.PageWait",pageWait);
240   }
241
242   public String JavaDoc getSaveOnRestart() {
243     return saveOnRestart;
244   }
245
246   public void setSaveOnRestart(String JavaDoc saveOnRestart) throws KeywordValueException{
247     this.saveOnRestart = saveOnRestart;
248     config.set("SessionManager.SessionHome.SaveOnRestart",saveOnRestart);
249   }
250
251   public String JavaDoc getPageDir() {
252     return pageDir;
253   }
254
255   public void setPageDir(String JavaDoc pageDir) throws KeywordValueException{
256     this.pageDir = pageDir;
257     config.set("SessionManager.SessionHome.PageDir",pageDir);
258   }
259
260   public String JavaDoc getDatabaseName() {
261     return databaseName;
262   }
263
264   public void setDatabaseName(String JavaDoc databaseName) throws KeywordValueException{
265     this.databaseName = databaseName;
266     config.set("SessionManager.SessionHome.DatabaseName",databaseName);
267   }
268
269   public String JavaDoc getDBTableName() {
270     return dBTableName;
271   }
272
273   public void setDBTableName(String JavaDoc dBTableName) throws KeywordValueException{
274     this.dBTableName = dBTableName;
275     config.set("SessionManager.SessionHome.DBTableName",dBTableName);
276   }
277
278   public String JavaDoc getSessionHomeClass() {
279     return sessionHomeClass;
280   }
281
282   public void setSessionHomeClass(String JavaDoc sessionHomeClass) throws KeywordValueException{
283     this.sessionHomeClass = sessionHomeClass;
284     config.set("SessionManager.SessionHome.Class",sessionHomeClass);
285   }
286
287   public String JavaDoc getSessionUserTableClass() {
288     return sessionUserTableClass;
289   }
290
291   public void setSessionUserTableClass(String JavaDoc sessionUserTableClass) throws KeywordValueException{
292     this.sessionUserTableClass = sessionUserTableClass;
293     config.set("SessionManager.SessionUserTable.Class",sessionUserTableClass);
294   }
295
296   /**
297    * Save state of SessionManager configuration parameters into config file.
298    * @return TRUE if OK, else FALSE.
299    */

300
301   public boolean saveState(){
302     try{
303     ConfigFileInterface confFile = config.getConfigFile();
304     confFile.write();
305    }catch(Exception JavaDoc e){ //FIXME log Exception
306
return false;
307     }
308     return true;
309   }
310 }
311
312
313
314
315
316
Popular Tags