Source Code Cross Referenced for Namespace.java in  » Ajax » zk » org » zkoss » idom » 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 » Ajax » zk » org.zkoss.idom 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Namespace.java
002:
003:        {{IS_NOTE
004:
005:        	Purpose: Namespace
006:        	Description:
007:        	History:
008:        		2001/10/21 16:06:46, Create, Tom M. Yeh
009:        }}IS_NOTE
010:
011:        Copyright (C) 2001 Potix Corporation. All Rights Reserved.
012:
013:        {{IS_RIGHT
014:        	This program is distributed under GPL Version 2.0 in the hope that
015:        	it will be useful, but WITHOUT ANY WARRANTY.
016:        }}IS_RIGHT
017:         */
018:        package org.zkoss.idom;
019:
020:        import java.util.HashMap;
021:        import java.util.Map;
022:        import java.io.Serializable;
023:        import java.io.IOException;
024:        import java.io.ObjectInputStream;
025:        import java.io.ObjectOutputStream;
026:
027:        /**
028:         * Represents the namespace.
029:         * A namespace is immutable, so you have to get a new one
030:         *
031:         * @author tomyeh
032:         * @see Item
033:         */
034:        public final class Namespace implements  Serializable, Cloneable {
035:            private static final long serialVersionUID = 20060622L;
036:
037:            /** The <code>Namespace</code> for when <i>not</i> in a namespace
038:             */
039:            public static final Namespace NO_NAMESPACE = newSpecialNamespace(
040:                    "", "");
041:            /** The xml namespace.
042:             */
043:            public static final Namespace XML_NAMESPACE = newSpecialNamespace(
044:                    "xml", "http://www.w3.org/XML/1998/namespace");
045:            /** The xmlns namespace.
046:             */
047:            public static final Namespace XMLNS_NAMESPACE = newSpecialNamespace(
048:                    "xmlns", "http://www.w3.org/XML/1998/namespace");
049:
050:            /** The prefix mapped to this namespace */
051:            private String _prefix;
052:            /** The URI for this namespace */
053:            private String _uri;
054:
055:            /** Returns the special namespace if prefix is special, or null if not.
056:             */
057:            public static Namespace getSpecial(String prefix) {
058:                if (prefix.equals("xml"))
059:                    return Namespace.XML_NAMESPACE;
060:                if (prefix.equals("xmlns"))
061:                    return Namespace.XMLNS_NAMESPACE;
062:                return null;
063:            }
064:
065:            /** Assigns a spacial namespace whose name starts with xml.
066:             * We need it because the verifier will reject it.
067:             */
068:            private static final Namespace newSpecialNamespace(String prefix,
069:                    String uri) {
070:                Namespace ns = new Namespace("", uri);
071:                ns._prefix = prefix; //assign directly to avoid checkNam...
072:                return ns;
073:            }
074:
075:            /**
076:             * Contructor.
077:             *
078:             * @param prefix String prefix to map to this namespace.
079:             * @param uri String URI for namespace.
080:             * @exception DOMException with NAMESPACE_ERR if the given prefix and uri
081:             * is invalid
082:             */
083:            public Namespace(String prefix, String uri) {
084:                Verifier.checkNamespacePrefix(prefix, null);
085:                Verifier.checkNamespaceURI(uri, null);
086:
087:                if (prefix.length() != 0 && uri.length() == 0)
088:                    throw new DOMException(DOMException.NAMESPACE_ERR,
089:                            "Non-empty prefix, " + prefix + ", requires a URI");
090:                _prefix = prefix;
091:                _uri = uri;
092:            }
093:
094:            /**
095:             * Gets the tag name of the giving local name.
096:             */
097:            public final String tagNameOf(String name) {
098:                assert (name.indexOf(':') < 0);
099:
100:                int len = _prefix.length();
101:                return len == 0 ? name : _prefix + ':' + name;
102:            }
103:
104:            /**
105:             * Gets the prefix mapped to this Namespace.
106:             */
107:            public final String getPrefix() {
108:                return _prefix;
109:            }
110:
111:            /**
112:             * Gets the namespace URI for this Namespace.
113:             */
114:            public final String getURI() {
115:                return _uri;
116:            }
117:
118:            /** Tests whether two namespace are the same in both prefix
119:             * and namespace URI.
120:             * On the other hand, equals check only the namespace URI.
121:             *
122:             * <p>Note: unlike equals, it throws DOMException if prefix
123:             * is the same but URI is different.
124:             *
125:             * @exception DOMException if they have the same prefix
126:             * but with different namespace URI
127:             */
128:            public final boolean equalsAll(Namespace ns) {
129:                if (_prefix.equals(ns._prefix))
130:                    if (_uri.equals(ns._uri))
131:                        return true;
132:                    else
133:                        throw new DOMException(DOMException.NAMESPACE_ERR,
134:                                "The same prefix, " + _prefix
135:                                        + ", cannot have different URI: "
136:                                        + _uri + " vs " + ns._uri);
137:                return false;
138:            }
139:
140:            //-- cloneable --//
141:            public Object clone() {
142:                try {
143:                    return super .clone();
144:                } catch (CloneNotSupportedException e) {
145:                    throw new InternalError();
146:                }
147:            }
148:
149:            //-- Object --//
150:            /** Note: equals() is based on URI only. */
151:            public boolean equals(Object o) {
152:                return this  == o
153:                        || ((o instanceof  Namespace) && _uri
154:                                .equals(((Namespace) o)._uri));
155:            }
156:
157:            /** Note: hashCode() is based on URI only. */
158:            public int hashCode() {
159:                return _uri.hashCode();
160:            }
161:
162:            public String toString() {
163:                return "[Namespace: \"" + _prefix + "\", \"" + _uri + "\"]";
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.