KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > lib > util > QName


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/util/QName.java,v 1.1 2004/08/02 15:45:49 unico Exp $
3  * $Revision: 1.1 $
4  * $Date: 2004/08/02 15:45:49 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *
23  */

24
25 package org.apache.webdav.lib.util;
26
27 import org.w3c.dom.Node JavaDoc;
28
29 /**
30  * A <code>QName</code> represents a fully-qualified name.
31  */

32 public class QName
33 {
34     private String JavaDoc namespaceURI;
35     private String JavaDoc localName;
36     private int hashCode;
37
38     public QName(String JavaDoc namespaceURI, String JavaDoc localName)
39     {
40         this.namespaceURI = (namespaceURI == null ? "" : namespaceURI).intern();
41         this.localName = localName.intern();
42         
43         String JavaDoc hash1 = this.namespaceURI.hashCode() + "";
44         String JavaDoc hash2 = this.localName.hashCode() + "";
45         String JavaDoc hash3 = hash1 + '_' + hash2;
46         this.hashCode=hash3.hashCode();
47     }
48
49     public String JavaDoc getNamespaceURI()
50     {
51         return this.namespaceURI;
52     }
53
54     public String JavaDoc getLocalName()
55     {
56         return this.localName;
57     }
58
59     public int hashCode()
60     {
61         return this.hashCode;
62     }
63
64     public boolean equals(Object JavaDoc obj)
65     {
66         return (obj != null
67             && (obj instanceof QName)
68             && namespaceURI == ((QName)obj).getNamespaceURI()
69             && localName == ((QName)obj).getLocalName());
70     }
71
72     public boolean matches(Node JavaDoc node)
73     {
74         return (node!=null)
75                     && (node.getNamespaceURI()!=null)
76                     && (node.getLocalName()!=null)
77                     && (node.getNamespaceURI().intern()==this.namespaceURI)
78                     && (node.getLocalName().intern()==this.localName);
79     }
80
81     public String JavaDoc toString()
82     {
83         return namespaceURI + ':' + localName;
84     }
85 }
86
Popular Tags