📄 nodeimpl.java
字号:
* @param doc */ public void setOwnerDocument(Document doc) { document = doc; } /** * The <code>Document</code> object associated with this node. This is * also the <code>Document</code> object used to create new nodes. When * this node is a <code>Document</code> or a <code>DocumentType</code> * which is not used with any <code>Document</code> yet, this is * <code>null</code>. */ public Document getOwnerDocument() { if(document == null) { NodeImpl node = getParent(); if (node != null) { return node.getOwnerDocument(); } } return document; } /** * A <code>NamedNodeMap</code> containing the attributes of this node (if * it is an <code>Element</code>) or <code>null</code> otherwise. */ public NamedNodeMap getAttributes() { // make first it is editable. makeAttributesEditable(); return convertAttrSAXtoDOM(attributes); } /** * The first child of this node. If there is no such node, this returns * <code>null</code>. */ public Node getFirstChild() { if (children != null && !children.isEmpty()) { return (Node) children.get(0); } else { return null; } } /** * The last child of this node. If there is no such node, this returns * <code>null</code>. */ public Node getLastChild() { if (children != null && !children.isEmpty()) { return (Node) children.get(children.size() - 1); } else { return null; } } /** * The node immediately following this node. If there is no such node, * this returns <code>null</code>. */ public Node getNextSibling() { SOAPElement parent = getParentElement(); if (parent == null) { return null; } Iterator iter = parent.getChildElements(); Node nextSibling = null; while (iter.hasNext()) { if (iter.next() == this) { if (iter.hasNext()) { return (Node) iter.next(); } else { return null; } } } return nextSibling; // should be null. } /** * The parent of this node. All nodes, except <code>Attr</code>, * <code>Document</code>, <code>DocumentFragment</code>, * <code>Entity</code>, and <code>Notation</code> may have a parent. * However, if a node has just been created and not yet added to the * tree, or if it has been removed from the tree, this is * <code>null</code>. */ public Node getParentNode() { return (Node) getParent(); } /** * The node immediately preceding this node. If there is no such node, * this returns <code>null</code>. */ public Node getPreviousSibling() { SOAPElement parent = getParentElement(); if (parent == null) { return null; } NodeList nl = parent.getChildNodes(); int len = nl.getLength(); int i = 0; Node previousSibling = null; while (i < len) { if (nl.item(i) == this) { return previousSibling; } previousSibling = nl.item(i); i++; } return previousSibling; // should be null. } /** * Returns a duplicate of this node, i.e., serves as a generic copy * constructor for nodes. The duplicate node has no parent; ( * <code>parentNode</code> is <code>null</code>.). * <br>Cloning an <code>Element</code> copies all attributes and their * values, including those generated by the XML processor to represent * defaulted attributes, but this method does not copy any text it * contains unless it is a deep clone, since the text is contained in a * child <code>Text</code> node. Cloning an <code>Attribute</code> * directly, as opposed to be cloned as part of an <code>Element</code> * cloning operation, returns a specified attribute ( * <code>specified</code> is <code>true</code>). Cloning any other type * of node simply returns a copy of this node. * <br>Note that cloning an immutable subtree results in a mutable copy, * but the children of an <code>EntityReference</code> clone are readonly * . In addition, clones of unspecified <code>Attr</code> nodes are * specified. And, cloning <code>Document</code>, * <code>DocumentType</code>, <code>Entity</code>, and * <code>Notation</code> nodes is implementation dependent. * * @param deep If <code>true</code>, recursively clone the subtree under * the specified node; if <code>false</code>, clone only the node * itself (and its attributes, if it is an <code>Element</code>). * @return The duplicate node. */ public Node cloneNode(boolean deep) { return new NodeImpl(textRep); } /** * A <code>NodeList</code> that contains all children of this node. If * there are no children, this is a <code>NodeList</code> containing no * nodes. */ public NodeList getChildNodes() { if (children == null) { return NodeListImpl.EMPTY_NODELIST; } else { return new NodeListImpl(children); } } /** * Tests whether the DOM implementation implements a specific feature and * that feature is supported by this node. * * @param feature The name of the feature to test. This is the same name * which can be passed to the method <code>hasFeature</code> on * <code>DOMImplementation</code>. * @param version This is the version number of the feature to test. In * Level 2, version 1, this is the string "2.0". If the version is not * specified, supporting any version of the feature will cause the * method to return <code>true</code>. * @return Returns <code>true</code> if the specified feature is * supported on this node, <code>false</code> otherwise. * @since DOM Level 2 */ public boolean isSupported(String feature, String version) { return false; //TODO: Fix this for SAAJ 1.2 Implementation } /** * Adds the node <code>newChild</code> to the end of the list of children * of this node. If the <code>newChild</code> is already in the tree, it * is first removed. * * @param newChild The node to add.If it is a * <code>DocumentFragment</code> object, the entire contents of the * document fragment are moved into the child list of this node * @return The node added. * @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 append 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 is readonly or * if the previous parent of the node being inserted is readonly. * */ public Node appendChild(Node newChild) throws DOMException { if (newChild == null) { throw new DOMException (DOMException.HIERARCHY_REQUEST_ERR, "Can't append a null node."); } initializeChildren(); // per DOM spec - must remove from tree. If newChild.parent == null, // detachNode() does nothing. So this shouldn't hurt performace of // serializers. ((NodeImpl) newChild).detachNode(); children.add(newChild); ((NodeImpl) newChild).parent = this; setDirty(); return newChild; } /** * Removes the child node indicated by <code>oldChild</code> from the list * of children, and returns it. * * @param oldChild The node being removed. * @return The node removed. * @throws org.w3c.dom.DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of * this node. */ public Node removeChild(Node oldChild) throws DOMException { if (removeNodeFromChildList((NodeImpl) oldChild)) { setDirty(); return oldChild; } throw new DOMException(DOMException.NOT_FOUND_ERR, "NodeImpl Not found"); } private boolean removeNodeFromChildList(NodeImpl n) { boolean removed = false; initializeChildren(); final Iterator itr = children.iterator(); while (itr.hasNext()) { final NodeImpl node = (NodeImpl) itr.next(); if (node == n) { removed = true; itr.remove(); } } return removed; } /** * Inserts the node <code>newChild</code> before the existing child node * <code>refChild</code>. If <code>refChild</code> is <code>null</code>, * insert <code>newChild</code> at the end of the list of children. * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object, * all of its children are inserted, in the same order, before * <code>refChild</code>. If the <code>newChild</code> is already in the * tree, it is first removed. * * @param newChild The node to insert. * @param refChild The reference node, i.e., the node before which the * new node must be inserted. * @return The node being inserted. * @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 insert 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 is readonly or * if the parent of the node being inserted is readonly. * <br>NOT_FOUND_ERR: Raised if <code>refChild</code> is not a child of * this node. */ public Node insertBefore(Node newChild, Node refChild) throws DOMException { initializeChildren(); int position = children.indexOf(refChild); if (position < 0) { position = 0; } children.add(position, newChild); setDirty(); return newChild; } /** * Replaces the child node <code>oldChild</code> with <code>newChild</code> * in the list of children, and returns the <code>oldChild</code> node. * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object, * <code>oldChild</code> is replaced by all of the * <code>DocumentFragment</code> children, which are inserted in the * same order. If the <code>newChild</code> is already in the tree, it
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -