1 57 58 package org.apache.soap.util.xml; 59 60 import org.w3c.dom.Node ; 61 62 68 public class QName implements java.io.Serializable 69 { 70 private String namespaceURI; 71 private String localPart; 72 73 public QName() 74 { 75 } 77 78 public QName(Node node) throws IllegalArgumentException 79 { 80 String namespaceURI = node.getNamespaceURI(); 81 82 if (namespaceURI == null) 83 { 84 throw new IllegalArgumentException ("Can't create QName: NamespaceURI " + 85 "must not be null."); 86 } 87 88 String localPart = node.getLocalName(); 89 90 if (localPart == null) 91 { 92 throw new IllegalArgumentException ("Can't create QName: LocalName " + 93 "must not be null."); 94 } 95 96 setNamespaceURI(namespaceURI); 97 setLocalPart(localPart); 98 } 99 100 public QName(String namespaceURI, String localPart) 101 { 102 setNamespaceURI(namespaceURI); 103 setLocalPart(localPart); 104 } 105 106 public void setNamespaceURI(String namespaceURI) 107 { 108 this.namespaceURI = (namespaceURI == null ? "" : namespaceURI).intern(); 109 } 110 111 public String getNamespaceURI() 112 { 113 return namespaceURI; 114 } 115 116 public void setLocalPart(String localPart) 117 { 118 this.localPart = (localPart == null ? "" : localPart).intern(); 119 } 120 121 public String getLocalPart() 122 { 123 return localPart; 124 } 125 126 public int hashCode() 127 { 128 String hash1 = namespaceURI.hashCode() + ""; 129 String hash2 = localPart.hashCode() + ""; 130 String hash3 = hash1 + '_' + hash2; 131 132 return hash3.hashCode(); 133 } 134 135 public boolean equals(Object obj) 136 { 137 return (obj != null 138 && namespaceURI == ((QName)obj).getNamespaceURI() 139 && localPart == ((QName)obj).getLocalPart()); 140 } 141 142 public boolean matches(Node node) 143 { 144 try 145 { 146 return (node != null && this.equals(new QName(node))); 147 } 148 catch (IllegalArgumentException e) 149 { 150 return false; 151 } 152 } 153 154 public String toString() 155 { 156 return namespaceURI + ':' + localPart; 157 } 158 } 159 | Popular Tags |