📄 dtm.java
字号:
/* * 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: DTM.java,v 1.2.4.1 2005/09/15 08:14:51 suresh_emailid Exp $ */package com.sun.org.apache.xml.internal.dtm;import javax.xml.transform.SourceLocator;import com.sun.org.apache.xml.internal.utils.XMLString;/** * <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 a <code>Root</code>. */ public static final short ROOT_NODE = 0; /** * 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); /** * Given a node handle, find its preceeding sibling. * WARNING: DTM implementations may be asymmetric; in some, * this operation has been resolved by search, and is relatively expensive. * * @param nodeHandle the id of the node. * @return int Node-number of the previous sib, * or DTM.NULL to indicate none exists. */ public int getPreviousSibling(int nodeHandle); /** * Given a node handle, advance to the next attribute. If an * element, we advance to its first attribute; if an attr, we advance to * the next attr of the same element. * * @param nodeHandle int Handle of the node. * @return int DTM node-number of the resolved attr, * or DTM.NULL to indicate none exists. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -