nodeimpl.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,697 行 · 第 1/5 页
JAVA
1,697 行
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.apache.org. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package com.sun.org.apache.xerces.internal.dom;import java.io.IOException;import java.io.ObjectOutputStream;import java.io.Serializable;import java.util.Hashtable;import org.w3c.dom.UserDataHandler;import org.w3c.dom.DOMException;import org.w3c.dom.Document;import org.w3c.dom.DocumentType;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.w3c.dom.events.Event;import org.w3c.dom.events.EventListener;import org.w3c.dom.events.EventTarget;/** * NodeImpl provides the basic structure of a DOM tree. It is never used * directly, but instead is subclassed to add type and data * information, and additional methods, appropriate to each node of * the tree. Only its subclasses should be instantiated -- and those, * with the exception of Document itself, only through a specific * Document's factory methods. * <P> * The Node interface provides shared behaviors such as siblings and * children, both for consistancy and so that the most common tree * operations may be performed without constantly having to downcast * to specific node types. When there is no obvious mapping for one of * these queries, it will respond with null. * Note that the default behavior is that children are forbidden. To * permit them, the subclass ParentNode overrides several methods. * <P> * NodeImpl also implements NodeList, so it can return itself in * response to the getChildNodes() query. This eliminiates the need * for a separate ChildNodeList object. Note that this is an * IMPLEMENTATION DETAIL; applications should _never_ assume that * this identity exists. * <P> * All nodes in a single document must originate * in that document. (Note that this is much tighter than "must be * same implementation") Nodes are all aware of their ownerDocument, * and attempts to mismatch will throw WRONG_DOCUMENT_ERR. * <P> * However, to save memory not all nodes always have a direct reference * to their ownerDocument. When a node is owned by another node it relies * on its owner to store its ownerDocument. Parent nodes always store it * though, so there is never more than one level of indirection. * And when a node doesn't have an owner, ownerNode refers to its * ownerDocument. * <p> * This class doesn't directly support mutation events, however, it still * implements the EventTarget interface and forward all related calls to the * document so that the document class do so. * * @author Arnaud Le Hors, IBM * @author Joe Kesselman, IBM * @version $Id: NodeImpl.java,v 1.71 2004/01/16 16:23:50 elena Exp $ * @since PR-DOM-Level-1-19980818. */public abstract class NodeImpl implements Node, NodeList, EventTarget, Cloneable, Serializable{ // // Constants // // TreePosition Constants. // Taken from DOM L3 Node interface. /** * The node precedes the reference node. */ public static final short TREE_POSITION_PRECEDING = 0x01; /** * The node follows the reference node. */ public static final short TREE_POSITION_FOLLOWING = 0x02; /** * The node is an ancestor of the reference node. */ public static final short TREE_POSITION_ANCESTOR = 0x04; /** * The node is a descendant of the reference node. */ public static final short TREE_POSITION_DESCENDANT = 0x08; /** * The two nodes have an equivalent position. This is the case of two * attributes that have the same <code>ownerElement</code>, and two * nodes that are the same. */ public static final short TREE_POSITION_EQUIVALENT = 0x10; /** * The two nodes are the same. Two nodes that are the same have an * equivalent position, though the reverse may not be true. */ public static final short TREE_POSITION_SAME_NODE = 0x20; /** * The two nodes are disconnected, they do not have any common ancestor. * This is the case of two nodes that are not in the same document. */ public static final short TREE_POSITION_DISCONNECTED = 0x00; // DocumentPosition public static final short DOCUMENT_POSITION_DISCONNECTED = 0x01; public static final short DOCUMENT_POSITION_PRECEDING = 0x02; public static final short DOCUMENT_POSITION_FOLLOWING = 0x04; public static final short DOCUMENT_POSITION_CONTAINS = 0x08; public static final short DOCUMENT_POSITION_IS_CONTAINED = 0x10; public static final short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; /** Serialization version. */ static final long serialVersionUID = -6316591992167219696L; // public /** Element definition node type. */ public static final short ELEMENT_DEFINITION_NODE = 21; // // Data // // links protected NodeImpl ownerNode; // typically the parent but not always! // data protected short flags; protected final static short READONLY = 0x1<<0; protected final static short SYNCDATA = 0x1<<1; protected final static short SYNCCHILDREN = 0x1<<2; protected final static short OWNED = 0x1<<3; protected final static short FIRSTCHILD = 0x1<<4; protected final static short SPECIFIED = 0x1<<5; protected final static short IGNORABLEWS = 0x1<<6; protected final static short HASSTRING = 0x1<<7; protected final static short NORMALIZED = 0x1<<8; protected final static short ID = 0x1<<9; // // Constructors // /** * No public constructor; only subclasses of Node should be * instantiated, and those normally via a Document's factory methods * <p> * Every Node knows what Document it belongs to. */ protected NodeImpl(CoreDocumentImpl ownerDocument) { // as long as we do not have any owner, ownerNode is our ownerDocument ownerNode = ownerDocument; } // <init>(CoreDocumentImpl) /** Constructor for serialization. */ public NodeImpl() {} // // Node methods // /** * A short integer indicating what type of node this is. The named * constants for this value are defined in the org.w3c.dom.Node interface. */ public abstract short getNodeType(); /** * the name of this node. */ public abstract String getNodeName(); /** * Returns the node value. * @throws DOMException(DOMSTRING_SIZE_ERR) */ public String getNodeValue() throws DOMException { return null; // overridden in some subclasses } /** * Sets the node value. * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) */ public void setNodeValue(String x) throws DOMException { // Default behavior is to do nothing, overridden in some subclasses } /** * Adds a child node to the end of the list of children for this node. * Convenience shorthand for insertBefore(newChild,null). * @see #insertBefore(Node, Node) * <P> * By default we do not accept any children, ParentNode overrides this. * @see ParentNode * * @return newChild, in its new state (relocated, or emptied in the case of * DocumentNode.) * * @throws DOMException(HIERARCHY_REQUEST_ERR) if newChild is of a * type that shouldn't be a child of this node. * * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a * different owner document than we do. * * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is * read-only. */ public Node appendChild(Node newChild) throws DOMException { return insertBefore(newChild, null); } /** * Returns a duplicate of a given node. You can consider this a * generic "copy constructor" for nodes. The newly returned object should * be completely independent of the source object's subtree, so changes * in one after the clone has been made will not affect the other. * <P> * Note: since we never have any children deep is meaningless here, * ParentNode overrides this behavior. * @see ParentNode * * <p> * Example: Cloning a Text node will copy both the node and the text it * contains. * <p> * Example: Cloning something that has children -- Element or Attr, for * example -- will _not_ clone those children unless a "deep clone" * has been requested. A shallow clone of an Attr node will yield an * empty Attr of the same name. * <p> * NOTE: Clones will always be read/write, even if the node being cloned * is read-only, to permit applications using only the DOM API to obtain * editable copies of locked portions of the tree. */ public Node cloneNode(boolean deep) { if (needsSyncData()) { synchronizeData(); } NodeImpl newnode; try { newnode = (NodeImpl)clone(); } catch (CloneNotSupportedException e) { // if we get here we have an error in our program we may as well // be vocal about it, so that people can take appropriate action. throw new RuntimeException("**Internal Error**" + e); } // Need to break the association w/ original kids newnode.ownerNode = ownerDocument(); newnode.isOwned(false); // By default we make all clones readwrite, // this is overriden in readonly subclasses newnode.isReadOnly(false); ownerDocument().callUserDataHandlers(this, newnode, UserDataHandler.NODE_CLONED); return newnode; } // cloneNode(boolean):Node /** * Find the Document that this Node belongs to (the document in * whose context the Node was created). The Node may or may not * currently be part of that Document's actual contents. */ public Document getOwnerDocument() { // if we have an owner simply forward the request // otherwise ownerNode is our ownerDocument if (isOwned()) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?