⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 domnode.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* DomNode.java --    Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.xml.dom;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import org.w3c.dom.Document;import org.w3c.dom.DOMException;import org.w3c.dom.DOMImplementation;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.w3c.dom.Text;import org.w3c.dom.UserDataHandler;import org.w3c.dom.events.DocumentEvent;import org.w3c.dom.events.Event;import org.w3c.dom.events.EventException;import org.w3c.dom.events.EventListener;import org.w3c.dom.events.EventTarget;import org.w3c.dom.events.MutationEvent;import org.w3c.dom.traversal.NodeFilter;import org.w3c.dom.traversal.NodeIterator;/** * <p> "Node", "EventTarget", and "DocumentEvent" implementation. * This provides most of the core DOM functionality; only more * specialized features are provided by subclasses.  Those subclasses may * have some particular constraints they must implement, by overriding * methods defined here.  Such constraints are noted here in the method * documentation. </p> * * <p> Note that you can create events with type names prefixed with "USER-", * and pass them through this DOM.  This lets you use the DOM event scheme * for application specific purposes, although you must use a predefined event * structure (such as MutationEvent) to pass data along with those events. * Test for existence of this feature with the "USER-Events" DOM feature * name.</p> * * <p> Other kinds of events you can send include the "html" events, * like "load", "unload", "abort", "error", and "blur"; and the mutation * events.  If this DOM has been compiled with mutation event support * enabled, it will send mutation events when you change parts of the * tree; otherwise you may create and send such events yourself, but * they won't be generated by the DOM itself. </p> * * <p> Note that there is a namespace-aware name comparison method, * <em>nameAndTypeEquals</em>, which compares the names (and types) of * two nodes in conformance with the "Namespaces in XML" specification. * While mostly intended for use with elements and attributes, this should * also be helpful for ProcessingInstruction nodes and some others which * do not have namespace URIs. * * @author David Brownell * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> */public abstract class DomNode  implements Node, NodeList, EventTarget, DocumentEvent, Cloneable, Comparable{  // package private  //final static String xmlNamespace = "http://www.w3.org/XML/1998/namespace";  //final static String xmlnsURI = "http://www.w3.org/2000/xmlns/";  // tunable  //	NKIDS_* affects arrays of children (which grow)  // (currently) fixed size:  //	ANCESTORS_* is for event capture/bubbling, # ancestors  //	NOTIFICATIONS_* is for per-node event delivery, # events  private static final int NKIDS_DELTA = 8;  private static final int ANCESTORS_INIT = 20;  private static final int NOTIFICATIONS_INIT = 10;  // tunable: enable mutation events or not?  Enabling it costs about  // 10-15% in DOM construction time, last time it was measured.  // package private !!!  static final boolean reportMutations = true;  // locking protocol changeable only within this class  private static final Object lockNode = new Object();  // NON-FINAL class data  // Optimize event dispatch by not allocating memory each time  private static boolean dispatchDataLock;  private static DomNode[] ancestors = new DomNode[ANCESTORS_INIT];  private static ListenerRecord[] notificationSet    = new ListenerRecord[NOTIFICATIONS_INIT];  // Ditto for the (most common) event object itself!  private static boolean eventDataLock;  private static DomEvent.DomMutationEvent mutationEvent    = new DomEvent.DomMutationEvent(null);  //  // PER-INSTANCE DATA  //  DomDocument owner;  DomNode parent; // parent node;  DomNode previous; // previous sibling node  DomNode next; // next sibling node  DomNode first; // first child node  DomNode last; // last child node  int index; // index of this node in its parent's children  int depth; // depth of the node in the document  int length; // number of children  final short nodeType;  // Bleech ... "package private" so a builder can populate entity refs.  // writable during construction.  DOM spec is nasty.  boolean readonly;  // event registrations  private ListenerRecord[] listeners;  private int nListeners;  // DOM Level 3 userData dictionary.  private HashMap userData;  private HashMap userDataHandlers;  //  // Some of the methods here are declared 'final' because  // knowledge about their implementation is built into this  // class -- for both integrity and performance.  //  /**   * Reduces space utilization for this node.   */  public void compact()  {    if (listeners != null && listeners.length != nListeners)      {        if (nListeners == 0)          {            listeners = null;          }        else          {            ListenerRecord[] l = new ListenerRecord[nListeners];            System.arraycopy(listeners, 0, l, 0, nListeners);            listeners = l;          }      }  }  /**   * Constructs a node and associates it with its owner.  Only   * Document and DocumentType nodes may be created with no owner,   * and DocumentType nodes get an owner as soon as they are   * associated with a document.   */  protected DomNode(short nodeType, DomDocument owner)  {    this.nodeType = nodeType;    if (owner == null)      {        // DOM calls never go down this path        if (nodeType != DOCUMENT_NODE && nodeType != DOCUMENT_TYPE_NODE)          {            throw new IllegalArgumentException ("no owner!");          }      }    this.owner = owner;  }    /**   * <b>DOM L1</b>   * Returns null; Element subclasses must override this method.   */  public NamedNodeMap getAttributes()  {    return null;  }  /**   * <b>DOM L2></b>   * Returns true iff this is an element node with attributes.   */  public boolean hasAttributes()  {    return false;  }  /**   * <b>DOM L1</b>   * Returns a list, possibly empty, of the children of this node.   * In this implementation, to conserve memory, nodes are the same   * as their list of children.  This can have ramifications for   * subclasses, which may need to provide their own getLength method   * for reasons unrelated to the NodeList method of the same name.   */  public NodeList getChildNodes()  {    return this;  }  /**   * <b>DOM L1</b>   * Returns the first child of this node, or null if there are none.   */  public Node getFirstChild()  {    return first;  }  /**   * <b>DOM L1</b>   * Returns the last child of this node, or null if there are none.   */  public Node getLastChild()  {    return last;  }  /**   * <b>DOM L1</b>   * Returns true if this node has children.   */  public boolean hasChildNodes()  {    return length != 0;  }  /**   * Exposes the internal "readonly" flag.  In DOM, children of   * entities and entity references are readonly, as are the   * objects associated with DocumentType objets.   */  public final boolean isReadonly()  {    return readonly;  }  /**   * Sets the internal "readonly" flag so this subtree can't be changed.   * Subclasses need to override this method for any associated content   * that's not a child node, such as an element's attributes or the   * (few) declarations associated with a DocumentType.   */  public void makeReadonly()  {    readonly = true;    for (DomNode child = first; child != null; child = child.next)      {        child.makeReadonly();      }  }  /**   * Used to adopt a node to a new document.   */  void setOwner(DomDocument doc)  {    this.owner = doc;    for (DomNode ctx = first; ctx != null; ctx = ctx.next)      {        ctx.setOwner(doc);      }  }  // just checks the node for inclusion -- may be called many  // times (docfrag) before anything is allowed to change  private void checkMisc(DomNode child)  {    if (readonly && !owner.building)      {        throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,                                  null, this, 0);      }    for (DomNode ctx = this; ctx != null; ctx = ctx.parent)      {        if (child == ctx)          {            throw new DomDOMException(DOMException.HIERARCHY_REQUEST_ERR,                                      "can't make ancestor into a child",                                      this, 0);          }      }    DomDocument owner = (nodeType == DOCUMENT_NODE) ? (DomDocument) this :      this.owner;    DomDocument childOwner = child.owner;    short childNodeType = child.nodeType;        if (childOwner != owner)      {        // new in DOM L2, this case -- patch it up later, in reparent()        if (!(childNodeType == DOCUMENT_TYPE_NODE && childOwner == null))          {            throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR,                                      null, child, 0);          }      }    // enforce various structural constraints    switch (nodeType)      {      case DOCUMENT_NODE:        switch (childNodeType)          {          case ELEMENT_NODE:          case PROCESSING_INSTRUCTION_NODE:          case COMMENT_NODE:          case DOCUMENT_TYPE_NODE:            return;          }        break;              case ATTRIBUTE_NODE:        switch (childNodeType)          {          case TEXT_NODE:          case ENTITY_REFERENCE_NODE:            return;          }        break;              case DOCUMENT_FRAGMENT_NODE:      case ENTITY_REFERENCE_NODE:      case ELEMENT_NODE:      case ENTITY_NODE:        switch (childNodeType)          {          case ELEMENT_NODE:          case TEXT_NODE:          case COMMENT_NODE:          case PROCESSING_INSTRUCTION_NODE:          case CDATA_SECTION_NODE:          case ENTITY_REFERENCE_NODE:            return;          }        break;      }    if (owner.checkingWellformedness)      {        throw new DomDOMException(DOMException.HIERARCHY_REQUEST_ERR,                                  "can't append " +                                  nodeTypeToString(childNodeType) +                                  " to node of type " +                                  nodeTypeToString(nodeType),                                  this, 0);      }  }    // Here's hoping a good optimizer will detect the case when the  // next several methods are never called, and won't allocate  // object code space of any kind.  (Case:  not reporting any  // mutation events.  We can also remove some static variables  // listed above.)  private void insertionEvent(DomEvent.DomMutationEvent event,                              DomNode target)  {    if (owner == null || owner.building)      {        return;      }    boolean doFree = false;        if (event == null)      {        event = getMutationEvent();      }    if (event != null)      {        doFree = true;      }    else      {        event = new DomEvent.DomMutationEvent(null);      }    event.initMutationEvent("DOMNodeInserted",                            true /* bubbles */, false /* nocancel */,                            this /* related */, null, null, null, (short) 0);    target.dispatchEvent(event);    // XXX should really visit every descendant of 'target'    // and sent a DOMNodeInsertedIntoDocument event to it...    // bleech, there's no way to keep that acceptably fast.    if (doFree)      {        event.target = null;        event.relatedNode = null;        event.currentNode = null;        eventDataLock = false;      } // else we created work for the GC  }  private void removalEvent(DomEvent.DomMutationEvent event,                            DomNode target)  {    if (owner == null || owner.building)      {        return;      }    boolean doFree = false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -