1 16 17 package org.jboss.axis.message; 18 19 import org.jboss.logging.Logger; 20 import org.w3c.dom.DOMException ; 21 import org.w3c.dom.Document ; 22 import org.w3c.dom.NamedNodeMap ; 23 import org.w3c.dom.Node ; 24 import org.w3c.dom.NodeList ; 25 import org.w3c.dom.UserDataHandler ; 26 27 import javax.xml.soap.SOAPElement ; 28 import javax.xml.soap.SOAPException ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 46 public class NodeImpl implements javax.xml.soap.Node 47 { 48 49 private static Logger log = Logger.getLogger(NodeImpl.class.getName()); 51 52 protected SOAPElementImpl soapParent; 54 protected org.w3c.dom.Node domNode; 56 private List soapChildren = new ArrayList (); 58 59 62 NodeImpl(org.w3c.dom.Node node) 63 { 64 if (node.getNodeName().startsWith(":")) 65 throw new IllegalArgumentException ("Illegal node name: " + node.getNodeName()); 66 67 this.domNode = node; 68 } 69 70 72 75 public void detachNode() 76 { 77 assertSOAPParent(); 78 79 org.w3c.dom.Node parent = domNode.getParentNode(); 80 if (parent != null) 81 { 82 83 parent.removeChild(domNode); 84 ((NodeImpl)soapParent).soapChildren.remove(this); 85 86 if (soapParent instanceof SOAPElementAxisImpl) 88 { 89 ((SOAPElementAxisImpl)soapParent).removeChild(this); 90 } 91 92 soapParent = null; 93 } 94 } 95 96 102 public SOAPElement getParentElement() 103 { 104 return soapParent; 105 } 106 107 113 public void setParentElement(SOAPElement parent) throws SOAPException 114 { 115 116 if (soapParent != null) 118 detachNode(); 119 120 soapParent = (SOAPElementImpl)parent; 121 } 122 123 133 public String getValue() 134 { 135 136 if (this instanceof javax.xml.soap.Text ) 139 throw new IllegalStateException ("javax.xml.soap.Text should take care of this"); 140 141 org.w3c.dom.Node child = (org.w3c.dom.Node )getFirstChild(); 142 if (child instanceof org.w3c.dom.Text ) 143 return ((org.w3c.dom.Text )child).getNodeValue(); 144 145 return null; 146 } 147 148 157 public void setValue(String value) 158 { 159 if (this instanceof javax.xml.soap.Text ) 162 throw new IllegalStateException ("javax.xml.soap.Text should take care of this"); 163 164 org.w3c.dom.Node child = (org.w3c.dom.Node )getFirstChild(); 165 if (child instanceof org.w3c.dom.Text ) 166 ((org.w3c.dom.Text )child).setNodeValue(value); 167 168 if (child == null && value != null) 169 { 170 child = domNode.getOwnerDocument().createTextNode(value); 171 appendChild(new TextImpl(child)); 172 } 173 } 174 175 180 public void recycleNode() 181 { 182 183 } 184 185 187 public String getNodeName() 188 { 189 return domNode.getNodeName(); 190 } 191 192 public String getNodeValue() throws DOMException 193 { 194 return domNode.getNodeValue(); 195 } 196 197 public void setNodeValue(String nodeValue) throws DOMException 198 { 199 domNode.setNodeValue(nodeValue); 200 } 201 202 public short getNodeType() 203 { 204 return domNode.getNodeType(); 205 } 206 207 public org.w3c.dom.Node getParentNode() 208 { 209 assertSOAPParent(); 210 return domNode.getParentNode(); 211 } 212 213 public NodeList getChildNodes() 214 { 215 return domNode.getChildNodes(); 216 } 217 218 public org.w3c.dom.Node getFirstChild() 219 { 220 return domNode.getFirstChild(); 221 } 222 223 public org.w3c.dom.Node getLastChild() 224 { 225 return domNode.getLastChild(); 226 } 227 228 public org.w3c.dom.Node getPreviousSibling() 229 { 230 return domNode.getPreviousSibling(); 231 } 232 233 public org.w3c.dom.Node getNextSibling() 234 { 235 return domNode.getNextSibling(); 236 } 237 238 public NamedNodeMap getAttributes() 239 { 240 return domNode.getAttributes(); 241 } 242 243 public Document getOwnerDocument() 244 { 245 return domNode.getOwnerDocument(); 246 } 247 248 public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws DOMException 249 { 250 assertSOAPNode(newChild); 251 assertSOAPNode(refChild); 252 253 int index = soapChildren.indexOf(refChild); 254 if (index < 0) 255 throw new IllegalArgumentException ("Cannot find refChild in list of javax.xml.soap.Node children"); 256 257 NodeImpl soapNewNode = (NodeImpl)newChild; 258 NodeImpl soapRefNode = (NodeImpl)refChild; 259 domNode.insertBefore(soapNewNode.domNode, soapRefNode.domNode); 260 soapChildren.add(index, soapNewNode); 261 262 return newChild; 263 } 264 265 public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild) throws DOMException 266 { 267 assertSOAPNode(newChild); 268 assertSOAPNode(oldChild); 269 270 int index = soapChildren.indexOf(oldChild); 271 if (index < 0) 272 throw new DOMException (DOMException.NOT_FOUND_ERR, "Cannot find oldChild in list of javax.xml.soap.Node children"); 273 274 NodeImpl soapNewNode = (NodeImpl)newChild; 275 NodeImpl soapOldNode = (NodeImpl)oldChild; 276 domNode.replaceChild(soapNewNode.domNode, soapOldNode.domNode); 277 soapChildren.remove(index); 278 soapChildren.add(index, soapNewNode); 279 280 return newChild; 281 } 282 283 public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws DOMException 284 { 285 assertSOAPNode(oldChild); 286 287 int index = soapChildren.indexOf(oldChild); 288 if (index < 0) 289 throw new DOMException (DOMException.NOT_FOUND_ERR, "Cannot find oldChild in list of javax.xml.soap.Node children"); 290 291 NodeImpl soapOldNode = (NodeImpl)oldChild; 292 domNode.removeChild(soapOldNode.domNode); 293 soapChildren.remove(index); 294 295 return oldChild; 296 } 297 298 public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) throws DOMException 299 { 300 assertSOAPNode(newChild); 301 302 if ((this instanceof SOAPElementImpl) == false) 303 throw new DOMException (DOMException.INVALID_ACCESS_ERR, "Cannot append child to this node: " + this); 304 305 NodeImpl soapNode = (NodeImpl)newChild; 306 domNode.appendChild(soapNode.domNode); 307 308 soapNode.soapParent = (SOAPElementImpl)this; 309 soapChildren.add(soapNode); 310 311 return newChild; 312 } 313 314 public boolean hasChildNodes() 315 { 316 return domNode.hasChildNodes(); 317 } 318 319 public org.w3c.dom.Node cloneNode(boolean deep) 320 { 321 322 NodeImpl soapNode = new NodeImpl(domNode.cloneNode(deep)); 323 if (deep == true) 324 { 325 for (int i = 0; i < soapChildren.size(); i++) 326 { 327 NodeImpl node = (NodeImpl)soapChildren.get(i); 328 soapNode.soapChildren.add(node.cloneNode(deep)); 329 } 330 } 331 332 return soapNode; 333 } 334 335 public void normalize() 336 { 337 domNode.normalize(); 338 } 339 340 public boolean isSupported(String feature, String version) 341 { 342 return domNode.isSupported(feature, version); 343 } 344 345 public String getNamespaceURI() 346 { 347 return domNode.getNamespaceURI(); 348 } 349 350 public String getPrefix() 351 { 352 return domNode.getPrefix(); 353 } 354 355 public void setPrefix(String prefix) throws DOMException 356 { 357 domNode.setPrefix(prefix); 358 } 359 360 public String getLocalName() 361 { 362 return domNode.getLocalName(); 363 } 364 365 public boolean hasAttributes() 366 { 367 return domNode.hasAttributes(); 368 } 369 370 public int hashCode() 371 { 372 return domNode.hashCode(); 373 } 374 375 public String toString() 376 { 377 return super.toString() + "[" + domNode.toString() + "]"; 378 } 379 380 private void assertSOAPNode(org.w3c.dom.Node node) 381 { 382 if ((node instanceof NodeImpl) == false) 383 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, "Operation only supported for javax.xml.soap.Node, this is a " + node); 384 } 385 386 private void assertSOAPParent() 387 { 388 org.w3c.dom.Node domParent = domNode.getParentNode(); 389 if (domParent != null && soapParent == null) 390 throw new IllegalStateException ("Inconsistent node, has a DOM parent but no SOAP parent: " + this); 391 if (domParent == null && soapParent != null) 392 throw new IllegalStateException ("Inconsistent node, has a SOAP parent but no DOM parent: " + this); 393 } 394 395 public String getBaseURI() 397 { 398 return null; 399 } 400 401 public short compareDocumentPosition(Node other) throws DOMException 402 { 403 return 0; 404 } 405 406 public String getTextContent() throws DOMException 407 { 408 return null; 409 } 410 411 public void setTextContent(String textContent) throws DOMException 412 { 413 414 } 415 416 public boolean isSameNode(Node other) 417 { 418 return false; 419 } 420 421 public String lookupPrefix(String namespaceURI) 422 { 423 return null; 424 } 425 426 public boolean isDefaultNamespace(String namespaceURI) 427 { 428 return false; 429 } 430 431 public String lookupNamespaceURI(String prefix) 432 { 433 return null; 434 } 435 436 public boolean isEqualNode(Node arg) 437 { 438 return false; 439 } 440 441 public Object getFeature(String feature, String version) 442 { 443 return null; 444 } 445 446 public Object setUserData(String key, Object data, UserDataHandler handler) 447 { 448 return null; 449 } 450 451 public Object getUserData(String key) 452 { 453 return null; 454 } 455 } 457 | Popular Tags |