Source Code Cross Referenced for ApplicationMap.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.ServletContext;
008:        import java.io.Serializable;
009:        import java.util.*;
010:
011:        /**
012:         * A simple implementation of the {@link java.util.Map} interface to handle a collection of attributes and
013:         * init parameters in a {@link javax.servlet.ServletContext} object. The {@link #entrySet()} method
014:         * enumerates over all servlet context attributes and init parameters and returns a collection of both.
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:         */
020:        public class ApplicationMap extends AbstractMap implements  Serializable {
021:
022:            ServletContext context;
023:            Set entries;
024:
025:            /**
026:             * Creates a new map object given the servlet context.
027:             *
028:             * @param ctx the servlet context
029:             */
030:            public ApplicationMap(ServletContext ctx) {
031:                this .context = ctx;
032:            }
033:
034:            /**
035:             * Removes all entries from the Map and removes all attributes from the servlet context.
036:             */
037:            public void clear() {
038:                entries = null;
039:
040:                Enumeration e = context.getAttributeNames();
041:
042:                while (e.hasMoreElements()) {
043:                    context.removeAttribute(e.nextElement().toString());
044:                }
045:            }
046:
047:            /**
048:             * Creates a Set of all servlet context attributes as well as context init parameters.
049:             *
050:             * @return a Set of all servlet context attributes as well as context init parameters.
051:             */
052:            public Set entrySet() {
053:                if (entries == null) {
054:                    entries = new HashSet();
055:
056:                    // Add servlet context attributes
057:                    Enumeration enumeration = context.getAttributeNames();
058:
059:                    while (enumeration.hasMoreElements()) {
060:                        final String key = enumeration.nextElement().toString();
061:                        final Object value = context.getAttribute(key);
062:                        entries.add(new Map.Entry() {
063:                            public boolean equals(Object obj) {
064:                                Map.Entry entry = (Map.Entry) obj;
065:
066:                                return ((key == null) ? (entry.getKey() == null)
067:                                        : key.equals(entry.getKey()))
068:                                        && ((value == null) ? (entry.getValue() == null)
069:                                                : value
070:                                                        .equals(entry
071:                                                                .getValue()));
072:                            }
073:
074:                            public int hashCode() {
075:                                return ((key == null) ? 0 : key.hashCode())
076:                                        ^ ((value == null) ? 0 : value
077:                                                .hashCode());
078:                            }
079:
080:                            public Object getKey() {
081:                                return key;
082:                            }
083:
084:                            public Object getValue() {
085:                                return value;
086:                            }
087:
088:                            public Object setValue(Object obj) {
089:                                context.setAttribute(key.toString(), obj);
090:
091:                                return value;
092:                            }
093:                        });
094:                    }
095:
096:                    // Add servlet context init params
097:                    enumeration = context.getInitParameterNames();
098:
099:                    while (enumeration.hasMoreElements()) {
100:                        final String key = enumeration.nextElement().toString();
101:                        final Object value = context.getInitParameter(key);
102:                        entries.add(new Map.Entry() {
103:                            public boolean equals(Object obj) {
104:                                Map.Entry entry = (Map.Entry) obj;
105:
106:                                return ((key == null) ? (entry.getKey() == null)
107:                                        : key.equals(entry.getKey()))
108:                                        && ((value == null) ? (entry.getValue() == null)
109:                                                : value
110:                                                        .equals(entry
111:                                                                .getValue()));
112:                            }
113:
114:                            public int hashCode() {
115:                                return ((key == null) ? 0 : key.hashCode())
116:                                        ^ ((value == null) ? 0 : value
117:                                                .hashCode());
118:                            }
119:
120:                            public Object getKey() {
121:                                return key;
122:                            }
123:
124:                            public Object getValue() {
125:                                return value;
126:                            }
127:
128:                            public Object setValue(Object obj) {
129:                                context.setAttribute(key.toString(), obj);
130:
131:                                return value;
132:                            }
133:                        });
134:                    }
135:                }
136:
137:                return entries;
138:            }
139:
140:            /**
141:             * Returns the servlet context attribute or init parameter based on the given key. If the
142:             * entry is not found, <tt>null</tt> is returned.
143:             *
144:             * @param key the entry key.
145:             * @return the servlet context attribute or init parameter or <tt>null</tt> if the entry is not found.
146:             */
147:            public Object get(Object key) {
148:                // Try context attributes first, then init params
149:                // This gives the proper shadowing effects
150:                String keyString = key.toString();
151:                Object value = context.getAttribute(keyString);
152:
153:                return (value == null) ? context.getInitParameter(keyString)
154:                        : value;
155:            }
156:
157:            /**
158:             * Sets a servlet context attribute given a attribute name and value.
159:             *
160:             * @param key   the name of the attribute.
161:             * @param value the value to set.
162:             * @return the attribute that was just set.
163:             */
164:            public Object put(Object key, Object value) {
165:                entries = null;
166:                context.setAttribute(key.toString(), value);
167:
168:                return get(key);
169:            }
170:
171:            /**
172:             * Removes the specified servlet context attribute.
173:             *
174:             * @param key the attribute to remove.
175:             * @return the entry that was just removed.
176:             */
177:            public Object remove(Object key) {
178:                entries = null;
179:
180:                Object value = get(key);
181:                context.removeAttribute(key.toString());
182:
183:                return value;
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.