1 17 package org.apache.ws.jaxme.xs.xml; 18 19 20 24 public class XsQName { 25 private final String namespaceURI; 26 private final String localName; 27 private final String prefix; 28 29 public XsQName(XsAnyURI pNamespaceURI, String pLocalName) { 30 this(pNamespaceURI == null ? null : pNamespaceURI.getURI(), pLocalName, null); 31 } 32 33 public XsQName(XsAnyURI pNamespaceURI, String pLocalName, String pPrefix) { 34 this(pNamespaceURI == null ? null : pNamespaceURI.getURI(), pLocalName, pPrefix); 35 } 36 37 public XsQName(String pNamespaceURI, String pLocalName) { 38 this(pNamespaceURI, pLocalName, null); 39 } 40 41 public XsQName(String pNamespaceURI, String pLocalName, String pPrefix) { 42 namespaceURI = (pNamespaceURI == null) ? "" : pNamespaceURI; 43 if (pLocalName == null) { 44 throw new NullPointerException ("The localName must not be null."); 45 } 46 int offset = pLocalName.indexOf(':'); 47 if (offset >= 0) { 48 throw new IllegalArgumentException ("The localName " + pLocalName + 49 " is invalid, because it contains a namespace prefix."); 50 } 51 localName = pLocalName; 52 prefix = pPrefix; 53 } 54 55 public String getNamespaceURI() { return namespaceURI; } 56 public String getLocalName() { return localName; } 57 public String getPrefix() { return prefix; } 58 59 public boolean equals(Object pObject) { 60 if (pObject == null || !(pObject instanceof XsQName)) { 61 return false; 62 } 63 XsQName name = (XsQName) pObject; 64 return name.getNamespaceURI().equals(getNamespaceURI()) 65 && name.getLocalName().equals(getLocalName()); 66 } 67 68 public int hashCode() { 69 return getNamespaceURI().hashCode() + getLocalName().hashCode(); 70 } 71 72 public String toString() { 73 if ("".equals(namespaceURI)) { return localName; } 74 return "{" + namespaceURI + "}" + localName; 75 } 76 77 public static String prefixOf(String pQName) { 78 int offset = pQName.indexOf(':'); 79 if (offset > 0) { 80 return pQName.substring(0, offset); 81 } else { 82 return ""; 83 } 84 } 85 } 86 | Popular Tags |