dtmdocumentimpl.java

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

JAVA
1,662
字号
/* * 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: DTMDocumentImpl.java,v 1.2.4.1 2005/09/15 08:15:01 suresh_emailid Exp $ */package com.sun.org.apache.xml.internal.dtm.ref;import javax.xml.transform.SourceLocator;import com.sun.org.apache.xml.internal.dtm.DTM;import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;import com.sun.org.apache.xml.internal.dtm.DTMAxisTraverser;import com.sun.org.apache.xml.internal.dtm.DTMManager;import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;import com.sun.org.apache.xml.internal.utils.FastStringBuffer;import com.sun.org.apache.xml.internal.utils.XMLString;import com.sun.org.apache.xml.internal.utils.XMLStringFactory;import org.xml.sax.Attributes;import org.xml.sax.ContentHandler;import org.xml.sax.Locator;import org.xml.sax.ext.LexicalHandler;/** * This is the implementation of the DTM document interface.  It receives * requests from an XML content handler similar to that of an XML DOM or SAX parser * to store information from the xml document in an array based * dtm table structure.  This informtion is used later for document navigation, * query, and SAX event dispatch functions. The DTM can also be used directly as a * document composition model for an application.  The requests received are: * <ul> * <li>initiating DTM to set the doc handle</li> * <li>resetting DTM for data structure reuse</li> * <li>hinting the end of document to adjust the end of data structure pointers</li> * <li>createnodes (element, comment, text, attribute, ....)</li> * <li>hinting the end of an element to patch parent and siblings<li> * <li>setting application provided symbol name stringpool data structures</li> * </ul> * <p>State: In progress!!</p> * * %REVIEW% I _think_ the SAX convention is that "no namespace" is expressed * as "" rather than as null (which is the DOM's convention). What should * DTM expect? What should it do with the other? * * <p>Origin: the implemention is a composite logic based on the DTM of XalanJ1 and *     DocImpl, DocumentImpl, ElementImpl, TextImpl, etc. of XalanJ2</p> */public class DTMDocumentImplimplements DTM, org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler{        // Number of lower bits used to represent node index.        protected static final byte DOCHANDLE_SHIFT = 22;        // Masks the lower order of node handle.        // Same as {@link DTMConstructor.IDENT_NODE_DEFAULT}        protected static final int NODEHANDLE_MASK = (1 << (DOCHANDLE_SHIFT + 1)) - 1;        // Masks the higher order Document handle        // Same as {@link DTMConstructor.IDENT_DOC_DEFAULT}        protected static final int DOCHANDLE_MASK = -1 - NODEHANDLE_MASK;        int m_docHandle = NULL;		 // masked document handle for this dtm document        int m_docElement = NULL;	 // nodeHandle to the root of the actual dtm doc content        // Context for parse-and-append operations        int currentParent = 0;			// current parent - default is document root        int previousSibling = 0;		// previous sibling - no previous sibling        protected int m_currentNode = -1;		// current node        // The tree under construction can itself be used as        // the element stack, so m_elemStack isn't needed.        //protected Stack m_elemStack = new Stack();	 // element stack        private boolean previousSiblingWasParent = false;        // Local cache for record-at-a-time fetch        int gotslot[] = new int[4];        // endDocument recieved?        private boolean done = false;        boolean m_isError = false;        private final boolean DEBUG = false;        /** The document base URI. */        protected String m_documentBaseURI;  /** If we're building the model incrementally on demand, we need to   * be able to tell the source when to send us more data.   *   * Note that if this has not been set, and you attempt to read ahead   * of the current build point, we'll probably throw a null-pointer   * exception. We could try to wait-and-retry instead, as a very poor   * fallback, but that has all the known problems with multithreading   * on multiprocessors and we Don't Want to Go There.   *   * @see setIncrementalSAXSource   */  private IncrementalSAXSource m_incrSAXSource=null;        // ========= DTM data structure declarations. ==============        // nodes array: integer array blocks to hold the first level reference of the nodes,        // each reference slot is addressed by a nodeHandle index value.        // Assumes indices are not larger than {@link NODEHANDLE_MASK}        // ({@link DOCHANDLE_SHIFT} bits).        ChunkedIntArray nodes = new ChunkedIntArray(4);        // text/comment table: string buffer to hold the text string values of the document,        // each of which is addressed by the absolute offset and length in the buffer        private FastStringBuffer m_char = new FastStringBuffer();        // Start of string currently being accumulated into m_char;        // needed because the string may be appended in several chunks.        private int m_char_current_start=0;        // %TBD% INITIALIZATION/STARTUP ISSUES        // -- Should we really be creating these, or should they be        // passed in from outside? Scott want to be able to share        // pools across multiple documents, so setting them here is        // probably not the right default.        private DTMStringPool m_localNames = new DTMStringPool();        private DTMStringPool m_nsNames = new DTMStringPool();        private DTMStringPool m_prefixNames = new DTMStringPool();        // %TBD% If we use the current ExpandedNameTable mapper, it        // needs to be bound to the NS and local name pools. Which        // means it needs to attach to them AFTER we've resolved their        // startup. Or it needs to attach to this document and        // retrieve them each time. Or this needs to be        // an interface _implemented_ by this class... which might be simplest!        private ExpandedNameTable m_expandedNames=                new ExpandedNameTable();        private XMLStringFactory m_xsf;        /**         * Construct a DTM.         *         * @param documentNumber the ID number assigned to this document.         * It will be shifted up into the high bits and returned as part of         * all node ID numbers, so those IDs indicate which document they         * came from as well as a location within the document. It is the         * DTMManager's responsibility to assign a unique number to each         * document.         */        public DTMDocumentImpl(DTMManager mgr, int documentNumber,                               DTMWSFilter whiteSpaceFilter,                               XMLStringFactory xstringfactory){                initDocument(documentNumber);	 // clear nodes and document handle                m_xsf = xstringfactory;        }  /** Bind a IncrementalSAXSource to this DTM. If we discover we need nodes   * that have not yet been built, we will ask this object to send us more   * events, and it will manage interactions with its data sources.   *   * Note that we do not actually build the IncrementalSAXSource, since we don't   * know what source it's reading from, what thread that source will run in,   * or when it will run.   *   * @param source The IncrementalSAXSource that we want to recieve events from   * on demand.   */  public void setIncrementalSAXSource(IncrementalSAXSource source)  {    m_incrSAXSource=source;    // Establish SAX-stream link so we can receive the requested data    source.setContentHandler(this);    source.setLexicalHandler(this);    // Are the following really needed? IncrementalSAXSource doesn't yet    // support them, and they're mostly no-ops here...    //source.setErrorHandler(this);    //source.setDTDHandler(this);    //source.setDeclHandler(this);  }        /**         * Wrapper for ChunkedIntArray.append, to automatically update the         * previous sibling's "next" reference (if necessary) and periodically         * wake a reader who may have encountered incomplete data and entered         * a wait state.         * @param w0 int As in ChunkedIntArray.append         * @param w1 int As in ChunkedIntArray.append         * @param w2 int As in ChunkedIntArray.append         * @param w3 int As in ChunkedIntArray.append         * @return int As in ChunkedIntArray.append         * @see ChunkedIntArray.append         */        private final int appendNode(int w0, int w1, int w2, int w3)        {                // A decent compiler may inline this.                int slotnumber = nodes.appendSlot(w0, w1, w2, w3);                if (DEBUG) System.out.println(slotnumber+": "+w0+" "+w1+" "+w2+" "+w3);                if (previousSiblingWasParent)                        nodes.writeEntry(previousSibling,2,slotnumber);                previousSiblingWasParent = false;	// Set the default; endElement overrides                return slotnumber;        }        // ========= DTM Implementation Control Functions. ==============        /**         * 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 reference pointer to the element name symbol table.         * %REVIEW% Should this really be Public? Changing it while         * DTM is in use would be a disaster.         *         * @param poolRef DTMStringPool reference to an instance of table.         */        public void setLocalNameTable(DTMStringPool poolRef) {                m_localNames = poolRef;        }        /**         * Get a reference pointer to the element name symbol table.         *         * @return DTMStringPool reference to an instance of table.         */        public DTMStringPool getLocalNameTable() {                 return m_localNames;         }        /**         * Set a reference pointer to the namespace URI symbol table.         * %REVIEW% Should this really be Public? Changing it while         * DTM is in use would be a disaster.         *         * @param poolRef DTMStringPool reference to an instance of table.         */        public void setNsNameTable(DTMStringPool poolRef) {                m_nsNames = poolRef;        }        /**         * Get a reference pointer to the namespace URI symbol table.         *         * @return DTMStringPool reference to an instance of table.         */        public DTMStringPool getNsNameTable() {                 return m_nsNames;         }        /**         * Set a reference pointer to the prefix name symbol table.         * %REVIEW% Should this really be Public? Changing it while         * DTM is in use would be a disaster.         *         * @param poolRef DTMStringPool reference to an instance of table.         */        public void setPrefixNameTable(DTMStringPool poolRef) {                m_prefixNames = poolRef;        }        /**         * Get a reference pointer to the prefix name symbol table.         *         * @return DTMStringPool reference to an instance of table.         */        public DTMStringPool getPrefixNameTable() {                return m_prefixNames;        }         /**          * Set a reference pointer to the content-text repository          *          * @param buffer FastStringBuffer reference to an instance of          * buffer          */         void setContentBuffer(FastStringBuffer buffer) {                 m_char = buffer;         }         /**          * Get a reference pointer to the content-text repository          *          * @return FastStringBuffer reference to an instance of buffer          */         FastStringBuffer getContentBuffer() {                 return m_char;         }  /** getContentHandler returns "our SAX builder" -- the thing that   * someone else should send SAX events to in order to extend this   * DTM model.   *   * @return null if this model doesn't respond to SAX events,   * "this" if the DTM object has a built-in SAX ContentHandler,   * the IncrementalSAXSource if we're bound to one and should receive   * the SAX stream via it for incremental build purposes...   * */  public org.xml.sax.ContentHandler getContentHandler()  {    if (m_incrSAXSource instanceof IncrementalSAXSource_Filter)      return (ContentHandler) m_incrSAXSource;    else      return this;  }  /**   * Return this DTM's lexical handler.   *   * %REVIEW% Should this return null if constrution already done/begun?   *   * @return null if this model doesn't respond to lexical SAX events,   * "this" if the DTM object has a built-in SAX ContentHandler,

⌨️ 快捷键说明

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