2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
20
package org.apache.xmlgraphics.util;
22
import java.io.Serializable;
25
* Represents a qualified name of an XML element or an XML attribute.
27
* Note: This class allows to carry a namespace prefix but it is not used in the equals() and
30
public class QName implements Serializable {
32
private static final long serialVersionUID = -5225376740044770690L;
34
private String namespaceURI;
35
private String localName;
36
private String prefix;
41
* @param namespaceURI the namespace URI
42
* @param prefix the namespace prefix, may be null
43
* @param localName the local name
45
public QName(String namespaceURI, String prefix, String localName) {
46
if (localName == null) {
47
throw new NullPointerException("Parameter localName must not be null");
49
if (localName.length() == 0) {
50
throw new IllegalArgumentException("Parameter localName must not be empty");
52
this.namespaceURI = namespaceURI;
54
this.localName = localName;
55
this.hashCode = toHashString().hashCode();
60
* @param namespaceURI the namespace URI
61
* @param qName the qualified name
63
public QName(String namespaceURI, String qName) {
65
throw new NullPointerException("Parameter localName must not be null");
67
if (qName.length() == 0) {
68
throw new IllegalArgumentException("Parameter localName must not be empty");
70
this.namespaceURI = namespaceURI;
71
int p = qName.indexOf(':');
73
this.prefix = qName.substring(0, p);
74
this.localName = qName.substring(p + 1);
77
this.localName = qName;
79
this.hashCode = toHashString().hashCode();
82
/** @return the namespace URI */
83
public String getNamespaceURI() {
84
return this.namespaceURI;
87
/** @return the namespace prefix */
88
public String getPrefix() {
92
/** @return the local name */
93
public String getLocalName() {
94
return this.localName;
97
/** @return the fully qualified name */
98
public String getQName() {
99
return getPrefix() != null ? getPrefix() + ':' + getLocalName() : getLocalName();
102
/** @see java.lang.Object#hashCode() */
103
public int hashCode() {
104
return this.hashCode;
107
/** @see java.lang.Object#equals(java.lang.Object) */
108
public boolean equals(Object obj) {
111
} else if (obj == this) {
114
if (obj instanceof QName) {
115
QName other = (QName)obj;
116
if ((getNamespaceURI() == null && other.getNamespaceURI() == null)
117
|| getNamespaceURI().equals(other.getNamespaceURI())) {
118
return getLocalName().equals(other.getLocalName());
125
/** @see java.lang.Object#toString() */
126
public String toString() {
127
return prefix != null
128
? (prefix + ":" + localName)
132
private String toHashString() {
133
return (namespaceURI != null
134
? ("{" + namespaceURI + "}" + localName)
2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
/* $Id: QName.java 750418 2009-03-05 11:03:54Z vhennebert $ */
20
package org.apache.xmlgraphics.util;
22
import java.io.Serializable;
25
* Represents a qualified name of an XML element or an XML attribute.
27
* Note: This class allows to carry a namespace prefix but it is not used in the equals() and
30
public class QName implements Serializable {
32
private static final long serialVersionUID = -5225376740044770690L;
34
private String namespaceURI;
35
private String localName;
36
private String prefix;
41
* @param namespaceURI the namespace URI
42
* @param prefix the namespace prefix, may be null
43
* @param localName the local name
45
public QName(String namespaceURI, String prefix, String localName) {
46
if (localName == null) {
47
throw new NullPointerException("Parameter localName must not be null");
49
if (localName.length() == 0) {
50
throw new IllegalArgumentException("Parameter localName must not be empty");
52
this.namespaceURI = namespaceURI;
54
this.localName = localName;
55
this.hashCode = toHashString().hashCode();
60
* @param namespaceURI the namespace URI
61
* @param qName the qualified name
63
public QName(String namespaceURI, String qName) {
65
throw new NullPointerException("Parameter localName must not be null");
67
if (qName.length() == 0) {
68
throw new IllegalArgumentException("Parameter localName must not be empty");
70
this.namespaceURI = namespaceURI;
71
int p = qName.indexOf(':');
73
this.prefix = qName.substring(0, p);
74
this.localName = qName.substring(p + 1);
77
this.localName = qName;
79
this.hashCode = toHashString().hashCode();
82
/** @return the namespace URI */
83
public String getNamespaceURI() {
84
return this.namespaceURI;
87
/** @return the namespace prefix */
88
public String getPrefix() {
92
/** @return the local name */
93
public String getLocalName() {
94
return this.localName;
97
/** @return the fully qualified name */
98
public String getQName() {
99
return getPrefix() != null ? getPrefix() + ':' + getLocalName() : getLocalName();
102
/** @see java.lang.Object#hashCode() */
103
public int hashCode() {
104
return this.hashCode;
107
/** @see java.lang.Object#equals(java.lang.Object) */
108
public boolean equals(Object obj) {
111
} else if (obj == this) {
114
if (obj instanceof QName) {
115
QName other = (QName)obj;
116
if ((getNamespaceURI() == null && other.getNamespaceURI() == null)
117
|| getNamespaceURI().equals(other.getNamespaceURI())) {
118
return getLocalName().equals(other.getLocalName());
125
/** @see java.lang.Object#toString() */
126
public String toString() {
127
return prefix != null
128
? (prefix + ":" + localName)
132
private String toHashString() {
133
return (namespaceURI != null
134
? ("{" + namespaceURI + "}" + localName)