Source Code Cross Referenced for ApplicationMap.java in  » Web-Framework » struts-2.0.11 » org » apache » struts2 » 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 » Web Framework » struts 2.0.11 » org.apache.struts2.dispatcher 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ApplicationMap.java 471756 2006-11-06 15:01:43Z husted $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts2.dispatcher;
022:
023:        import java.io.Serializable;
024:        import java.util.AbstractMap;
025:        import java.util.Enumeration;
026:        import java.util.HashSet;
027:        import java.util.Map;
028:        import java.util.Set;
029:
030:        import javax.servlet.ServletContext;
031:
032:        /**
033:         * A simple implementation of the {@link java.util.Map} interface to handle a collection of attributes and
034:         * init parameters in a {@link javax.servlet.ServletContext} object. The {@link #entrySet()} method
035:         * enumerates over all servlet context attributes and init parameters and returns a collection of both.
036:         * Note, this will occur lazily - only when the entry set is asked for.
037:         *
038:         */
039:        public class ApplicationMap extends AbstractMap implements  Serializable {
040:
041:            private static final long serialVersionUID = 9136809763083228202L;
042:
043:            private ServletContext context;
044:            private Set<Object> entries;
045:
046:            /**
047:             * Creates a new map object given the servlet context.
048:             *
049:             * @param ctx the servlet context
050:             */
051:            public ApplicationMap(ServletContext ctx) {
052:                this .context = ctx;
053:            }
054:
055:            /**
056:             * Removes all entries from the Map and removes all attributes from the servlet context.
057:             */
058:            public void clear() {
059:                entries = null;
060:
061:                Enumeration e = context.getAttributeNames();
062:
063:                while (e.hasMoreElements()) {
064:                    context.removeAttribute(e.nextElement().toString());
065:                }
066:            }
067:
068:            /**
069:             * Creates a Set of all servlet context attributes as well as context init parameters.
070:             *
071:             * @return a Set of all servlet context attributes as well as context init parameters.
072:             */
073:            public Set entrySet() {
074:                if (entries == null) {
075:                    entries = new HashSet<Object>();
076:
077:                    // Add servlet context attributes
078:                    Enumeration enumeration = context.getAttributeNames();
079:
080:                    while (enumeration.hasMoreElements()) {
081:                        final String key = enumeration.nextElement().toString();
082:                        final Object value = context.getAttribute(key);
083:                        entries.add(new Map.Entry() {
084:                            public boolean equals(Object obj) {
085:                                Map.Entry entry = (Map.Entry) obj;
086:
087:                                return ((key == null) ? (entry.getKey() == null)
088:                                        : key.equals(entry.getKey()))
089:                                        && ((value == null) ? (entry.getValue() == null)
090:                                                : value
091:                                                        .equals(entry
092:                                                                .getValue()));
093:                            }
094:
095:                            public int hashCode() {
096:                                return ((key == null) ? 0 : key.hashCode())
097:                                        ^ ((value == null) ? 0 : value
098:                                                .hashCode());
099:                            }
100:
101:                            public Object getKey() {
102:                                return key;
103:                            }
104:
105:                            public Object getValue() {
106:                                return value;
107:                            }
108:
109:                            public Object setValue(Object obj) {
110:                                context.setAttribute(key.toString(), obj);
111:
112:                                return value;
113:                            }
114:                        });
115:                    }
116:
117:                    // Add servlet context init params
118:                    enumeration = context.getInitParameterNames();
119:
120:                    while (enumeration.hasMoreElements()) {
121:                        final String key = enumeration.nextElement().toString();
122:                        final Object value = context.getInitParameter(key);
123:                        entries.add(new Map.Entry() {
124:                            public boolean equals(Object obj) {
125:                                Map.Entry entry = (Map.Entry) obj;
126:
127:                                return ((key == null) ? (entry.getKey() == null)
128:                                        : key.equals(entry.getKey()))
129:                                        && ((value == null) ? (entry.getValue() == null)
130:                                                : value
131:                                                        .equals(entry
132:                                                                .getValue()));
133:                            }
134:
135:                            public int hashCode() {
136:                                return ((key == null) ? 0 : key.hashCode())
137:                                        ^ ((value == null) ? 0 : value
138:                                                .hashCode());
139:                            }
140:
141:                            public Object getKey() {
142:                                return key;
143:                            }
144:
145:                            public Object getValue() {
146:                                return value;
147:                            }
148:
149:                            public Object setValue(Object obj) {
150:                                context.setAttribute(key.toString(), obj);
151:
152:                                return value;
153:                            }
154:                        });
155:                    }
156:                }
157:
158:                return entries;
159:            }
160:
161:            /**
162:             * Returns the servlet context attribute or init parameter based on the given key. If the
163:             * entry is not found, <tt>null</tt> is returned.
164:             *
165:             * @param key the entry key.
166:             * @return the servlet context attribute or init parameter or <tt>null</tt> if the entry is not found.
167:             */
168:            public Object get(Object key) {
169:                // Try context attributes first, then init params
170:                // This gives the proper shadowing effects
171:                String keyString = key.toString();
172:                Object value = context.getAttribute(keyString);
173:
174:                return (value == null) ? context.getInitParameter(keyString)
175:                        : value;
176:            }
177:
178:            /**
179:             * Sets a servlet context attribute given a attribute name and value.
180:             *
181:             * @param key   the name of the attribute.
182:             * @param value the value to set.
183:             * @return the attribute that was just set.
184:             */
185:            public Object put(Object key, Object value) {
186:                entries = null;
187:                context.setAttribute(key.toString(), value);
188:
189:                return get(key);
190:            }
191:
192:            /**
193:             * Removes the specified servlet context attribute.
194:             *
195:             * @param key the attribute to remove.
196:             * @return the entry that was just removed.
197:             */
198:            public Object remove(Object key) {
199:                entries = null;
200:
201:                Object value = get(key);
202:                context.removeAttribute(key.toString());
203:
204:                return value;
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.