KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > PrefixedQName


1 /*
2  * Copyright 2004,2005 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 package org.apache.axis2.saaj;
17
18 import javax.xml.namespace.QName JavaDoc;
19 import javax.xml.soap.Name JavaDoc;
20
21 /**
22  * Class Prefixed QName
23  *
24  * Took this implementation from Axis 1.2 code
25  */

26 public class PrefixedQName implements Name JavaDoc {
27     /** comment/shared empty string */
28     private static final String JavaDoc emptyString = "".intern();
29     
30     /**
31      * Field prefix
32      */

33     private String JavaDoc prefix;
34     /**
35      * Field qName
36      */

37     private QName JavaDoc qName;
38     
39     /**
40      * Constructor PrefixedQName
41      * @param uri
42      * @param localName
43      * @param pre
44      */

45     public PrefixedQName(String JavaDoc uri, String JavaDoc localName, String JavaDoc pre) {
46         qName = new QName JavaDoc(uri, localName);
47         prefix = (pre == null)
48                             ? emptyString
49                             : pre.intern();
50     }
51
52     /**
53      * Constructor qname
54      * @param qname
55      * @return
56      */

57     public PrefixedQName(QName JavaDoc qname) {
58         this.qName = qname;
59         prefix = emptyString;
60     }
61
62     /**
63      * Method getLocalName
64      * @return
65      */

66     public String JavaDoc getLocalName() {
67         return qName.getLocalPart();
68     }
69     
70     /**
71      * Method getQualifiedName
72      * @return
73      */

74     public String JavaDoc getQualifiedName() {
75         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(prefix);
76         if(prefix != emptyString)
77             buf.append(':');
78         buf.append(qName.getLocalPart());
79         return buf.toString();
80     }
81     
82     /**
83      * Method getURI
84      * @return
85      */

86     public String JavaDoc getURI() {
87         return qName.getNamespaceURI();
88     }
89     
90     /**
91      * Method getPrefix
92      * @return
93      */

94     public String JavaDoc getPrefix() {
95         return prefix;
96     }
97    
98     /**
99      * Method equals
100      * @param obj
101      * @return
102      */

103     public boolean equals(Object JavaDoc obj) {
104         if (obj == this) {
105             return true;
106         }
107         if (!(obj instanceof PrefixedQName)) {
108             return false;
109         }
110         if (!qName.equals(((PrefixedQName)obj).qName)) {
111             return false;
112         }
113         if (prefix == ((PrefixedQName) obj).prefix) {
114             return true;
115         }
116         return false;
117     }
118
119     /**
120      * Method hasCode
121      * @return
122      */

123     public int hashCode() {
124         return prefix.hashCode() + qName.hashCode();
125     }
126     
127     /**
128      * Method toString
129      * @return
130      */

131     public String JavaDoc toString() {
132         return qName.toString();
133     }
134 }
135
Popular Tags