KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > xml > XsQName


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.xs.xml;
18
19
20 /** <p>Implementation of <code>xs:qName</code>.</p>
21  *
22  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
23  */

24 public class XsQName {
25   private final String JavaDoc namespaceURI;
26   private final String JavaDoc localName;
27   private final String JavaDoc prefix;
28
29   public XsQName(XsAnyURI pNamespaceURI, String JavaDoc pLocalName) {
30     this(pNamespaceURI == null ? null : pNamespaceURI.getURI(), pLocalName, null);
31   }
32
33   public XsQName(XsAnyURI pNamespaceURI, String JavaDoc pLocalName, String JavaDoc pPrefix) {
34     this(pNamespaceURI == null ? null : pNamespaceURI.getURI(), pLocalName, pPrefix);
35   }
36
37   public XsQName(String JavaDoc pNamespaceURI, String JavaDoc pLocalName) {
38     this(pNamespaceURI, pLocalName, null);
39   }
40
41   public XsQName(String JavaDoc pNamespaceURI, String JavaDoc pLocalName, String JavaDoc pPrefix) {
42     namespaceURI = (pNamespaceURI == null) ? "" : pNamespaceURI;
43     if (pLocalName == null) {
44       throw new NullPointerException JavaDoc("The localName must not be null.");
45     }
46     int offset = pLocalName.indexOf(':');
47     if (offset >= 0) {
48         throw new IllegalArgumentException JavaDoc("The localName " + pLocalName +
49                                            " is invalid, because it contains a namespace prefix.");
50     }
51     localName = pLocalName;
52     prefix = pPrefix;
53   }
54
55   public String JavaDoc getNamespaceURI() { return namespaceURI; }
56   public String JavaDoc getLocalName() { return localName; }
57   public String JavaDoc getPrefix() { return prefix; }
58
59   public boolean equals(Object JavaDoc pObject) {
60     if (pObject == null || !(pObject instanceof XsQName)) {
61       return false;
62     }
63     XsQName name = (XsQName) pObject;
64     return name.getNamespaceURI().equals(getNamespaceURI())
65         && name.getLocalName().equals(getLocalName());
66   }
67
68   public int hashCode() {
69       return getNamespaceURI().hashCode() + getLocalName().hashCode();
70   }
71
72   public String JavaDoc toString() {
73     if ("".equals(namespaceURI)) { return localName; }
74     return "{" + namespaceURI + "}" + localName;
75   }
76
77   public static String JavaDoc prefixOf(String JavaDoc pQName) {
78     int offset = pQName.indexOf(':');
79     if (offset > 0) {
80       return pQName.substring(0, offset);
81     } else {
82       return "";
83     }
84   }
85 }
86
Popular Tags