Source Code Cross Referenced for SimpleNamespaceContext.java in  » Web-Services » spring-ws-1.0.0 » org » springframework » xml » namespace » 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 Services » spring ws 1.0.0 » org.springframework.xml.namespace 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.xml.namespace;
018:
019:        import java.util.ArrayList;
020:        import java.util.Collections;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Map;
025:        import javax.xml.XMLConstants;
026:        import javax.xml.namespace.NamespaceContext;
027:
028:        import org.springframework.util.Assert;
029:
030:        /**
031:         * Simple <code>javax.xml.namespace.NamespaceContext</code> implementation. Follows the standard
032:         * <code>NamespaceContext</code> contract, and is loadable via a <code>java.util.Map</code> or
033:         * <code>java.util.Properties</code> object
034:         *
035:         * @author Arjen Poutsma
036:         * @since 1.0.0
037:         */
038:        public class SimpleNamespaceContext implements  NamespaceContext {
039:
040:            private Map prefixToNamespaceUri = new HashMap();
041:
042:            /** Maps a <code>String</code> namespaceUri to a <code>List</code> of prefixes */
043:            private Map namespaceUriToPrefixes = new HashMap();
044:
045:            private String defaultNamespaceUri = "";
046:
047:            public String getNamespaceURI(String prefix) {
048:                Assert.notNull(prefix, "prefix is null");
049:                if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
050:                    return XMLConstants.XML_NS_URI;
051:                } else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
052:                    return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
053:                } else if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
054:                    return defaultNamespaceUri;
055:                } else if (prefixToNamespaceUri.containsKey(prefix)) {
056:                    return (String) prefixToNamespaceUri.get(prefix);
057:                }
058:                return "";
059:            }
060:
061:            public String getPrefix(String namespaceUri) {
062:                List prefixes = getPrefixesInternal(namespaceUri);
063:                return prefixes.isEmpty() ? null : (String) prefixes.get(0);
064:            }
065:
066:            public Iterator getPrefixes(String namespaceUri) {
067:                return getPrefixesInternal(namespaceUri).iterator();
068:            }
069:
070:            /**
071:             * Sets the bindings for this namespace context. The supplied map must consist of string key value pairs.
072:             *
073:             * @param bindings the bindings
074:             */
075:            public void setBindings(Map bindings) {
076:                for (Iterator iterator = bindings.entrySet().iterator(); iterator
077:                        .hasNext();) {
078:                    Map.Entry entry = (Map.Entry) iterator.next();
079:                    bindNamespaceUri((String) entry.getKey(), (String) entry
080:                            .getValue());
081:                }
082:            }
083:
084:            /**
085:             * Binds the given namespace as default namespace.
086:             *
087:             * @param namespaceUri the namespace uri
088:             */
089:            public void bindDefaultNamespaceUri(String namespaceUri) {
090:                bindNamespaceUri(XMLConstants.DEFAULT_NS_PREFIX, namespaceUri);
091:            }
092:
093:            /**
094:             * Binds the given prefix to the given namespace.
095:             *
096:             * @param prefix       the namespace prefix
097:             * @param namespaceUri the namespace uri
098:             */
099:            public void bindNamespaceUri(String prefix, String namespaceUri) {
100:                Assert.notNull(prefix, "No prefix given");
101:                Assert.notNull(namespaceUri, "No namespaceUri given");
102:                if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
103:                    defaultNamespaceUri = namespaceUri;
104:                } else {
105:                    prefixToNamespaceUri.put(prefix, namespaceUri);
106:                    getPrefixesInternal(namespaceUri).add(prefix);
107:                }
108:            }
109:
110:            /** Removes all declared prefixes. */
111:            public void clear() {
112:                prefixToNamespaceUri.clear();
113:            }
114:
115:            /**
116:             * Returns all declared prefixes.
117:             *
118:             * @return the declared prefixes
119:             */
120:            public Iterator getBoundPrefixes() {
121:                return prefixToNamespaceUri.keySet().iterator();
122:            }
123:
124:            private List getPrefixesInternal(String namespaceUri) {
125:                if (defaultNamespaceUri.equals(namespaceUri)) {
126:                    return Collections
127:                            .singletonList(XMLConstants.DEFAULT_NS_PREFIX);
128:                } else if (XMLConstants.XML_NS_URI.equals(namespaceUri)) {
129:                    return Collections
130:                            .singletonList(XMLConstants.XML_NS_PREFIX);
131:                } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI
132:                        .equals(namespaceUri)) {
133:                    return Collections
134:                            .singletonList(XMLConstants.XMLNS_ATTRIBUTE);
135:                } else {
136:                    List list = (List) namespaceUriToPrefixes.get(namespaceUri);
137:                    if (list == null) {
138:                        list = new ArrayList();
139:                        namespaceUriToPrefixes.put(namespaceUri, list);
140:                    }
141:                    return list;
142:                }
143:            }
144:
145:            /**
146:             * Removes the given prefix from this context.
147:             *
148:             * @param prefix the prefix to be removed
149:             */
150:            public void removeBinding(String prefix) {
151:                if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
152:                    defaultNamespaceUri = "";
153:                } else {
154:                    String namespaceUri = (String) namespaceUriToPrefixes
155:                            .get(prefix);
156:                    List prefixes = getPrefixesInternal(namespaceUri);
157:                    prefixes.remove(prefix);
158:                    namespaceUriToPrefixes.remove(prefixes);
159:                }
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.