KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > wsrp > producer > impl > helpers > WSRPHttpSession


1 /*
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  *
5  * Created on 9 janv. 2004
6  */

7 package org.exoplatform.services.wsrp.producer.impl.helpers;
8
9 import java.util.Enumeration JavaDoc;
10 import java.util.HashMap JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.Map JavaDoc;
13 import java.util.Collections JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import javax.servlet.ServletContext JavaDoc;
17 import javax.servlet.http.HttpSession JavaDoc;
18 import javax.servlet.http.HttpSessionContext JavaDoc;
19
20 /**
21  * @author Mestrallet Benjamin
22  * benjmestrallet@users.sourceforge.net
23  */

24 public class WSRPHttpSession implements HttpSession JavaDoc {
25   
26   private String JavaDoc sessionID;
27   private Map JavaDoc attributsMap = new HashMap JavaDoc();
28   private long creationTime;
29   private long lastAccessTime;
30   private int maxInactiveInterval = 900;
31   private boolean isNew = false;
32   private boolean invalidated = false;
33   
34   public WSRPHttpSession(String JavaDoc sessionID, int maxInactiveInterval) {
35     creationTime = System.currentTimeMillis();
36     this.sessionID = sessionID;
37     this.maxInactiveInterval = maxInactiveInterval;
38     isNew = true;
39   }
40
41   public long getCreationTime() {
42     if(invalidated)
43       throw new IllegalStateException JavaDoc();
44     return creationTime;
45   }
46
47   public String JavaDoc getId() {
48     if(invalidated)
49       throw new IllegalStateException JavaDoc();
50     return sessionID;
51   }
52
53   public long getLastAccessedTime() {
54     if(invalidated)
55       throw new IllegalStateException JavaDoc();
56     return lastAccessTime;
57   }
58   
59   public void setLastAccessTime(long lastAccessTime){
60     this.lastAccessTime = lastAccessTime;
61   }
62
63   public ServletContext JavaDoc getServletContext() {
64     if(invalidated)
65       throw new IllegalStateException JavaDoc();
66     return null;
67   }
68
69   public void setMaxInactiveInterval(int arg0) {
70     if(invalidated)
71       throw new IllegalStateException JavaDoc();
72     maxInactiveInterval = arg0;
73   }
74
75   public int getMaxInactiveInterval() {
76     if(invalidated)
77       throw new IllegalStateException JavaDoc();
78     return maxInactiveInterval;
79   }
80
81   public Object JavaDoc getAttribute(String JavaDoc arg0) {
82     if(invalidated)
83       throw new IllegalStateException JavaDoc();
84     return attributsMap.get(arg0);
85   }
86
87   public Enumeration JavaDoc getAttributeNames() {
88     if(invalidated)
89       throw new IllegalStateException JavaDoc();
90     return Collections.enumeration(attributsMap.keySet());
91   }
92
93   public void setAttribute(String JavaDoc arg0, Object JavaDoc arg1) {
94     if(invalidated)
95       throw new IllegalStateException JavaDoc();
96     attributsMap.put(arg0, arg1);
97   }
98
99   public void removeAttribute(String JavaDoc arg0) {
100     if(invalidated)
101       throw new IllegalStateException JavaDoc();
102     attributsMap.remove(arg0);
103   }
104
105   public void invalidate() {
106     Set JavaDoc keys = attributsMap.entrySet();
107     for (Iterator JavaDoc iter = keys.iterator(); iter.hasNext();) {
108       String JavaDoc key = (String JavaDoc) iter.next();
109       attributsMap.remove(key);
110     }
111     invalidated = true;
112   }
113   
114   public boolean isInvalidated(){
115     return invalidated;
116   }
117
118   public boolean isNew() {
119     if(invalidated)
120       throw new IllegalStateException JavaDoc();
121     return false;
122   }
123   
124   public void setNew(boolean isNew){
125     this.isNew = isNew;
126   }
127   
128   //deprecated methods
129
public void removeValue(String JavaDoc arg0) {
130   }
131   
132   public void putValue(String JavaDoc arg0, Object JavaDoc arg1) {
133   }
134   
135   public String JavaDoc[] getValueNames() {
136     return null;
137   }
138   
139   public Object JavaDoc getValue(String JavaDoc arg0) {
140     return null;
141   }
142
143   public HttpSessionContext JavaDoc getSessionContext() {
144     return null;
145   }
146 }
147
Popular Tags