public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) throws DOMException { newChild = convertDOMNode(newChild); if (newChild instanceof DocumentFragment) { List<NodeImpl> list = convertDocumentFragment((DocumentFragment)newChild); for (NodeImpl node : list) { appendChild(node); } return newChild; } if ((this instanceof SOAPElementImpl) == false) throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Cannot append child to this node: " + this); NodeImpl soapNode = (NodeImpl)newChild; soapNode.detachNode(); domNode.appendChild(soapNode.domNode); soapNode.soapParent = (SOAPElementImpl)this; soapChildren.add(soapNode); return newChild; }
public org.w3c.dom.Node getParentNode() { assertSOAPParent(); return soapParent; }
public void setTextContent(String textContent) throws DOMException { NodeList nodes = getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { removeChild((Node)nodes.item(i)); } if (textContent != null && textContent.length() > 0) { Node node = domNode.getOwnerDocument().createTextNode(textContent); appendChild(node); } }
public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild) throws DOMException { newChild = convertDOMNode(newChild); oldChild = convertDOMNode(oldChild); if (newChild instanceof DocumentFragment) { insertBefore(newChild, oldChild); ((NodeImpl)oldChild).detachNode(); return newChild; } int index = soapChildren.indexOf(oldChild); if (index < 0) throw new DOMException(DOMException.NOT_FOUND_ERR, "Cannot find oldChild in list of javax.xml.soap.Node children"); NodeImpl soapNewNode = (NodeImpl)newChild; NodeImpl soapOldNode = (NodeImpl)oldChild; soapNewNode.detachNode(); if (soapNewNode.domNode != soapOldNode.domNode) domNode.replaceChild(soapNewNode.domNode, soapOldNode.domNode); soapChildren.remove(index); soapChildren.add(index, soapNewNode); soapNewNode.soapParent = soapOldNode.soapParent; soapOldNode.soapParent = null; return newChild; }
/** * If this is a Text node then this method will set its value, otherwise it sets the value of the immediate (Text) child of this node. * <p/> * The value of the immediate child of this node can be set only if, there is one child node and * that node is a Text node, or if there are no children in which case a child Text node will be created. * * @param value A value string * @throws IllegalStateException if the node is not a Text node and either has more than one child node or has a child node that is not a Text node. */ public void setValue(String value) { // The Text node should overwrite setValue if (this instanceof javax.xml.soap.Text) throw new WSException(BundleUtils.getMessage(bundle, "IS_NOT_TEXT")); org.w3c.dom.Node child = (org.w3c.dom.Node)getFirstChild(); if (child instanceof org.w3c.dom.Text) ((org.w3c.dom.Text)child).setNodeValue(value); if (child == null) { child = domNode.getOwnerDocument().createTextNode(value); appendChild(new TextImpl(child)); } }
@Override public void setPrefix(String prefix) throws DOMException { super.setPrefix(prefix); elementName = null; }
/** * Sets the parent of this Node object to the given SOAPElement object. * * @param parent the SOAPElement object to be set as the parent of this Node object * @throws javax.xml.soap.SOAPException if there is a problem in setting the parent to the given node */ public void setParentElement(SOAPElement parent) throws SOAPException { // detach from the old parent if (soapParent != null) detachNode(); soapParent = (SOAPElementImpl)parent; }
public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws DOMException { oldChild = convertDOMNode(oldChild); int index = soapChildren.indexOf(oldChild); if (index < 0) throw new DOMException(DOMException.NOT_FOUND_ERR, "Cannot find oldChild in list of javax.xml.soap.Node children"); NodeImpl soapOldNode = (NodeImpl)oldChild; domNode.removeChild(soapOldNode.domNode); soapChildren.remove(index); soapOldNode.soapParent = null; return oldChild; }
/** * Returns the value of this node if this is a Text node or the value of the immediate child of this node otherwise. * <p/> * If there is an immediate child of this Node that it is a Text node then it's value will be returned. * If there is more than one Text node then the value of the first Text Node will be returned. * Otherwise null is returned. * * @return a String with the text of this node if this is a Text node or the text contained by the first immediate * child of this Node object that is a Text object if such a child exists; null otherwise. */ public String getValue() { // The Text node should overwrite getValue if (this instanceof javax.xml.soap.Text) throw new WSException(BundleUtils.getMessage(bundle, "IS_NOT_TEXT")); String nodeValue = null; org.w3c.dom.Node child = (org.w3c.dom.Node)getFirstChild(); if (child instanceof org.w3c.dom.Text) nodeValue = ((org.w3c.dom.Text)child).getNodeValue(); return nodeValue; }
public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws DOMException { // DOM says that if refChild is null, an append is performed if (refChild == null) return appendChild(newChild); newChild = convertDOMNode(newChild); refChild = convertDOMNode(refChild); if (newChild instanceof DocumentFragment) { List<NodeImpl> list = convertDocumentFragment((DocumentFragment)newChild); for (NodeImpl node : list) { insertBefore(node, refChild); } return newChild; } int index = soapChildren.indexOf(refChild); if (index < 0) throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "CANNOT_FIND_REFCHILD")); NodeImpl soapNewNode = (NodeImpl)newChild; soapNewNode.detachNode(); NodeImpl soapRefNode = (NodeImpl)refChild; domNode.insertBefore(soapNewNode.domNode, soapRefNode.domNode); soapChildren.add(index, soapNewNode); soapNewNode.soapParent = (SOAPElementImpl)this; return newChild; }
public org.w3c.dom.Node getPreviousSibling() { assertSOAPParent(); NodeImpl sibling = null; if (soapParent != null) { List children = ((NodeImpl)soapParent).soapChildren; int len = children.size(); for (int i = 0; i < len; i++) { NodeImpl node = (NodeImpl)children.get(i); if (node == this && i > 0) { sibling = (NodeImpl)children.get(i - 1); break; } } if (sibling != null && sibling.domNode != domNode.getPreviousSibling()) throw new WSException(BundleUtils.getMessage(bundle, "INCONSISTENT_NODE")); } return sibling; }
public org.w3c.dom.Node getNextSibling() { assertSOAPParent(); NodeImpl sibling = null; if (soapParent != null) { List children = ((NodeImpl)soapParent).soapChildren; int len = children.size(); for (int i = 0; i < len; i++) { NodeImpl node = (NodeImpl)children.get(i); if (node == this && (i + 1) < len) { sibling = (NodeImpl)children.get(i + 1); break; } } if (sibling != null && sibling.domNode != domNode.getNextSibling()) throw new WSException(BundleUtils.getMessage(bundle, "INCONSISTENT_NODE")); } return sibling; }