dtmdefaultbase.java

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

JAVA
2,022
字号
/* * 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.apache.xml.dtm.*;import org.apache.xml.utils.SuballocatedIntVector;import org.apache.xml.utils.SuballocatedByteVector;import org.apache.xml.utils.IntStack;import org.apache.xml.utils.BoolStack;import org.apache.xml.utils.StringBufferPool;import org.apache.xml.utils.FastStringBuffer;import org.apache.xml.utils.TreeWalker;import org.apache.xml.utils.QName;import org.apache.xml.utils.XMLCharacterRecognizer;import java.util.Vector;import org.xml.sax.ContentHandler;import org.apache.xml.utils.NodeVector;import javax.xml.transform.Source;import org.apache.xml.utils.XMLString;import org.apache.xml.utils.XMLStringFactory;import org.apache.xalan.res.XSLMessages;import org.apache.xalan.res.XSLTErrorResources;import java.io.*; // for dumpDTM/** * The <code>DTMDefaultBase</code> class serves as a helper base for DTMs. * It sets up structures for navigation and type, while leaving data * management and construction to the derived classes. */public abstract class DTMDefaultBase implements DTM{	static boolean JJK_DEBUG=false;	  /**   * The number of nodes, which is also used to determine the next   *  node index.   */  protected int m_size = 0;  /** The expanded names, one array element for each node. */  protected SuballocatedIntVector m_exptype;  /** First child values, one array element for each node. */  protected SuballocatedIntVector m_firstch;  /** Next sibling values, one array element for each node. */  protected SuballocatedIntVector m_nextsib;  /** Previous sibling values, one array element for each node. */  protected SuballocatedIntVector m_prevsib;  /** Previous sibling values, one array element for each node. */  protected SuballocatedIntVector m_parent;  /** Vector of SuballocatedIntVectors of NS decl sets */  protected Vector m_namespaceDeclSets = null;  /** SuballocatedIntVector  of elements at which corresponding   * namespaceDeclSets were defined */  protected SuballocatedIntVector m_namespaceDeclSetElements = null;  /**   * These hold indexes to elements based on namespace and local name.   * The base lookup is the the namespace.  The second lookup is the local   * name, and the last array contains the the first free element   * at the start, and the list of element handles following.   */  protected int[][][] m_elemIndexes;  /** The default initial block size of the node arrays */  protected int m_initialblocksize = 512;  // favor small docs.  /** Size of blocks to allocate */  protected int m_blocksize = 2 * 1024;  /**   * The value to use when the information has not been built yet.   */  protected static final int NOTPROCESSED = DTM.NULL - 1;  /**   * The DTM manager who "owns" this DTM.   */  protected DTMManager m_mgr;  /**   * m_mgr cast to DTMManagerDefault, or null if it isn't an instance   * (Efficiency hook)   */  protected DTMManagerDefault m_mgrDefault=null;  /** The document identity number(s). If we have overflowed the addressing   * range of the first that was assigned to us, we may add others. */  protected SuballocatedIntVector m_dtmIdent=new SuballocatedIntVector();  /** The mask for the identity.      %REVIEW% Should this really be set to the _DEFAULT? What if      a particular DTM wanted to use another value? */  //protected final static int m_mask = DTMManager.IDENT_NODE_DEFAULT;  /** The base URI for this document. */  protected String m_documentBaseURI;  /**   * The whitespace filter that enables elements to strip whitespace or not.   */  protected DTMWSFilter m_wsfilter;  /** Flag indicating whether to strip whitespace nodes */  protected boolean m_shouldStripWS = false;  /** Stack of flags indicating whether to strip whitespace nodes */  protected BoolStack m_shouldStripWhitespaceStack;  /** The XMLString factory for creating XMLStrings. */  protected XMLStringFactory m_xstrf;  /**   * The table for exandedNameID lookups.  This may or may not be the same   * table as is contained in the DTMManagerDefault.   */  protected ExpandedNameTable m_expandedNameTable;  /** true if indexing is turned on. */  protected boolean m_indexing;  /**   * Construct a DTMDefaultBase object from a DOM node.   *   * @param mgr The DTMManager who owns this DTM.   * @param domSource the DOM source that this DTM will wrap.   * @param source The object that is used to specify the construction source.   * @param dtmIdentity The DTM identity ID for this DTM.   * @param whiteSpaceFilter The white space filter for this DTM, which may   *                         be null.   * @param xstringfactory The factory to use for creating XMLStrings.   * @param doIndexing true if the caller considers it worth it to use   *                   indexing schemes.   */  public DTMDefaultBase(DTMManager mgr, Source source, int dtmIdentity,                        DTMWSFilter whiteSpaceFilter,                        XMLStringFactory xstringfactory, boolean doIndexing)  {    if(false == doIndexing)    {      m_initialblocksize = 8;      m_blocksize = 16;    }    m_exptype = new SuballocatedIntVector(m_initialblocksize);    m_firstch = new SuballocatedIntVector(m_initialblocksize);    m_nextsib = new SuballocatedIntVector(m_initialblocksize);    m_prevsib = new SuballocatedIntVector(m_initialblocksize);    m_parent = new SuballocatedIntVector(m_initialblocksize);    m_mgr = mgr;    if(mgr instanceof DTMManagerDefault)      m_mgrDefault=(DTMManagerDefault)mgr;        m_documentBaseURI = (null != source) ? source.getSystemId() : null;    m_dtmIdent.setElementAt(dtmIdentity,0);    m_wsfilter = whiteSpaceFilter;    m_xstrf = xstringfactory;    m_indexing = doIndexing;    if (doIndexing)    {      m_expandedNameTable = new ExpandedNameTable();    }    else    {      // Note that this fails if we aren't talking to an instance of      // DTMManagerDefault      m_expandedNameTable = m_mgrDefault.getExpandedNameTable(this);    }    if (null != whiteSpaceFilter)    {      m_shouldStripWhitespaceStack = new BoolStack();      pushShouldStripWhitespace(false);    }  }  /**   * Ensure that the size of the element indexes can hold the information.   *   * @param namespaceID Namespace ID index.   * @param LocalNameID Local name ID.   */  protected void ensureSizeOfIndex(int namespaceID, int LocalNameID)  {    if (null == m_elemIndexes)    {      m_elemIndexes = new int[namespaceID + 20][][];    }    else if (m_elemIndexes.length <= namespaceID)    {      int[][][] indexes = m_elemIndexes;      m_elemIndexes = new int[namespaceID + 20][][];      System.arraycopy(indexes, 0, m_elemIndexes, 0, indexes.length);    }    int[][] localNameIndex = m_elemIndexes[namespaceID];    if (null == localNameIndex)    {      localNameIndex = new int[LocalNameID + 100][];      m_elemIndexes[namespaceID] = localNameIndex;    }    else if (localNameIndex.length <= LocalNameID)    {      int[][] indexes = localNameIndex;      localNameIndex = new int[LocalNameID + 100][];      System.arraycopy(indexes, 0, localNameIndex, 0, indexes.length);      m_elemIndexes[namespaceID] = localNameIndex;    }    int[] elemHandles = localNameIndex[LocalNameID];    if (null == elemHandles)    {      elemHandles = new int[128];      localNameIndex[LocalNameID] = elemHandles;      elemHandles[0] = 1;    }    else if (elemHandles.length <= elemHandles[0] + 1)    {      int[] indexes = elemHandles;      elemHandles = new int[elemHandles[0] + 1024];      System.arraycopy(indexes, 0, elemHandles, 0, indexes.length);      localNameIndex[LocalNameID] = elemHandles;    }  }  /**   * Add a node to the element indexes. The node will not be added unless   * it's an element.   *   * @param expandedTypeID The expanded type ID of the node.   * @param identity The node identity index.   */  protected void indexNode(int expandedTypeID, int identity)  {    ExpandedNameTable ent = m_expandedNameTable;    short type = ent.getType(expandedTypeID);    if (DTM.ELEMENT_NODE == type)    {      int namespaceID = ent.getNamespaceID(expandedTypeID);      int localNameID = ent.getLocalNameID(expandedTypeID);      ensureSizeOfIndex(namespaceID, localNameID);      int[] index = m_elemIndexes[namespaceID][localNameID];      index[index[0]] = identity;      index[0]++;    }  }  /**   * Find the first index that occurs in the list that is greater than or   * equal to the given value.   *   * @param list A list of integers.   * @param start The start index to begin the search.   * @param len The number of items to search.   * @param value Find the slot that has a value that is greater than or   * identical to this argument.   *   * @return The index in the list of the slot that is higher or identical   * to the identity argument, or -1 if no node is higher or equal.   */  protected int findGTE(int[] list, int start, int len, int value)  {    int low = start;    int high = start + (len - 1);    int end = high;    while (low <= high)    {      int mid = (low + high) / 2;      int c = list[mid];      if (c > value)        high = mid - 1;      else if (c < value)        low = mid + 1;      else        return mid;    }    return (low <= end && list[low] > value) ? low : -1;  }  /**   * Find the first matching element from the index at or after the   * given node.   *   * @param nsIndex The namespace index lookup.   * @param lnIndex The local name index lookup.   * @param firstPotential The first potential match that is worth looking at.   *   * @return The first node that is greater than or equal to the   *         firstPotential argument, or DTM.NOTPROCESSED if not found.   */  int findElementFromIndex(int nsIndex, int lnIndex, int firstPotential)  {    int[][][] indexes = m_elemIndexes;    if (null != indexes && nsIndex < indexes.length)    {      int[][] lnIndexs = indexes[nsIndex];      if (null != lnIndexs && lnIndex < lnIndexs.length)      {        int[] elems = lnIndexs[lnIndex];        if (null != elems)        {          int pos = findGTE(elems, 1, elems[0], firstPotential);          if (pos > -1)          {            return elems[pos];          }        }      }    }

⌨️ 快捷键说明

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