View Javadoc

1   /*-------------------------------------------------------------------------
2    Copyright 2006 Olivier Berlanger
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  package net.sf.xolite;
17  
18  
19  /**
20   * Class holding a "local name" and a "namespace URI".
21   * 
22   * @author Olivier Berlanger
23   */
24  public class NamespacedName {
25  
26  
27      private String uri;
28      private String name;
29  
30  
31      public NamespacedName(String namespaceUri, String localName) {
32          uri = (namespaceUri == null) ? "" : namespaceUri;
33          name = localName;
34      }
35  
36  
37      public String getNamespaceUri() {
38          return uri;
39      }
40  
41  
42      public String getLocalName() {
43          return name;
44      }
45  
46  
47      public String toString() {
48          return uri + ":" + name;
49      }
50  
51  
52      public boolean equals(Object obj) {
53          if (obj == null) return false;
54          if (getClass() != obj.getClass()) return false;
55          NamespacedName qName = (NamespacedName) obj;
56          if (!name.equals(qName.name)) return false;
57          if (uri == null) {
58              if (qName.uri != null) return false;
59          } else {
60              if (!uri.equals(qName.uri)) return false;
61          }
62          return true;
63      }
64  
65  
66      public int hashCode() {
67          int uriHash = (uri == null) ? 999 : uri.hashCode();
68          int nameHash = (name == null) ? 777 : name.hashCode();
69          return (uriHash << 15) + nameHash;
70      }
71  
72  
73  }