dtmdefaultbase.java

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

JAVA
2,066
字号
   * @param identity The node identity (index).   * @return identity+1, or DTM.NULL.   */  protected abstract int getNextNodeIdentity(int identity);  /**   * This method should try and build one or more nodes in the table.   *   * @return The true if a next node is found or false if   *         there are no more nodes.   */  protected abstract boolean nextNode();  /**   * Get the number of nodes that have been added.   *   * @return the number of nodes that have been mapped.   */  protected abstract int getNumberOfNodes();  /** Stateless axis traversers, lazely built. */  protected DTMAxisTraverser[] m_traversers;//    /**//     * Ensure that the size of the information arrays can hold another entry//     * at the given index.//     *//     * @param index On exit from this function, the information arrays sizes must be//     * at least index+1.//     *///    protected void ensureSize(int index)//    {//        // We've cut over to Suballocated*Vector, which are self-sizing.//    }  /**   * Get the simple type ID for the given node identity.   *   * @param identity The node identity.   *   * @return The simple type ID, or DTM.NULL.   */  protected short _type(int identity)  {    int info = _exptype(identity);    if (NULL != info)      return m_expandedNameTable.getType(info);    else      return NULL;  }  /**   * Get the expanded type ID for the given node identity.   *   * @param identity The node identity.   *   * @return The expanded type ID, or DTM.NULL.   */  protected int _exptype(int identity)  {  	if (identity == DTM.NULL)  	return NULL;    // Reorganized test and loop into single flow    // Tiny performance improvement, saves a few bytes of code, clearer.    // %OPT% Other internal getters could be treated simliarly    while (identity>=m_size)    {      if (!nextNode() && identity >= m_size)        return NULL;    }    return m_exptype.elementAt(identity);  }  /**   * Get the level in the tree for the given node identity.   *   * @param identity The node identity.   *   * @return The tree level, or DTM.NULL.   */  protected int _level(int identity)  {    while (identity>=m_size)    {      boolean isMore = nextNode();      if (!isMore && identity >= m_size)        return NULL;    }    int i=0;    while(NULL != (identity=_parent(identity)))      ++i;    return i;  }  /**   * Get the first child for the given node identity.   *   * @param identity The node identity.   *   * @return The first child identity, or DTM.NULL.   */  protected int _firstch(int identity)  {    // Boiler-plate code for each of the _xxx functions, except for the array.    int info = (identity >= m_size) ? NOTPROCESSED : m_firstch.elementAt(identity);    // Check to see if the information requested has been processed, and,    // if not, advance the iterator until we the information has been    // processed.    while (info == NOTPROCESSED)    {      boolean isMore = nextNode();      if (identity >= m_size &&!isMore)        return NULL;      else      {        info = m_firstch.elementAt(identity);        if(info == NOTPROCESSED && !isMore)          return NULL;      }    }    return info;  }  /**   * Get the next sibling for the given node identity.   *   * @param identity The node identity.   *   * @return The next sibling identity, or DTM.NULL.   */  protected int _nextsib(int identity)  {    // Boiler-plate code for each of the _xxx functions, except for the array.    int info = (identity >= m_size) ? NOTPROCESSED : m_nextsib.elementAt(identity);    // Check to see if the information requested has been processed, and,    // if not, advance the iterator until we the information has been    // processed.    while (info == NOTPROCESSED)    {      boolean isMore = nextNode();      if (identity >= m_size &&!isMore)        return NULL;      else      {        info = m_nextsib.elementAt(identity);        if(info == NOTPROCESSED && !isMore)          return NULL;      }    }    return info;  }  /**   * Get the previous sibling for the given node identity.   *   * @param identity The node identity.   *   * @return The previous sibling identity, or DTM.NULL.   */  protected int _prevsib(int identity)  {    if (identity < m_size)      return m_prevsib.elementAt(identity);    // Check to see if the information requested has been processed, and,    // if not, advance the iterator until we the information has been    // processed.    while (true)    {      boolean isMore = nextNode();      if (identity >= m_size && !isMore)        return NULL;      else if (identity < m_size)        return m_prevsib.elementAt(identity);    }  }  /**   * Get the parent for the given node identity.   *   * @param identity The node identity.   *   * @return The parent identity, or DTM.NULL.   */  protected int _parent(int identity)  {    if (identity < m_size)      return m_parent.elementAt(identity);    // Check to see if the information requested has been processed, and,    // if not, advance the iterator until we the information has been    // processed.    while (true)    {      boolean isMore = nextNode();      if (identity >= m_size && !isMore)        return NULL;      else if (identity < m_size)        return m_parent.elementAt(identity);    }  }  /**   * Diagnostics function to dump the DTM.   */  public void dumpDTM(OutputStream os)  {    try    {      if(os==null)      {	      File f = new File("DTMDump"+((Object)this).hashCode()+".txt"); 	      System.err.println("Dumping... "+f.getAbsolutePath()); 	      os=new FileOutputStream(f);      }      PrintStream ps = new PrintStream(os);      while (nextNode()){}      int nRecords = m_size;      ps.println("Total nodes: " + nRecords);      for (int index = 0; index < nRecords; ++index)      {      	int i=makeNodeHandle(index);        ps.println("=========== index=" + index + " handle=" + i + " ===========");        ps.println("NodeName: " + getNodeName(i));        ps.println("NodeNameX: " + getNodeNameX(i));        ps.println("LocalName: " + getLocalName(i));        ps.println("NamespaceURI: " + getNamespaceURI(i));        ps.println("Prefix: " + getPrefix(i));        int exTypeID = _exptype(index);        ps.println("Expanded Type ID: "                           + Integer.toHexString(exTypeID));        int type = _type(index);        String typestring;        switch (type)        {        case DTM.ATTRIBUTE_NODE :          typestring = "ATTRIBUTE_NODE";          break;        case DTM.CDATA_SECTION_NODE :          typestring = "CDATA_SECTION_NODE";          break;        case DTM.COMMENT_NODE :          typestring = "COMMENT_NODE";          break;        case DTM.DOCUMENT_FRAGMENT_NODE :          typestring = "DOCUMENT_FRAGMENT_NODE";          break;        case DTM.DOCUMENT_NODE :          typestring = "DOCUMENT_NODE";          break;        case DTM.DOCUMENT_TYPE_NODE :          typestring = "DOCUMENT_NODE";          break;        case DTM.ELEMENT_NODE :          typestring = "ELEMENT_NODE";          break;        case DTM.ENTITY_NODE :          typestring = "ENTITY_NODE";          break;        case DTM.ENTITY_REFERENCE_NODE :          typestring = "ENTITY_REFERENCE_NODE";          break;        case DTM.NAMESPACE_NODE :          typestring = "NAMESPACE_NODE";          break;        case DTM.NOTATION_NODE :          typestring = "NOTATION_NODE";          break;        case DTM.NULL :          typestring = "NULL";          break;        case DTM.PROCESSING_INSTRUCTION_NODE :          typestring = "PROCESSING_INSTRUCTION_NODE";          break;        case DTM.TEXT_NODE :          typestring = "TEXT_NODE";          break;        default :          typestring = "Unknown!";          break;        }        ps.println("Type: " + typestring);        int firstChild = _firstch(index);        if (DTM.NULL == firstChild)          ps.println("First child: DTM.NULL");        else if (NOTPROCESSED == firstChild)          ps.println("First child: NOTPROCESSED");        else          ps.println("First child: " + firstChild);        if (m_prevsib != null)        {          int prevSibling = _prevsib(index);          if (DTM.NULL == prevSibling)            ps.println("Prev sibling: DTM.NULL");          else if (NOTPROCESSED == prevSibling)            ps.println("Prev sibling: NOTPROCESSED");          else            ps.println("Prev sibling: " + prevSibling);        }        int nextSibling = _nextsib(index);        if (DTM.NULL == nextSibling)          ps.println("Next sibling: DTM.NULL");        else if (NOTPROCESSED == nextSibling)          ps.println("Next sibling: NOTPROCESSED");        else          ps.println("Next sibling: " + nextSibling);        int parent = _parent(index);        if (DTM.NULL == parent)          ps.println("Parent: DTM.NULL");        else if (NOTPROCESSED == parent)          ps.println("Parent: NOTPROCESSED");        else          ps.println("Parent: " + parent);        int level = _level(index);        ps.println("Level: " + level);        ps.println("Node Value: " + getNodeValue(i));        ps.println("String Value: " + getStringValue(i));      }    }    catch(IOException ioe)    {      ioe.printStackTrace(System.err);        throw new RuntimeException(ioe.getMessage());    }  }    /**   * Diagnostics function to dump a single node.   *    * %REVIEW% KNOWN GLITCH: If you pass it a node index rather than a    * node handle, it works just fine... but the displayed identity    * number before the colon is different, which complicates comparing   * it with nodes printed the other way. We could always OR the DTM ID   * into the value, to suppress that distinction...   *    * %REVIEW% This might want to be moved up to DTMDefaultBase, or possibly   * DTM itself, since it's a useful diagnostic and uses only DTM's public   * APIs.   */  public String dumpNode(int nodeHandle)  {	  	  if(nodeHandle==DTM.NULL)		  return "[null]";		          String typestring;        switch (getNodeType(nodeHandle))        {        case DTM.ATTRIBUTE_NODE :          typestring = "ATTR";          break;        case DTM.CDATA_SECTION_NODE :          typestring = "CDATA";          break;        case DTM.COMMENT_NODE :          typestring = "COMMENT";          break;        case DTM.DOCUMENT_FRAGMENT_NODE :          typestring = "DOC_FRAG";          break;        case DTM.DOCUMENT_NODE :          typestring = "DOC";          break;        case DTM.DOCUMENT_TYPE_NODE :          typestring = "DOC_TYPE";          break;        case DTM.ELEMENT_NODE :          typestring = "ELEMENT";          break;        case DTM.ENTITY_NODE :          typestring = "ENTITY";          break;        case DTM.ENTITY_REFERENCE_NODE :          typestring = "ENT_REF";          break;        case DTM.NAMESPACE_NODE :          typestring = "NAMESPACE";          break;        case DTM.NOTATION_NODE :          typestring = "NOTATION";          break;

⌨️ 快捷键说明

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