dtmnodeproxy.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,381 行 · 第 1/3 页

JAVA
1,381
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999 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 "Xalan" 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, Lotus * Development Corporation., http://www.lotus.com.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package org.apache.xml.dtm.ref;import org.w3c.dom.*;import org.apache.xml.dtm.*;import org.apache.xml.dtm.Axis;/** * <meta name="usage" content="internal"/> * <code>DTMNodeProxy</code> presents a DOM Node API front-end to the DTM model. * <p> * It does _not_ attempt to address the "node identity" question; no effort * is made to prevent the creation of multiple proxies referring to a single * DTM node. Users can create a mechanism for managing this, or relinquish the * use of "==" and use the .sameNodeAs() mechanism, which is under * consideration for future versions of the DOM. * <p> * DTMNodeProxy may be subclassed further to present specific DOM node types. * * @see org.w3c.dom */public class DTMNodeProxy  implements Node, Document, Text, Element, Attr,                   ProcessingInstruction, Comment, DocumentFragment{  /** The DTM for this node. */  public DTM dtm;  /** The DTM node handle. */  int node;          /** The DOMImplementation object */  static final DOMImplementation implementation=new DTMNodeProxyImplementation();  /**   * Create a DTMNodeProxy Node representing a specific Node in a DTM   *   * @param dtm The DTM Reference, must be non-null.   * @param node The DTM node handle.   */  DTMNodeProxy(DTM dtm, int node)  {    this.dtm = dtm;    this.node = node;  }  /**   * NON-DOM: Return the DTM model   *   * @return The DTM that this proxy is a representative for.   */  public final DTM getDTM()  {    return dtm;  }  /**   * NON-DOM: Return the DTM node number   *   * @return The DTM node handle.   */  public final int getDTMNodeNumber()  {    return node;  }  /**   * Test for equality based on node number.   *   * @param node A DTM node proxy reference.   *   * @return true if the given node has the same handle as this node.   */  public final boolean equals(Node node)  {    try    {      DTMNodeProxy dtmp = (DTMNodeProxy) node;      // return (dtmp.node == this.node);      // Patch attributed to Gary L Peskin <garyp@firstech.com>      return (dtmp.node == this.node) && (dtmp.dtm == this.dtm);    }    catch (ClassCastException cce)    {      return false;    }  }  /**   * Test for equality based on node number.   *   * @param node A DTM node proxy reference.   *   * @return true if the given node has the same handle as this node.   */  public final boolean equals(Object node)  {    try    {      // DTMNodeProxy dtmp = (DTMNodeProxy)node;      // return (dtmp.node == this.node);      // Patch attributed to Gary L Peskin <garyp@firstech.com>      return equals((Node) node);    }    catch (ClassCastException cce)    {      return false;    }  }  /**   * FUTURE DOM: Test node identity, in lieu of Node==Node   *   * @param other   *   * @return true if the given node has the same handle as this node.   */  public final boolean sameNodeAs(Node other)  {    if (!(other instanceof DTMNodeProxy))      return false;    DTMNodeProxy that = (DTMNodeProxy) other;    return this.dtm == that.dtm && this.node == that.node;  }  /**   *   * @return   * @see org.w3c.dom.Node   */  public final String getNodeName()  {    return dtm.getNodeName(node);  }  /**   * A PI's "target" states what processor channel the PI's data   * should be directed to. It is defined differently in HTML and XML.   * <p>   * In XML, a PI's "target" is the first (whitespace-delimited) token   * following the "<?" token that begins the PI.   * <p>   * In HTML, target is always null.   * <p>   * Note that getNodeName is aliased to getTarget.   *   * @return   */  public final String getTarget()  {    return dtm.getNodeName(node);  }  // getTarget():String  /**   *   * @return   * @see org.w3c.dom.Node as of DOM Level 2   */  public final String getLocalName()  {    return dtm.getLocalName(node);  }  /**   * @return The prefix for this node.   * @see org.w3c.dom.Node as of DOM Level 2   */  public final String getPrefix()  {    return dtm.getPrefix(node);  }  /**   *   * @param prefix   *   * @throws DOMException   * @see org.w3c.dom.Node as of DOM Level 2 -- DTMNodeProxy is read-only   */  public final void setPrefix(String prefix) throws DOMException  {    throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);  }  /**   *   * @return   * @see org.w3c.dom.Node as of DOM Level 2   */  public final String getNamespaceURI()  {    return dtm.getNamespaceURI(node);  }  /** Ask whether we support a given DOM feature.   * In fact, we do not _fully_ support any DOM feature -- we're a   * read-only subset -- so arguably we should always return false.   * Or we could say that we support DOM Core Level 2 but all nodes   * are read-only. Unclear which answer is least misleading.   *    * NON-DOM method. This was present in early drafts of DOM Level 2,   * but was renamed isSupported. It's present here only because it's   * cheap, harmless, and might help some poor fool who is still trying   * to use an early Working Draft of the DOM.   *   * @param feature   * @param version   *   * @return false   */  public final boolean supports(String feature, String version)  {    return implementation.hasFeature(feature,version);    //throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);  }  /** Ask whether we support a given DOM feature.   * In fact, we do not _fully_ support any DOM feature -- we're a   * read-only subset -- so arguably we should always return false.   *   * @param feature   * @param version   *   * @return false   * @see org.w3c.dom.Node as of DOM Level 2   */  public final boolean isSupported(String feature, String version)  {    return implementation.hasFeature(feature,version);    // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);  }  /**   *   * @return   *   * @throws DOMException   * @see org.w3c.dom.Node   */  public final String getNodeValue() throws DOMException  {    return dtm.getNodeValue(node);  }    /**   * @return The string value of the node   *    * @throws DOMException   */  public final String getStringValue() throws DOMException  {  	return dtm.getStringValue(node).toString();  }  /**   *   * @param nodeValue   *   * @throws DOMException   * @see org.w3c.dom.Node -- DTMNodeProxy is read-only   */  public final void setNodeValue(String nodeValue) throws DOMException  {    throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);  }  /**   *   * @return   * @see org.w3c.dom.Node   */  public final short getNodeType()  {    return (short) dtm.getNodeType(node);  }  /**   *   * @return   * @see org.w3c.dom.Node   */  public final Node getParentNode()  {    if (getNodeType() == Node.ATTRIBUTE_NODE)      return null;    int newnode = dtm.getParent(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  /**   *   * @return   * @see org.w3c.dom.Node   */  public final Node getOwnerNode()  {    int newnode = dtm.getParent(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  /**   *   * @return   * @see org.w3c.dom.Node   */  public final NodeList getChildNodes()  {                    // Annoyingly, AxisIterators do not currently implement DTMIterator, so    // we can't just wap DTMNodeList around an Axis.CHILD iterator.    // Instead, we've created a special-case operating mode for that object.    return new DTMNodeList(dtm,node);    // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);  }  /**   *   * @return   * @see org.w3c.dom.Node   */  public final Node getFirstChild()  {    int newnode = dtm.getFirstChild(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  /**   *   * @return   * @see org.w3c.dom.Node   */  public final Node getLastChild()  {    int newnode = dtm.getLastChild(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  /**   *   * @return   * @see org.w3c.dom.Node   */  public final Node getPreviousSibling()  {    int newnode = dtm.getPreviousSibling(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  /**   *   * @return   * @see org.w3c.dom.Node   */  public final Node getNextSibling()  {    // Attr's Next is defined at DTM level, but not at DOM level.    if (dtm.getNodeType(node) == Node.ATTRIBUTE_NODE)      return null;    int newnode = dtm.getNextSibling(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  // DTMNamedNodeMap m_attrs;  /**   *   * @return   * @see org.w3c.dom.Node   */  public final NamedNodeMap getAttributes()  {    return new DTMNamedNodeMap(dtm, node);  }  /**   * Method hasAttribute   *   *   * @param name   *   * (hasAttribute) @return   */

⌨️ 快捷键说明

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