1 19 20 package org.netbeans.modules.schema2beans; 21 22 31 public class QName { 32 private String namespaceURI; 33 private String localPart; 34 private String prefix; 35 36 public QName(String localPart) { 37 this("", localPart, ""); 38 } 39 40 public QName(String namespaceURI, String localPart) { 41 this(namespaceURI, localPart, ""); 42 } 43 44 public QName(String namespaceURI, String localPart, String prefix) { 45 if (namespaceURI == null) 46 namespaceURI = ""; 47 this.namespaceURI = namespaceURI; 48 if (localPart == null) 49 throw new IllegalArgumentException ("localPart == null"); 50 this.localPart = localPart; 51 this.prefix = prefix; 52 } 53 54 public String getNamespaceURI() { 55 return namespaceURI; 56 } 57 58 public String getLocalPart() { 59 return localPart; 60 } 61 62 public String getPrefix() { 63 return prefix; 64 } 65 66 public boolean equals(Object o) { 67 if (o == this) 68 return true; 69 if (!(o instanceof QName)) 70 return false; 71 QName q = (QName) o; 72 if (!namespaceURI.equals(q.namespaceURI)) 73 return false; 74 if (!localPart.equals(q.localPart)) 75 return false; 76 return true; 77 } 78 79 public int hashCode() { 80 int result = 17; 81 result = 37*result + namespaceURI.hashCode(); 82 result = 37*result + localPart.hashCode(); 83 return result; 84 } 85 86 public String toString() { 87 if ("".equals(namespaceURI)) 88 return localPart; 89 else 90 return "{"+namespaceURI+"}"+localPart; 91 } 92 93 public static QName valueOf(String asString) { 94 int pos = asString.indexOf('}'); 95 if (pos < 0) { 96 return new QName(asString); 97 } else { 98 String ns = asString.substring(1, pos-1); 99 String localPart = asString.substring(pos+1, asString.length()); 100 return new QName(ns, localPart); 101 } 102 } 103 } 104 | Popular Tags |