1 package org.sapia.util.xml; 2 3 4 import java.io.Serializable ; 7 8 9 20 public class Namespace implements Serializable { 21 25 26 private String _theURI; 27 28 29 private String _thePrefix; 30 31 32 private int _theHashCode; 33 34 38 41 public Namespace() { 42 generateHashCode(); 43 } 44 45 51 public Namespace(String anURI, String aPrefix) { 52 _theURI = anURI; 53 _thePrefix = aPrefix; 54 generateHashCode(); 55 } 56 57 61 66 public String getURI() { 67 return _theURI; 68 } 69 70 75 public String getPrefix() { 76 return _thePrefix; 77 } 78 79 83 88 public void setURI(String anURI) { 89 _theURI = anURI; 90 generateHashCode(); 91 } 92 93 98 public void setPrefix(String aPrefix) { 99 _thePrefix = aPrefix; 100 generateHashCode(); 101 } 102 103 106 private void generateHashCode() { 107 StringBuffer aBuffer = new StringBuffer (); 108 aBuffer.append(_theURI).append(_thePrefix); 109 _theHashCode = aBuffer.toString().hashCode(); 110 } 111 112 116 121 public int hashCode() { 122 return _theHashCode; 123 } 124 125 132 public boolean equals(Object anObject) { 133 if (anObject == this) { 134 return true; 135 } else if (!(anObject instanceof Namespace)) { 136 return false; 137 } else { 138 Namespace aNamespace = (Namespace) anObject; 139 140 return ((((_theURI == null) && (aNamespace._theURI == null)) || 141 ((_theURI != null) && (aNamespace._theURI != null) && 142 _theURI.equals(aNamespace._theURI))) && 143 (((_thePrefix == null) && (aNamespace._thePrefix == null)) || 144 ((_thePrefix != null) && (aNamespace._thePrefix != null) && 145 _thePrefix.equals(aNamespace._thePrefix)))); 146 } 147 } 148 149 154 public String toString() { 155 StringBuffer aBuffer = new StringBuffer (super.toString()); 156 aBuffer.append("[uri=").append(_theURI).append(" prefix=").append(_thePrefix) 157 .append("]"); 158 159 return aBuffer.toString(); 160 } 161 } 162 | Popular Tags |