1 9 10 package org.ozoneDB.xml.dom4j.o3impl; 11 12 import org.dom4j.Element; 13 import org.dom4j.Namespace; 14 import org.dom4j.Node; 15 import org.dom4j.Visitor; 16 17 22 public class AbstractNamespace extends AbstractNode implements Namespace { 23 24 25 27 28 30 31 33 34 35 private String prefix; 36 37 38 private String uri; 39 40 41 private int hashCode; 42 43 44 49 53 58 62 65 public AbstractNamespace(String prefix, String uri) { 66 this.prefix = (prefix != null) ? prefix : ""; 67 this.uri = (uri != null) ? uri : ""; 68 ; 69 } 70 71 72 public short getNodeType() { 73 return NAMESPACE_NODE; 74 } 75 76 79 public int hashCode() { 80 if (hashCode == 0) { 81 hashCode = createHashCode(); 82 } 83 return hashCode; 84 } 85 86 87 protected int createHashCode() { 88 int hashCode = uri.hashCode() ^ prefix.hashCode(); 89 if (hashCode == 0) { 90 hashCode = 0xbabe; 91 } 92 return hashCode; 93 } 94 95 96 public boolean equals(Object object) { 97 if (this == object) { 98 return true; 99 } else if (object instanceof Namespace) { 100 Namespace that = (Namespace) object; 101 102 if (hashCode() == that.hashCode()) { 104 return uri.equals(that.getURI()) 105 && prefix.equals(that.getPrefix()); 106 } 107 } 108 return false; 109 } 110 111 public String getText() { 112 return uri; 113 } 114 115 public String getStringValue() { 116 return uri; 117 } 118 119 121 public String getPrefix() { 122 return prefix; 123 } 124 125 127 public String getURI() { 128 return uri; 129 } 130 131 132 public String getXPathNameStep() { 133 if (prefix != null && !"".equals(prefix)) { 134 return "namespace::" + prefix; 135 } 136 return "namespace::*[name()='']"; 137 } 138 139 public String getPath(Element context) { 140 StringBuffer path = new StringBuffer (10); 141 Element parent = getParent(); 142 if (parent != null && parent != context) { 143 path.append(parent.getPath(context)); 144 path.append('/'); 145 } 146 path.append(getXPathNameStep()); 147 return path.toString(); 148 } 149 150 public String getUniquePath(Element context) { 151 StringBuffer path = new StringBuffer (10); 152 Element parent = getParent(); 153 if (parent != null && parent != context) { 154 path.append(parent.getUniquePath(context)); 155 path.append('/'); 156 } 157 path.append(getXPathNameStep()); 158 return path.toString(); 159 } 160 161 public String toString() { 162 return super.toString() + " [AbstractNamespace: prefix " + getPrefix() 163 + " mapped to URI \"" + getURI() + "\"]"; 164 } 165 166 public String asXML() { 167 StringBuffer asxml = new StringBuffer (10); 168 String prefix = getPrefix(); 169 if (prefix != null && prefix.length() > 0) { 170 asxml.append("xmlns:"); 171 asxml.append(prefix); 172 asxml.append("=\""); 173 } else { 174 asxml.append("xmlns=\""); 175 } 176 asxml.append(getURI()); 177 asxml.append("\""); 178 return asxml.toString(); 179 } 180 181 public void accept(Visitor visitor) { 182 visitor.visit(this); 183 } 184 185 protected Node createXPathResult(Element parent) { 186 return new org.dom4j.tree.DefaultNamespace(parent, getPrefix(), getURI()); 187 } 188 189 } 190 191 192 236 | Popular Tags |