Source Code Cross Referenced for TestHttpSession.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » 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 » Wiki Engine » JSPWiki » com.ecyrd.jspwiki 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ecyrd.jspwiki;
002:
003:        import java.util.Enumeration;
004:        import java.util.HashMap;
005:        import java.util.Iterator;
006:        import java.util.Map;
007:        import java.util.Random;
008:        import java.security.SecureRandom;
009:        import java.util.Vector;
010:
011:        import javax.servlet.ServletContext;
012:        import javax.servlet.http.HttpSession;
013:
014:        /**
015:         * This is a mock HttpSession implementation. It is used for testing.
016:         * Most methods work as the should; notable exceptions include
017:         * getSessionContext/getServletContext.
018:         * @author Andrew R. Jaquith
019:         */
020:        public class TestHttpSession implements  HttpSession {
021:
022:            protected final long m_createTime;
023:
024:            protected static final Random RANDOM = new SecureRandom();
025:
026:            protected final String m_id;
027:
028:            protected final long m_lastAccessTime;
029:
030:            protected final Map m_attributes;
031:
032:            protected int m_inactiveInterval;
033:
034:            protected boolean m_invalidated;
035:
036:            /**
037:             * Constructs a new instance of this class.
038:             */
039:            public TestHttpSession() {
040:                m_createTime = System.currentTimeMillis();
041:                m_lastAccessTime = m_createTime;
042:                m_id = String.valueOf(RANDOM.nextLong());
043:                m_attributes = new HashMap();
044:                m_invalidated = false;
045:                m_inactiveInterval = 1800;
046:            }
047:
048:            /**
049:             * @see javax.servlet.http.HttpSession#getCreationTime()
050:             */
051:            public long getCreationTime() {
052:                return m_createTime;
053:            }
054:
055:            /**
056:             * @see javax.servlet.http.HttpSession#getId()
057:             */
058:            public String getId() {
059:                return m_id;
060:            }
061:
062:            /**
063:             * @see javax.servlet.http.HttpSession#getLastAccessedTime()
064:             */
065:            public long getLastAccessedTime() {
066:                return m_lastAccessTime;
067:            }
068:
069:            /**
070:             * Always returns null.
071:             * @see javax.servlet.http.HttpSession#getServletContext()
072:             */
073:            public ServletContext getServletContext() {
074:                return null;
075:            }
076:
077:            /**
078:             * No-op.
079:             * @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
080:             */
081:            public void setMaxInactiveInterval(int arg0) {
082:                m_inactiveInterval = arg0;
083:            }
084:
085:            /**
086:             * Returns the number of seconds of allowed inactivity;
087:             * returns 1800 seconds (30 minutes) by default.
088:             * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
089:             */
090:            public int getMaxInactiveInterval() {
091:                return m_inactiveInterval;
092:            }
093:
094:            /**
095:             * No-op; returns null;
096:             * @see javax.servlet.http.HttpSession#getSessionContext()
097:             * @deprecated
098:             */
099:            public javax.servlet.http.HttpSessionContext getSessionContext() {
100:                return null;
101:            }
102:
103:            /**
104:             * Returns the attribute with a given name, or null of no object is bound
105:             * with that name.
106:             * @see javax.servlet.http.HttpSession#getAttribute(java.lang.String)
107:             */
108:            public Object getAttribute(String arg0) {
109:                return m_attributes.get(arg0);
110:            }
111:
112:            /**
113:             * Delegates to {@link #getAttribute(String)}.
114:             * @see javax.servlet.http.HttpSession#getValue(java.lang.String)
115:             * @deprecated
116:             */
117:            public Object getValue(String arg0) {
118:                return getAttribute(arg0);
119:            }
120:
121:            /**
122:             * @see javax.servlet.http.HttpSession#getAttributeNames()
123:             */
124:            public Enumeration getAttributeNames() {
125:                Vector items = new Vector();
126:                for (Iterator it = m_attributes.keySet().iterator(); it
127:                        .hasNext();) {
128:                    items.add(it.next());
129:                }
130:                return items.elements();
131:            }
132:
133:            /**
134:             * @see javax.servlet.http.HttpSession#getValueNames()
135:             * @deprecated
136:             */
137:            public String[] getValueNames() {
138:                Vector items = new Vector();
139:                for (Iterator it = m_attributes.keySet().iterator(); it
140:                        .hasNext();) {
141:                    items.add(it.next());
142:                }
143:                return (String[]) items.toArray(new String[items.size()]);
144:            }
145:
146:            /**
147:             * @see javax.servlet.http.HttpSession#setAttribute(java.lang.String,
148:             *      java.lang.Object)
149:             */
150:            public void setAttribute(String arg0, Object arg1) {
151:                m_attributes.put(arg0, arg1);
152:            }
153:
154:            /**
155:             * @see javax.servlet.http.HttpSession#putValue(java.lang.String,
156:             *      java.lang.Object)
157:             * @deprecated
158:             */
159:            public void putValue(String arg0, Object arg1) {
160:                setAttribute(arg0, arg1);
161:            }
162:
163:            /**
164:             * @see javax.servlet.http.HttpSession#removeAttribute(java.lang.String)
165:             */
166:            public void removeAttribute(String arg0) {
167:                m_attributes.remove(arg0);
168:            }
169:
170:            /**
171:             * @see javax.servlet.http.HttpSession#removeValue(java.lang.String)
172:             * @deprecated
173:             */
174:            public void removeValue(String arg0) {
175:                removeAttribute(arg0);
176:            }
177:
178:            /**
179:             * Invalidates the session.
180:             * @see javax.servlet.http.HttpSession#invalidate()
181:             */
182:            public void invalidate() {
183:                if (m_invalidated) {
184:                    throw new IllegalStateException(
185:                            "Session is already invalidated.");
186:                }
187:                m_invalidated = true;
188:                m_attributes.clear();
189:            }
190:
191:            /**
192:             * Always returns false.
193:             * @see javax.servlet.http.HttpSession#isNew()
194:             */
195:            public boolean isNew() {
196:                return false;
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.