dtmdefaultbase.java

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

JAVA
2,022
字号
        int ancestor=_parent(elementNodeIndex);        while(wouldBeAt>=0 && ancestor>0)          {            candidate=m_namespaceDeclSetElements.elementAt(wouldBeAt);            if(candidate==ancestor) // Found ancestor in list                return (SuballocatedIntVector)m_namespaceDeclSets.elementAt(wouldBeAt);            else if(candidate<ancestor) // Too deep in tree                ancestor=_parent(ancestor);            else // Too late in list              --wouldBeAt;          }      }    return null; // No namespaces known at this node  }  /**     * Subroutine: Locate the specified node within     * m_namespaceDeclSetElements, or the last element which     * preceeds it in document order     *     * %REVIEW% Inlne this into findNamespaceContext? Create SortedSuballocatedIntVector type?     *     * @param elementNodeIndex Index of a node to look up.     *     * @return If positive or zero, the index of the found item.     * If negative, index of the point at which it would have appeared,     * encoded as -1-index and hence reconvertable by subtracting     * it from -1. (Encoding because I don't want to recompare the strings     * but don't want to burn bytes on a datatype to hold a flagged value.)     */  protected int findInSortedSuballocatedIntVector(SuballocatedIntVector vector, int lookfor)  {    // Binary search    int i = 0;    if(vector != null) {      int first = 0;      int last  = vector.size() - 1;      while (first <= last) {        i = (first + last) / 2;        int test = lookfor-vector.elementAt(i);        if(test == 0) {          return i; // Name found        }        else if (test < 0) {          last = i - 1; // looked too late        }        else {          first = i + 1; // looked ot early        }      }      if (first > i) {        i = first; // Clean up at loop end      }    }    return -1 - i; // not-found has to be encoded.  }  /**   * Given a node handle, get the index of the node's first child.   * If not yet resolved, waits for more nodes to be added to the document and   * tries again   *   * @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 namespace declarations should be   *                   returned.   * @return handle of first namespace, or DTM.NULL to indicate none exists.   */  public int getFirstNamespaceNode(int nodeHandle, boolean inScope)  {        if(inScope)        {            SuballocatedIntVector nsContext=findNamespaceContext(makeNodeIdentity(nodeHandle));            if(nsContext==null || nsContext.size()<1)              return NULL;            return nsContext.elementAt(0);          }        else          {            // Assume that attributes and namespaces immediately            // follow the element.            //            // %OPT% Would things be faster if all NS nodes were built            // before all Attr nodes? Some costs at build time for 2nd            // pass...            int identity = makeNodeIdentity(nodeHandle);            while (DTM.NULL != (identity = getNextNodeIdentity(identity)))              {                int type = _type(identity);                if (type == DTM.NAMESPACE_NODE)                    return makeNodeHandle(identity);                else if (DTM.ATTRIBUTE_NODE != type)                    break;              }            return NULL;          }  }  /**   * Given a namespace handle, advance to the next namespace.   *   * @param baseHandle handle to original node from where the first namespace   * was relative to (needed to return nodes in document order).   * @param namespaceHandle handle to node which must be of type   * NAMESPACE_NODE.   * @param nodeHandle A namespace handle for which we will find the next node.   * @param inScope true if all namespaces that are in scope should be processed,   * otherwise just process the nodes in the given element handle.   * @return handle of next namespace, or DTM.NULL to indicate none exists.   */  public int getNextNamespaceNode(int baseHandle, int nodeHandle,                                  boolean inScope)  {        if(inScope)          {            //Since we've been given the base, try direct lookup            //(could look from nodeHandle but this is at least one            //comparison/get-parent faster)            //SuballocatedIntVector nsContext=findNamespaceContext(nodeHandle & m_mask);                SuballocatedIntVector nsContext=findNamespaceContext(makeNodeIdentity(baseHandle));            if(nsContext==null)              return NULL;            int i=1 + nsContext.indexOf(nodeHandle);            if(i<=0 || i==nsContext.size())              return NULL;            return nsContext.elementAt(i);          }        else          {            // Assume that attributes and namespace nodes immediately follow the element.            int identity = makeNodeIdentity(nodeHandle);            while (DTM.NULL != (identity = getNextNodeIdentity(identity)))              {                int type = _type(identity);                if (type == DTM.NAMESPACE_NODE)                  {                    return makeNodeHandle(identity);                  }                else if (type != DTM.ATTRIBUTE_NODE)                  {                    break;                  }              }          }     return DTM.NULL;  }  /**   * Given a node handle, find its parent node.   *   * @param nodeHandle the id of the node.   * @return int Node-number of parent,   * or DTM.NULL to indicate none exists.   */  public int getParent(int nodeHandle)  {    int identity = makeNodeIdentity(nodeHandle);    if (identity > 0)      return makeNodeHandle(_parent(identity));    else      return DTM.NULL;  }  /**   * Find the Document node handle for the document currently under construction.   * PLEASE NOTE that most people should use getOwnerDocument(nodeHandle) instead;   * this version of the operation is primarily intended for use during negotiation   * with the DTM Manager.   *    *  @param nodeHandle the id of the node.   *  @return int Node handle of document, which should always be valid.   */  public int getDocument()  {    return m_dtmIdent.elementAt(0); // makeNodeHandle(0)  }  /**   * Given a node handle, find the owning document node.  This has the exact   * same semantics as the DOM Document method of the same name, in that if   * the nodeHandle is a document node, it will return NULL.   *   * <p>%REVIEW% Since this is DOM-specific, it may belong at the DOM   * binding layer. Included here as a convenience function and to   * aid porting of DOM code to DTM.</p>   *   * @param nodeHandle the id of the node.   * @return int Node handle of owning document, or -1 if the node was a Docment   */  public int getOwnerDocument(int nodeHandle)  {    if (DTM.DOCUMENT_NODE == getNodeType(nodeHandle))  	    return DTM.NULL;    return getDocumentRoot(nodeHandle);  }  /**   * Given a node handle, find the owning document node.  Unlike the DOM,   * this considers the owningDocument of a Document to be itself.   *   * @param nodeHandle the id of the node.   * @return int Node handle of owning document, or the nodeHandle if it is   *             a Document.   */  public int getDocumentRoot(int nodeHandle)  {    return getDocument();  }  /**   * Get the string-value of a node as a String object   * (see http://www.w3.org/TR/xpath#data-model   * for the definition of a node's string-value).   *   * @param nodeHandle The node ID.   *   * @return A string object that represents the string-value of the given node.   */  public abstract XMLString getStringValue(int nodeHandle);  /**   * Get number of character array chunks in   * the string-value of a node.   * (see http://www.w3.org/TR/xpath#data-model   * for the definition of a node's string-value).   * Note that a single text node may have multiple text chunks.   *   * @param nodeHandle The node ID.   *   * @return number of character array chunks in   *         the string-value of a node.   */  public int getStringValueChunkCount(int nodeHandle)  {    // %TBD%    error(XSLMessages.createMessage(XSLTErrorResources.ER_METHOD_NOT_SUPPORTED, null));//("getStringValueChunkCount not yet supported!");    return 0;  }  /**   * Get a character array chunk in the string-value of a node.   * (see http://www.w3.org/TR/xpath#data-model   * for the definition of a node's string-value).   * Note that a single text node may have multiple text chunks.   *   * @param nodeHandle The node ID.   * @param chunkIndex Which chunk to get.   * @param startAndLen An array of 2 where the start position and length of   *                    the chunk will be returned.   *   * @return The character array reference where the chunk occurs.   */  public char[] getStringValueChunk(int nodeHandle, int chunkIndex,                                    int[] startAndLen)  {    // %TBD%    error(XSLMessages.createMessage(XSLTErrorResources.ER_METHOD_NOT_SUPPORTED, null));//"getStringValueChunk not yet supported!");    return null;  }  /**   * Given a node handle, return an ID that represents the node's expanded name.   *   * @param nodeHandle The handle to the node in question.   *   * @return the expanded-name id of the node.   */  public int getExpandedTypeID(int nodeHandle)  {    // %REVIEW% This _should_ only be null if someone asked the wrong DTM about the node...    // which one would hope would never happen...    int id=makeNodeIdentity(nodeHandle);    if(id==NULL)      return NULL;    return _exptype(id);  }  /**   * Given an expanded name, return an ID.  If the expanded-name does not   * exist in the internal tables, the entry will be created, and the ID will   * be returned.  Any additional nodes that are created that have this   * expanded name will use this ID.   *   * @param nodeHandle The handle to the node in question.   * @param type The simple type, i.e. one of ELEMENT, ATTRIBUTE, etc.   *   * @param namespace The namespace URI, which may be null, may be an empty   *                  string (which will be the same as null), or may be a   *                  namespace URI.   * @param localName The local name string, which must be a valid   *                  <a href="http://www.w3.org/TR/REC-xml-names/">NCName</a>.   *   * @return the expanded-name id of the node.   */  public int getExpandedTypeID(String namespace, String localName, int type)  {    ExpandedNameTable ent = m_expandedNameTable;    return ent.getExpandedTypeID(namespace, localName, type);  }  /**   * Given an expanded-name ID, return the local name part.   *   * @param ExpandedNameID an ID that represents an expanded-name.   * @return String Local name of this node.   */  public String getLocalNameFromExpandedNameID(int expandedNameID)  {    return m_expandedNameTable.getLocalName(expandedNameID);  }  /**   * Given an expanded-name ID, return the namespace URI part.   *   * @param ExpandedNameID an ID that represents an expanded-name.   * @return String URI value of this node's namespace, or null if no   * namespace was resolved.   */  public String getNamespaceFromExpandedNameID(int expandedNameID)  {    return m_expandedNameTable.getNamespace(expandedNameID);  }  /**   * Returns the namespace type of a specific node   * @param nodeHandle the id of the node.   * @return the ID of the namespace.   */  public int getNamespaceType(final int nodeHandle)  {    int identity = makeNodeIdentity(nodeHandle);    int expandedNameID = _exptype(identity);    return m_expandedNameTable.getNamespaceID(expandedNameID);  }  /**   * Given a node handle, return its DOM-style node name. This will   * include names such as #text or #document.   *   * @param nodeHandle the id of the node.   * @return String Name of this node, which may be an empty string.   * %REVIEW% Document when empty string is possible...   * %REVIEW-COMMENT% It should never be empty, should it?   */  public abstract String getNodeName(int nodeHandle);  /**   * Given a node handle, return the XPath node name.  This should be   * the name as described by the XPath data model, NOT the DOM-style   * name.   *   * @param nodeHandle the id of the node.   * @return String Name of this node, which may be an empty string.   */  public String getNodeNameX(int nodeHandle)  {    /** @todo: implement this org.apache.xml.dtm.DTMDefaultBase abstract method */    error(XSLMessages.createMessage(XSLTErrorResources.ER_METHOD_NOT_SUPPORTED, null));//"Not yet supported!");    return null;  }  /**   * Given a node handle, return its XPath-style localname.   * (As defined in Namespaces, this is the portion of the name after any   * colon character).   *   * @param nodeHandle the id of the node.   * @return String Local name of this node.   */  public abstract String getLocalName(int nodeHandle);  /**   * Given a namespace handle, return the prefix that the namespace decl is   * mapping.   * Given a node handle, return the prefix used to map to the namespace.   *   * <p> %REVIEW% Are you sure you want "" for no prefix?  </p>   * <p> %REVIEW-COMMENT% I think so... not totally sure. -sb  </p>   *

⌨️ 快捷键说明

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