📄 nodeimpl.java
字号:
* is first removed. * * @param newChild The new node to put in the child list. * @param oldChild The node being replaced in the list. * @return The node replaced. * @throws org.w3c.dom.DOMException HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not * allow children of the type of the <code>newChild</code> node, or if * the node to put in is one of this node's ancestors or this node * itself. * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created * from a different document than the one that created this node. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of * the new node is readonly. * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of * this node. */ public Node replaceChild(Node newChild, Node oldChild) throws DOMException { initializeChildren(); int position = children.indexOf(oldChild); if (position < 0) { throw new DOMException(DOMException.NOT_FOUND_ERR, "NodeImpl Not found"); } children.remove(position); children.add(position, newChild); setDirty(); return oldChild; } /** * Returns the the value of the immediate child of this <code>Node</code> * object if a child exists and its value is text. * * @return a <code>String</code> with the text of the immediate child of * this <code>Node</code> object if (1) there is a child and * (2) the child is a <code>Text</code> object; * <code>null</code> otherwise */ public String getValue() { return textRep.getNodeValue(); } /** * Sets the parent of this <code>Node</code> object to the given * <code>SOAPElement</code> object. * * @param parent the <code>SOAPElement</code> object to be set as * the parent of this <code>Node</code> object * @throws javax.xml.soap.SOAPException if there is a problem in setting the * parent to the given element * @see #getParentElement() getParentElement() */ public void setParentElement(SOAPElement parent) throws SOAPException { if (parent == null) throw new IllegalArgumentException( Messages.getMessage("nullParent00")); try { setParent((NodeImpl) parent); } catch (Throwable t) { throw new SOAPException(t); } } /** * Returns the parent element of this <code>Node</code> object. * This method can throw an <code>UnsupportedOperationException</code> * if the tree is not kept in memory. * * @return the <code>SOAPElement</code> object that is the parent of * this <code>Node</code> object or <code>null</code> if this * <code>Node</code> object is root * @throws UnsupportedOperationException if the whole tree is not kept in memory * @see #setParentElement(javax.xml.soap.SOAPElement) setParentElement(javax.xml.soap.SOAPElement) */ public SOAPElement getParentElement() { return (SOAPElement) getParent(); } /** * Removes this <code>Node</code> object from the tree. Once * removed, this node can be garbage collected if there are no * application references to it. */ public void detachNode() { setDirty(); if (parent != null) { parent.removeChild(this); parent = null; } } /** * Notifies the implementation that this <code>Node</code> * object is no longer being used by the application and that the * implementation is free to reuse this object for nodes that may * be created later. * <P> * Calling the method <code>recycleNode</code> implies that the method * <code>detachNode</code> has been called previously. */ public void recycleNode() { //TODO: Fix this for SAAJ 1.2 Implementation } /** * 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. 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 the text to set * @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) { if (this instanceof org.apache.axis.message.Text) { setNodeValue(value); } else if (children != null) { if (children.size() != 1) { throw new IllegalStateException( "setValue() may not be called on a non-Text node with more than one child." ); } javax.xml.soap.Node child = (javax.xml.soap.Node) children.get(0); if (!(child instanceof org.apache.axis.message.Text)) { throw new IllegalStateException( "setValue() may not be called on a non-Text node with a non-Text child." ); } ((javax.xml.soap.Text)child).setNodeValue(value); } else { appendChild(new org.apache.axis.message.Text(value)); } } /** * make the attributes editable * * @return AttributesImpl */ protected AttributesImpl makeAttributesEditable() { if (attributes == null || attributes instanceof NullAttributes) { attributes = new AttributesImpl(); } else if (!(attributes instanceof AttributesImpl)) { attributes = new AttributesImpl(attributes); } return (AttributesImpl) attributes; } /** * The internal representation of Attributes cannot help being changed * It is because Attribute is not immutible Type, so if we keep out value and * just return it in another form, the application may chnae it, which we cannot * detect without some kind back track method (call back notifying the chnage.) * I am not sure which approach is better. */ protected NamedNodeMap convertAttrSAXtoDOM(Attributes saxAttr) { try { org.w3c.dom.Document doc = org.apache.axis.utils.XMLUtils.newDocument(); AttributesImpl saxAttrs = (AttributesImpl) saxAttr; NamedNodeMap domAttributes = new NamedNodeMapImpl(); for (int i = 0; i < saxAttrs.getLength(); i++) { String uri = saxAttrs.getURI(i); String qname = saxAttrs.getQName(i); String value = saxAttrs.getValue(i); if (uri != null && uri.trim().length() > 0) { // filterring out the tricky method to differentiate the null namespace // -ware case if (NULL_URI_NAME.equals(uri)) { uri = null; } Attr attr = doc.createAttributeNS(uri, qname); attr.setValue(value); domAttributes.setNamedItemNS(attr); } else { Attr attr = doc.createAttribute(qname); attr.setValue(value); domAttributes.setNamedItem(attr); } } return domAttributes; } catch (Exception ex) { log.error(Messages.getMessage("saxToDomFailed00"),ex); return null; } } /** * Initialize the children array */ protected void initializeChildren() { if (children == null) { children = new ArrayList(); } } /** * get the parent node * @return parent node */ protected NodeImpl getParent() { return parent; } /** * Set the parent node and invoke appendChild(this) to * add this node to the parent's list of children. * @param parent * @throws SOAPException */ protected void setParent(NodeImpl parent) throws SOAPException { if (this.parent == parent) { return; } if (this.parent != null) { this.parent.removeChild(this); } if (parent != null) { parent.appendChild(this); } this.setDirty(); this.parent = parent; } /** * print the contents of this node * @param context * @throws Exception */ public void output(SerializationContext context) throws Exception { if (textRep == null) return; boolean oldPretty = context.getPretty(); context.setPretty(false); if (textRep instanceof CDATASection) { context.writeString("<![CDATA["); context.writeString(((org.w3c.dom.Text) textRep).getData()); context.writeString("]]>"); } else if (textRep instanceof Comment) { context.writeString("<!--"); context.writeString(((CharacterData) textRep).getData()); context.writeString("-->"); } else if (textRep instanceof Text) { context.writeSafeString(((Text) textRep).getData()); } context.setPretty(oldPretty); } /** * get the dirty bit * @return */ public boolean isDirty() { return _isDirty; } /** * set the dirty bit. will also set our parent as dirty, if there is one. * Note that clearing the dirty bit does <i>not</i> propagate upwards. * @param dirty new value of the dirty bit */ public void setDirty(boolean dirty) { _isDirty = dirty; if (_isDirty && parent != null) { ((NodeImpl) parent).setDirty(); } } public void setDirty() { _isDirty = true; if (parent != null) { ((NodeImpl) parent).setDirty(); } } /* clear dirty flag recursively */ public void reset() { if (children != null) { for (int i=0; i<children.size(); i++) { ((NodeImpl) children.get(i)).reset(); } } this._isDirty = false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -