001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.saaj;
020:
021: import javax.xml.namespace.QName;
022: import javax.xml.soap.Name;
023:
024: /**
025: * Class Prefixed QName
026: * <p/>
027: * Took this implementation from Axis 1.2 code
028: */
029: public class PrefixedQName implements Name {
030: /** comment/shared empty string */
031: private static final String EMPTY_STRING = "".intern();
032:
033: /** Field prefix */
034: private String prefix;
035: /** Field qName */
036: private QName qName;
037:
038: /**
039: * Constructor PrefixedQName.
040: *
041: * @param uri
042: * @param localName
043: * @param prefix
044: */
045: public PrefixedQName(String uri, String localName, String prefix) {
046: qName = new QName(uri, localName);
047: this .prefix = (prefix == null) ? EMPTY_STRING : prefix.intern();
048: }
049:
050: /**
051: * Constructor PrefixedQName
052: *
053: * @param qname
054: */
055: public PrefixedQName(QName qname) {
056: this .qName = qname;
057: this .prefix = (qname.getPrefix() == null) ? EMPTY_STRING
058: : qname.getPrefix().intern();
059: }
060:
061: /**
062: * Gets the local name part of the XML name that this <code>Name</code> object represents.
063: *
064: * @return Returns the local name.
065: */
066: public String getLocalName() {
067: return qName.getLocalPart();
068: }
069:
070: /**
071: * Gets the namespace-qualified name of the XML name that this <code>Name</code> object
072: * represents.
073: *
074: * @return Returns the namespace-qualified name.
075: */
076: public String getQualifiedName() {
077: StringBuffer buf = new StringBuffer(prefix);
078: if (!prefix.equals(EMPTY_STRING))
079: buf.append(':');
080: buf.append(qName.getLocalPart());
081: return buf.toString();
082: }
083:
084: /**
085: * Returns the URI of the namespace for the XML name that this <code>Name</code> object
086: * represents.
087: *
088: * @return Returns the URI as a string.
089: */
090: public String getURI() {
091: return qName.getNamespaceURI();
092: }
093:
094: /**
095: * Returns the prefix associated with the namespace for the XML name that this <code>Name</code>
096: * object represents.
097: *
098: * @return Returns the prefix as a string.
099: */
100: public String getPrefix() {
101: return prefix;
102: }
103:
104: public boolean equals(Object obj) {
105: if (obj == this ) {
106: return true;
107: }
108: if (!(obj instanceof PrefixedQName)) {
109: return false;
110: }
111: if (!qName.equals(((PrefixedQName) obj).qName)) {
112: return false;
113: }
114: return true;
115: //Is this correct?
116: //return prefix.equals(((PrefixedQName) obj).prefix);
117: }
118:
119: public int hashCode() {
120: return prefix.hashCode() + qName.hashCode();
121: }
122:
123: public String toString() {
124: return qName.toString();
125: }
126: }
|