Source Code Cross Referenced for JspSession.java in  » Portal » Open-Portal » com » sun » portal » providers » jsp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.providers.jsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved. 
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms. 
004:         */
005:        package com.sun.portal.providers.jsp;
006:
007:        import java.util.Hashtable;
008:        import java.util.Enumeration;
009:        import java.util.Vector;
010:
011:        import javax.servlet.ServletContext;
012:        import javax.servlet.http.HttpSession;
013:        import javax.servlet.http.HttpSessionBindingListener;
014:        import javax.servlet.http.HttpSessionBindingEvent;
015:
016:        /*
017:         * The JspSession is an implementation of the HttpSession interface
018:         * that is used by the JSP servlet for maintaining session state.  One
019:         * JspSession object is created for each JSPProvider object, allowing
020:         * the JSPs in a channel to share session information.  Most of this
021:         * code was copied from the Tomcat ApplicationSession class.
022:         **/
023:        class JspSession implements  HttpSession {
024:            private Hashtable values = new Hashtable();
025:            private ServletContext sContext = null;
026:            private String id;
027:            private long creationTime = System.currentTimeMillis();;
028:            private long this AccessTime = creationTime;
029:            private long lastAccessed = creationTime;
030:            private int inactiveInterval = -1;
031:            private boolean valid = true;
032:
033:            JspSession() {
034:                id = "" + hashCode();
035:            }
036:
037:            void setServletContext(ServletContext sc) {
038:                sContext = sc;
039:            }
040:
041:            /**
042:             * Called by context when request comes in so that accesses and
043:             * inactivities can be dealt with accordingly.
044:             */
045:
046:            void accessed() {
047:                // set last accessed to thisAccessTime as it will be left over
048:                // from the previous access
049:                lastAccessed = this AccessTime;
050:                this AccessTime = System.currentTimeMillis();
051:
052:                validate();
053:            }
054:
055:            void validate() {
056:                // if we have an inactive interval, check to see if we've exceeded it
057:                if (inactiveInterval != -1) {
058:                    int this Interval = (int) (System.currentTimeMillis() - lastAccessed) / 1000;
059:
060:                    if (this Interval > inactiveInterval) {
061:                        invalidate();
062:                    }
063:                }
064:            }
065:
066:            // HTTP SESSION IMPLEMENTATION METHODS
067:
068:            public String getId() {
069:                if (valid) {
070:                    return id;
071:                } else {
072:                    throw new IllegalStateException("invalid session");
073:                }
074:            }
075:
076:            public long getCreationTime() {
077:                if (valid) {
078:                    return creationTime;
079:                } else {
080:                    throw new IllegalStateException("invalid session");
081:                }
082:            }
083:
084:            public long getLastAccessedTime() {
085:                if (valid) {
086:                    return lastAccessed;
087:                } else {
088:                    throw new IllegalStateException("invalid session");
089:                }
090:            }
091:
092:            public void invalidate() {
093:	// remove everything in the session
094:
095:	Enumeration enum = values.keys();
096:	while (enum.hasMoreElements()) {
097:	    String name = (String)enum.nextElement();
098:	    removeValue(name);
099:	}
100:
101:	valid = false;
102:    }
103:
104:            public boolean isNew() {
105:                if (!valid) {
106:                    throw new IllegalStateException("invalid session");
107:                }
108:
109:                if (this AccessTime == creationTime) {
110:                    return true;
111:                } else {
112:                    return false;
113:                }
114:            }
115:
116:            /**
117:             * @deprecated
118:             */
119:
120:            public void putValue(String name, Object value) {
121:                setAttribute(name, value);
122:            }
123:
124:            public void setAttribute(String name, Object value) {
125:                if (!valid) {
126:                    throw new IllegalStateException("invalid session");
127:                }
128:
129:                if (name == null) {
130:                    throw new IllegalArgumentException("null name");
131:                }
132:
133:                removeValue(name); // remove any existing binding
134:
135:                if (value != null
136:                        && value instanceof  HttpSessionBindingListener) {
137:                    HttpSessionBindingEvent e = new HttpSessionBindingEvent(
138:                            this , name);
139:
140:                    ((HttpSessionBindingListener) value).valueBound(e);
141:                }
142:
143:                values.put(name, value);
144:            }
145:
146:            /**
147:             * @deprecated
148:             */
149:            public Object getValue(String name) {
150:                return getAttribute(name);
151:            }
152:
153:            public Object getAttribute(String name) {
154:                if (!valid) {
155:                    throw new IllegalStateException("invalid session");
156:                }
157:
158:                if (name == null) {
159:                    throw new IllegalArgumentException("null name");
160:                }
161:
162:                return values.get(name);
163:            }
164:
165:            /**
166:             * @deprecated
167:             */
168:            public String[] getValueNames() {
169:                Enumeration e = getAttributeNames();
170:                Vector names = new Vector();
171:
172:                while (e.hasMoreElements()) {
173:                    names.addElement(e.nextElement());
174:                }
175:
176:                String[] valueNames = new String[names.size()];
177:
178:                names.copyInto(valueNames);
179:
180:                return valueNames;
181:
182:            }
183:
184:            public Enumeration getAttributeNames() {
185:                if (!valid) {
186:                    throw new IllegalStateException("invalid session");
187:                }
188:
189:                Hashtable valuesClone = (Hashtable) values.clone();
190:
191:                return (Enumeration) valuesClone.keys();
192:            }
193:
194:            /**
195:             * @deprecated
196:             */
197:
198:            public void removeValue(String name) {
199:                removeAttribute(name);
200:            }
201:
202:            public void removeAttribute(String name) {
203:                if (!valid) {
204:                    throw new IllegalStateException("invalid session");
205:                }
206:
207:                if (name == null) {
208:                    throw new IllegalArgumentException("null name");
209:                }
210:
211:                Object o = values.get(name);
212:
213:                if (o instanceof  HttpSessionBindingListener) {
214:                    HttpSessionBindingEvent e = new HttpSessionBindingEvent(
215:                            this , name);
216:
217:                    ((HttpSessionBindingListener) o).valueUnbound(e);
218:                }
219:
220:                values.remove(name);
221:            }
222:
223:            public void setMaxInactiveInterval(int interval) {
224:                if (!valid) {
225:                    throw new IllegalStateException("invalid session");
226:                }
227:
228:                inactiveInterval = interval;
229:            }
230:
231:            public int getMaxInactiveInterval() {
232:                if (!valid) {
233:                    throw new IllegalStateException("invalid session");
234:                }
235:
236:                return inactiveInterval;
237:            }
238:
239:            public ServletContext getServletContext() {
240:                return sContext;
241:            }
242:
243:            /**
244:             *
245:             * @deprecated
246:             */
247:            public javax.servlet.http.HttpSessionContext getSessionContext() {
248:                return new javax.servlet.http.HttpSessionContext() {
249:                    /**
250:                     *
251:                     * @deprecated
252:                     */
253:
254:                    public HttpSession getSession(String sessionId) {
255:                        return null;
256:                    }
257:
258:                    /**
259:                     *
260:                     * @deprecated
261:                     */
262:
263:                    public Enumeration getIds() {
264:                        // cheap hack to get an empty enum
265:                        Vector v = new Vector();
266:
267:                        return v.elements();
268:                    }
269:                };
270:            }
271:
272:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.