📄 dtm.java
字号:
/* * 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;import org.apache.xml.utils.XMLString;import javax.xml.transform.SourceLocator;/** * <code>DTM</code> is an XML document model expressed as a table * rather than an object tree. It attempts to provide an interface to * a parse tree that has very little object creation. (DTM * implementations may also support incremental construction of the * model, but that's hidden from the DTM API.) * * <p>Nodes in the DTM are identified by integer "handles". A handle must * be unique within a process, and carries both node identification and * document identification. It must be possible to compare two handles * (and thus their nodes) for identity with "==".</p> * * <p>Namespace URLs, local-names, and expanded-names can all be * represented by and tested as integer ID values. An expanded name * represents (and may or may not directly contain) a combination of * the URL ID, and the local-name ID. Note that the namespace URL id * can be 0, which should have the meaning that the namespace is null. * For consistancy, zero should not be used for a local-name index. </p> * * <p>Text content of a node is represented by an index and length, * permitting efficient storage such as a shared FastStringBuffer.</p> * * <p>The model of the tree, as well as the general navigation model, * is that of XPath 1.0, for the moment. The model will eventually be * adapted to match the XPath 2.0 data model, XML Schema, and * InfoSet.</p> * * <p>DTM does _not_ directly support the W3C's Document Object * Model. However, it attempts to come close enough that an * implementation of DTM can be created that wraps a DOM and vice * versa.</p> * * <p><strong>Please Note:</strong> The DTM API is still * <strong>Subject To Change.</strong> This wouldn't affect most * users, but might require updating some extensions.</p> * * <p> The largest change being contemplated is a reconsideration of * the Node Handle representation. We are still not entirely sure * that an integer packed with two numeric subfields is really the * best solution. It has been suggested that we move up to a Long, to * permit more nodes per document without having to reduce the number * of slots in the DTMManager. There's even been a proposal that we * replace these integers with "cursor" objects containing the * internal node id and a pointer to the actual DTM object; this might * reduce the need to continuously consult the DTMManager to retrieve * the latter, and might provide a useful "hook" back into normal Java * heap management. But changing this datatype would have huge impact * on Xalan's internals -- especially given Java's lack of C-style * typedefs -- so we won't cut over unless we're convinced the new * solution really would be an improvement!</p> * */public interface DTM{ /** * Null node handles are represented by this value. */ public static final int NULL = -1; // These nodeType mnemonics and values are deliberately the same as those // used by the DOM, for convenient mapping // // %REVIEW% Should we actually define these as initialized to, // eg. org.w3c.dom.Document.ELEMENT_NODE? /** * The node is an <code>Element</code>. */ public static final short ELEMENT_NODE = 1; /** * The node is an <code>Attr</code>. */ public static final short ATTRIBUTE_NODE = 2; /** * The node is a <code>Text</code> node. */ public static final short TEXT_NODE = 3; /** * The node is a <code>CDATASection</code>. */ public static final short CDATA_SECTION_NODE = 4; /** * The node is an <code>EntityReference</code>. */ public static final short ENTITY_REFERENCE_NODE = 5; /** * The node is an <code>Entity</code>. */ public static final short ENTITY_NODE = 6; /** * The node is a <code>ProcessingInstruction</code>. */ public static final short PROCESSING_INSTRUCTION_NODE = 7; /** * The node is a <code>Comment</code>. */ public static final short COMMENT_NODE = 8; /** * The node is a <code>Document</code>. */ public static final short DOCUMENT_NODE = 9; /** * The node is a <code>DocumentType</code>. */ public static final short DOCUMENT_TYPE_NODE = 10; /** * The node is a <code>DocumentFragment</code>. */ public static final short DOCUMENT_FRAGMENT_NODE = 11; /** * The node is a <code>Notation</code>. */ public static final short NOTATION_NODE = 12; /** * The node is a <code>namespace node</code>. Note that this is not * currently a node type defined by the DOM API. */ public static final short NAMESPACE_NODE = 13; /** * The number of valid nodetypes. */ public static final short NTYPES = 14; // ========= DTM Implementation Control Functions. ============== // %TBD% RETIRED -- do via setFeature if needed. Remove from impls. // public void setParseBlockSize(int blockSizeSuggestion); /** * Set an implementation dependent feature. * <p> * %REVIEW% Do we really expect to set features on DTMs? * * @param featureId A feature URL. * @param state true if this feature should be on, false otherwise. */ public void setFeature(String featureId, boolean state); /** * Set a run time property for this DTM instance. * * @param property a <code>String</code> value * @param value an <code>Object</code> value */ public void setProperty(String property, Object value); // ========= Document Navigation Functions ========= /** * This returns a stateless "traverser", that can navigate over an * XPath axis, though not in document order. * * @param axis One of Axes.ANCESTORORSELF, etc. * * @return A DTMAxisIterator, or null if the givin axis isn't supported. */ public DTMAxisTraverser getAxisTraverser(final int axis); /** * This is a shortcut to the iterators that implement * XPath axes. * Returns a bare-bones iterator that must be initialized * with a start node (using iterator.setStartNode()). * * @param axis One of Axes.ANCESTORORSELF, etc. * * @return A DTMAxisIterator, or null if the givin axis isn't supported. */ public DTMAxisIterator getAxisIterator(final int axis); /** * Get an iterator that can navigate over an XPath Axis, predicated by * the extended type ID. * * @param axis * @param type An extended type ID. * * @return A DTMAxisIterator, or null if the givin axis isn't supported. */ public DTMAxisIterator getTypedAxisIterator(final int axis, final int type); /** * Given a node handle, test if it has child nodes. * <p> %REVIEW% This is obviously useful at the DOM layer, where it * would permit testing this without having to create a proxy * node. It's less useful in the DTM API, where * (dtm.getFirstChild(nodeHandle)!=DTM.NULL) is just as fast and * almost as self-evident. But it's a convenience, and eases porting * of DOM code to DTM. </p> * * @param nodeHandle int Handle of the node. * @return int true if the given node has child nodes. */ public boolean hasChildNodes(int nodeHandle); /** * Given a node handle, get the handle of the node's first child. * * @param nodeHandle int Handle of the node. * @return int DTM node-number of first child, * or DTM.NULL to indicate none exists. */ public int getFirstChild(int nodeHandle); /** * Given a node handle, get the handle of the node's last child. * * @param nodeHandle int Handle of the node. * @return int Node-number of last child, * or DTM.NULL to indicate none exists. */ public int getLastChild(int nodeHandle); /** * Retrieves an attribute node by local name and namespace URI * * %TBD% Note that we currently have no way to support * the DOM's old getAttribute() call, which accesses only the qname. * * @param elementHandle Handle of the node upon which to look up this attribute. * @param namespaceURI The namespace URI of the attribute to * retrieve, or null. * @param name The local name of the attribute to * retrieve. * @return The attribute node handle with the specified name ( * <code>nodeName</code>) or <code>DTM.NULL</code> if there is no such * attribute. */ public int getAttributeNode(int elementHandle, String namespaceURI, String name); /** * Given a node handle, get the index of the node's first attribute. * * @param nodeHandle int Handle of the node. * @return Handle of first attribute, or DTM.NULL to indicate none exists. */ public int getFirstAttribute(int nodeHandle); /** * Given a node handle, get the index of the node's first namespace node. * * @param nodeHandle handle to node, which should probably be an element * node, but need not be. * * @param inScope true if all namespaces in scope should be * returned, false if only the node's own * namespace declarations should be returned. * @return handle of first namespace, * or DTM.NULL to indicate none exists. */ public int getFirstNamespaceNode(int nodeHandle, boolean inScope); /** * Given a node handle, advance to its next sibling. * @param nodeHandle int Handle of the node. * @return int Node-number of next sibling, * or DTM.NULL to indicate none exists. */ public int getNextSibling(int nodeHandle);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -