/** * 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; }
/** * 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)); } }