Source Code Cross Referenced for QName.java in  » IDE-Netbeans » xml » org » netbeans » modules » xml » wsdl » ui » common » 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 » IDE Netbeans » xml » org.netbeans.modules.xml.wsdl.ui.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.xml.wsdl.ui.common;
043:
044:        /**
045:         * Implements a fully-qualified name model.
046:         *
047:         * @author Enrico Lelina
048:         * @version 
049:         */
050:        public class QName {
051:
052:            /** The XML namespace URI. */
053:            public static final String XMLNS = "http://www.w3.org/XML/1998/namespace";
054:
055:            /** The local name. */
056:            private String mLocalName = null;
057:
058:            /** The namespace URI. */
059:            private String mNamespaceURI = null;
060:
061:            /** The namespace prefix. */
062:            private String mPrefix = null;
063:
064:            /**
065:             * Constructs an empty QName.
066:             */
067:            public QName() {
068:                // nothing to do
069:            }
070:
071:            /**
072:             * Constructs a QName given QName string
073:             * @param localName the local name
074:             */
075:            public QName(String qNameStr) {
076:                QName qName = getQNameFromString(qNameStr);
077:                this .mNamespaceURI = qName.getNamespaceURI();
078:                this .mPrefix = qName.getPrefix();
079:                this .mLocalName = qName.getLocalName();
080:            }
081:
082:            /**
083:             * Constructs a QName with the specified namespace URI and local name.
084:             * @param namespaceURI the namespace URI
085:             * @param name Either the local name or qualified name.
086:             */
087:            public QName(String namespaceURI, String name) {
088:                this (namespaceURI, null, name);
089:            }
090:
091:            /**
092:             * Constructs a QName with the specified namespace URI, namespace prefix
093:             * and local name.
094:             * @param namespaceURI the namespace URI
095:             * @param prefix the namespace prefix
096:             * @param name Either the local name or qualified name (in which case, prefix must be <code>null</code>).
097:             */
098:            public QName(String namespaceURI, String prefix, String name) {
099:                mNamespaceURI = namespaceURI;
100:                int colon;
101:                if ((null == prefix)
102:                        && ((name != null) && ((colon = name.indexOf(':')) != -1))) {
103:                    mPrefix = name.substring(0, colon);
104:                    mLocalName = name.substring(colon + 1);
105:                } else {
106:                    mPrefix = prefix;
107:                    mLocalName = name;
108:                }
109:            }
110:
111:            /**
112:             * Constructs a QName from the given QName string, e.g., "tns:foo", "foo".
113:             * @param qNameString the QName string
114:             * @return a new QName
115:             */
116:            public static QName getQNameFromString(String qNameString) {
117:                QName qName = new QName(QName.getNamespaceURI(qNameString),
118:                        QName.getPrefix(qNameString), QName
119:                                .getLocalName(qNameString));
120:
121:                if (qName.getLocalName() == null) {
122:                    return null;
123:                }
124:
125:                return qName;
126:            }
127:
128:            /**
129:             * Gets the prefix from the given QName string.
130:             * @param qName the QName string
131:             * @return the prefix or null if there is no prefix
132:             */
133:            public static String getPrefix(String qName) {
134:                if (qName == null || qName.trim().equals("")) {
135:                    return null;
136:                }
137:
138:                int index = qName.indexOf('{');
139:                //if { then we have namespace
140:                if (index != -1) {
141:                    return null;
142:                }
143:
144:                index = qName.lastIndexOf(':');
145:
146:                return ((index > 0) ? qName.substring(0, index) : null);
147:            }
148:
149:            /**
150:             * Gets the local name from the given QName string.
151:             * @param qName the QName string
152:             * @return the local name
153:             */
154:            public static String getLocalName(String qName) {
155:                if (qName == null || qName.trim().equals("")) {
156:                    return null;
157:                }
158:
159:                //first check if qName is {namespace}localName
160:                int index = qName.lastIndexOf('}');
161:
162:                if (index == -1) {
163:                    index = qName.lastIndexOf(':');
164:                }
165:
166:                return ((index < 0) ? qName : qName.substring(index + 1));
167:            }
168:
169:            public static String getNamespaceURI(String qName) {
170:                if (qName == null || qName.trim().equals("")) {
171:                    return null;
172:                }
173:
174:                String namespace = null;
175:                int sIndex = qName.indexOf('{');
176:                int eIndex = qName.lastIndexOf('}');
177:
178:                if (sIndex != -1 && eIndex != -1) {
179:                    namespace = qName.substring(sIndex + 1, eIndex);
180:                }
181:
182:                return namespace;
183:            }
184:
185:            /**
186:             * Gets the local name.
187:             * @return the local name
188:             */
189:            public String getLocalName() {
190:                return mLocalName;
191:            }
192:
193:            /**
194:             * Sets the local name.
195:             * @param localName the new local name
196:             */
197:            public void setLocalName(String localName) {
198:                mLocalName = localName;
199:            }
200:
201:            /**
202:             * Gets the namespace URI.
203:             * @return the namespace URI
204:             */
205:            public String getNamespaceURI() {
206:                return mNamespaceURI;
207:            }
208:
209:            /**
210:             * Sets the namespace URI.
211:             * @param namespaceURI the new namespace URI
212:             */
213:            public void setNamespaceURI(String namespaceURI) {
214:                mNamespaceURI = namespaceURI;
215:            }
216:
217:            /**
218:             * Gets the prefix.
219:             * @return the prefix
220:             */
221:            public String getPrefix() {
222:                return mPrefix;
223:            }
224:
225:            /**
226:             * Sets the prefix.
227:             * @param prefix the new prefix
228:             */
229:            public void setPrefix(String prefix) {
230:                mPrefix = prefix;
231:            }
232:
233:            /**
234:             * Returns the string representation of the QName. If the prefix is
235:             * available, then it will be [prefix]:[localName], for example,
236:             * tns:foo. If the prefix is not available and there is a namespace URI,
237:             * then it will be {[namespaceURI]}[localName], for example,
238:             * {http://schemas.xmlsoap.org/wsdl/}message. If neither the prefix not
239:             * the namespace URI are present, then it will just be the local name.
240:             * @return the QName's string representation
241:             */
242:            public String toString() {
243:                String qName = (null == getLocalName()) ? "" : getLocalName();
244:
245:                if (getPrefix() != null) {
246:                    return getPrefix() + ':' + qName;
247:                } else if (getNamespaceURI() != null) {
248:                    return '{' + getNamespaceURI() + '}' + qName;
249:                } else {
250:                    return qName;
251:                }
252:            }
253:
254:            public boolean equals(Object src) {
255:                if (!(src instanceof  QName)) {
256:                    return false;
257:                }
258:
259:                QName srcQName = (QName) src;
260:                return this .toString().equals(srcQName.toString());
261:
262:            }
263:
264:            public int hashCode() {
265:                return this.toString().hashCode();
266:            }
267:        }
w_ww.__j__a_va___2_s.__c__o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.