Source Code Cross Referenced for SessionMap.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » dispatcher » 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 » J2EE » webwork 2.2.6 » com.opensymphony.webwork.dispatcher 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.dispatcher;
006:
007:        import javax.servlet.http.HttpServletRequest;
008:        import javax.servlet.http.HttpSession;
009:        import java.io.Serializable;
010:        import java.util.*;
011:
012:        /**
013:         * A simple implementation of the {@link java.util.Map} interface to handle a collection of HTTP session
014:         * attributes. The {@link #entrySet()} method enumerates over all session attributes and creates a Set of entries.
015:         * Note, this will occur lazily - only when the entry set is asked for.
016:         *
017:         * @author <a href="mailto:rickard@middleware-company.com">Rickard �berg</a>
018:         * @author Bill Lynch (docs)
019:         * @author tm_jee
020:         * @version $Date: 2006-09-16 19:38:35 +0200 (Sat, 16 Sep 2006) $ $Id: SessionMap.java 2723 2006-09-16 17:38:35Z tmjee $
021:         */
022:        public class SessionMap extends AbstractMap implements  Serializable {
023:
024:            protected HttpSession session;
025:            protected Set entries;
026:            protected HttpServletRequest request;
027:
028:            /**
029:             * Creates a new session map given a http servlet request. Note, ths enumeration of request
030:             * attributes will occur when the map entries are asked for.
031:             *
032:             * @param request the http servlet request object.
033:             */
034:            public SessionMap(HttpServletRequest request) {
035:                // note, holding on to this request and relying on lazy session initalization will not work
036:                // if you are running your action invocation in a background task, such as using the
037:                // "exec-and-wait" interceptor
038:                this .request = request;
039:                this .session = request.getSession(false);
040:            }
041:
042:            /**
043:             * Invalidate the http session.
044:             */
045:            public void invalidate() {
046:                if (session == null) {
047:                    return;
048:                }
049:
050:                synchronized (session) {
051:                    session.invalidate();
052:                    session = null;
053:                    entries = null;
054:                }
055:            }
056:
057:            /**
058:             * Removes all attributes from the session as well as clears entries in this map.
059:             */
060:            public void clear() {
061:                if (session == null) {
062:                    return;
063:                }
064:                synchronized (session) {
065:                    entries = null;
066:                    Enumeration attributeNamesEnum = session
067:                            .getAttributeNames();
068:                    while (attributeNamesEnum.hasMoreElements()) {
069:                        session.removeAttribute((String) attributeNamesEnum
070:                                .nextElement());
071:                    }
072:                }
073:            }
074:
075:            /**
076:             * Returns a Set of attributes from the http session.
077:             *
078:             * @return a Set of attributes from the http session.
079:             */
080:            public Set entrySet() {
081:                if (session == null) {
082:                    return Collections.EMPTY_SET;
083:                }
084:
085:                synchronized (session) {
086:                    if (entries == null) {
087:                        entries = new HashSet();
088:
089:                        Enumeration enumeration = session.getAttributeNames();
090:
091:                        while (enumeration.hasMoreElements()) {
092:                            final String key = enumeration.nextElement()
093:                                    .toString();
094:                            final Object value = session.getAttribute(key);
095:                            entries.add(new Map.Entry() {
096:                                public boolean equals(Object obj) {
097:                                    Map.Entry entry = (Map.Entry) obj;
098:
099:                                    return ((key == null) ? (entry.getKey() == null)
100:                                            : key.equals(entry.getKey()))
101:                                            && ((value == null) ? (entry
102:                                                    .getValue() == null)
103:                                                    : value.equals(entry
104:                                                            .getValue()));
105:                                }
106:
107:                                public int hashCode() {
108:                                    return ((key == null) ? 0 : key.hashCode())
109:                                            ^ ((value == null) ? 0 : value
110:                                                    .hashCode());
111:                                }
112:
113:                                public Object getKey() {
114:                                    return key;
115:                                }
116:
117:                                public Object getValue() {
118:                                    return value;
119:                                }
120:
121:                                public Object setValue(Object obj) {
122:                                    session.setAttribute(key.toString(), obj);
123:
124:                                    return value;
125:                                }
126:                            });
127:                        }
128:                    }
129:                }
130:
131:                return entries;
132:            }
133:
134:            /**
135:             * Returns the session attribute associated with the given key or <tt>null</tt> if it doesn't exist.
136:             *
137:             * @param key the name of the session attribute.
138:             * @return the session attribute or <tt>null</tt> if it doesn't exist.
139:             */
140:            public Object get(Object key) {
141:                if (session == null) {
142:                    return null;
143:                }
144:
145:                synchronized (session) {
146:                    return session.getAttribute(key.toString());
147:                }
148:            }
149:
150:            /**
151:             * Saves an attribute in the session.
152:             *
153:             * @param key   the name of the session attribute.
154:             * @param value the value to set.
155:             * @return the object that was just set.
156:             */
157:            public Object put(Object key, Object value) {
158:                synchronized (this ) {
159:                    if (session == null) {
160:                        session = request.getSession(true);
161:                    }
162:                }
163:
164:                synchronized (session) {
165:                    entries = null;
166:                    session.setAttribute(key.toString(), value);
167:
168:                    return get(key);
169:                }
170:            }
171:
172:            /**
173:             * Removes the specified session attribute.
174:             *
175:             * @param key the name of the attribute to remove.
176:             * @return the value that was removed or <tt>null</tt> if the value was not found (and hence, not removed).
177:             */
178:            public Object remove(Object key) {
179:                if (session == null) {
180:                    return null;
181:                }
182:
183:                synchronized (session) {
184:                    entries = null;
185:
186:                    Object value = get(key);
187:                    session.removeAttribute(key.toString());
188:
189:                    return value;
190:                }
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.