dtmnodeproxy.java

来自「JAVA 所有包」· Java 代码 · 共 2,314 行 · 第 1/5 页

JAVA
2,314
字号
/* * Copyright 1999-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Id: DTMNodeProxy.java,v  */package com.sun.org.apache.xml.internal.dtm.ref;import java.util.Vector;import com.sun.org.apache.xml.internal.dtm.DTM;import com.sun.org.apache.xml.internal.dtm.DTMDOMException;import com.sun.org.apache.xpath.internal.NodeSet;import org.w3c.dom.Attr;import org.w3c.dom.CDATASection;import org.w3c.dom.Comment;import org.w3c.dom.DOMException;import org.w3c.dom.DOMImplementation;import org.w3c.dom.Document;import org.w3c.dom.DocumentFragment;import org.w3c.dom.DocumentType;import org.w3c.dom.Element;import org.w3c.dom.EntityReference;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.w3c.dom.ProcessingInstruction;import org.w3c.dom.Text;import org.w3c.dom.UserDataHandler;import org.w3c.dom.DOMConfiguration;import org.w3c.dom.TypeInfo;/** * <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 return value as Empty String. */  private static final String EMPTYSTRING = "";          /** 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.   */  public 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;  }  /**   *   *    * @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.   *   *    */  public final String getTarget()  {    return dtm.getNodeName(node);  }  // getTarget():String  /**   *   *    * @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);  }  /**   *   *    * @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);  }  /**   *   *    *   * @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);  }  /**   *   *    * @see org.w3c.dom.Node   */  public final short getNodeType()  {    return (short) dtm.getNodeType(node);  }  /**   *   *    * @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);  }  /**   *   *    * @see org.w3c.dom.Node   */  public final Node getOwnerNode()  {    int newnode = dtm.getParent(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  /**   *   *    * @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 DTMChildIterNodeList(dtm,node);    // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);  }  /**   *   *    * @see org.w3c.dom.Node   */  public final Node getFirstChild()  {    int newnode = dtm.getFirstChild(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  /**   *   *    * @see org.w3c.dom.Node   */  public final Node getLastChild()  {    int newnode = dtm.getLastChild(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  /**   *   *    * @see org.w3c.dom.Node   */  public final Node getPreviousSibling()  {    int newnode = dtm.getPreviousSibling(node);    return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);  }  /**   *   *    * @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;  /**   *   *    * @see org.w3c.dom.Node   */  public final NamedNodeMap getAttributes()  {    return new DTMNamedNodeMap(dtm, node);  }  /**   * Method hasAttribute   *   *   * @param name   *   */  public boolean hasAttribute(String name)  {    return DTM.NULL != dtm.getAttributeNode(node,null,name);  }  /**   * Method hasAttributeNS   *   *   * @param namespaceURI   * @param localName   *   *   */  public boolean hasAttributeNS(String namespaceURI, String localName)  {    return DTM.NULL != dtm.getAttributeNode(node,namespaceURI,localName);

⌨️ 快捷键说明

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