dtmdefaultbase.java

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

JAVA
2,066
字号
        case DTM.NULL :          typestring = "null";          break;        case DTM.PROCESSING_INSTRUCTION_NODE :          typestring = "PI";          break;        case DTM.TEXT_NODE :          typestring = "TEXT";          break;        default :          typestring = "Unknown!";          break;        }      StringBuffer sb=new StringBuffer();	  sb.append("["+nodeHandle+": "+typestring+				"(0x"+Integer.toHexString(getExpandedTypeID(nodeHandle))+") "+				getNodeNameX(nodeHandle)+" {"+getNamespaceURI(nodeHandle)+"}"+				"=\""+ getNodeValue(nodeHandle)+"\"]");	  return sb.toString();  }  // ========= 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){}  // ========= Document Navigation Functions =========  /**   * 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)  {    int identity = makeNodeIdentity(nodeHandle);    int firstChild = _firstch(identity);    return firstChild != DTM.NULL;  }	  /** Given a node identity, return a node handle. If extended addressing   * has been used (multiple DTM IDs), we need to map the high bits of the   * identity into the proper DTM ID.   *    * This has been made FINAL to facilitate inlining, since we do not expect   * any subclass of DTMDefaultBase to ever change the algorithm. (I don't   * really like doing so, and would love to have an excuse not to...)   *    * %REVIEW% Is it worth trying to specialcase small documents?   * %REVIEW% Should this be exposed at the package/public layers?   *    * @param nodeIdentity Internal offset to this node's records.   * @return NodeHandle (external representation of node)   * */  final public int makeNodeHandle(int nodeIdentity)  {    if(NULL==nodeIdentity) return NULL;		    if(JJK_DEBUG && nodeIdentity>DTMManager.IDENT_NODE_DEFAULT)      System.err.println("GONK! (only useful in limited situations)");    return m_dtmIdent.elementAt(nodeIdentity >>> DTMManager.IDENT_DTM_NODE_BITS)      + (nodeIdentity & DTMManager.IDENT_NODE_DEFAULT) ;											  }	  /** Given a node handle, return a node identity. If extended addressing   * has been used (multiple DTM IDs), we need to map the high bits of the   * identity into the proper DTM ID and thence find the proper offset   * to add to the low bits of the identity   *    * This has been made FINAL to facilitate inlining, since we do not expect   * any subclass of DTMDefaultBase to ever change the algorithm. (I don't   * really like doing so, and would love to have an excuse not to...)   *    * %OPT% Performance is critical for this operation.   *   * %REVIEW% Should this be exposed at the package/public layers?   *    * @param nodeHandle (external representation of node)   * @return nodeIdentity Internal offset to this node's records.   * */  final public int makeNodeIdentity(int nodeHandle)  {    if(NULL==nodeHandle) return NULL;    if(m_mgrDefault!=null)    {      // Optimization: use the DTMManagerDefault's fast DTMID-to-offsets      // table.  I'm not wild about this solution but this operation      // needs need extreme speed.      int whichDTMindex=nodeHandle>>>DTMManager.IDENT_DTM_NODE_BITS;      // %REVIEW% Wish I didn't have to perform the pre-test, but      // someone is apparently asking DTMs whether they contain nodes      // which really don't belong to them. That's probably a bug      // which should be fixed, but until it is:      if(m_mgrDefault.m_dtms[whichDTMindex]!=this)	return NULL;      else	return	  m_mgrDefault.m_dtm_offsets[whichDTMindex]	  | (nodeHandle & DTMManager.IDENT_NODE_DEFAULT);    }	      int whichDTMid=m_dtmIdent.indexOf(nodeHandle & DTMManager.IDENT_DTM_DEFAULT);    return (whichDTMid==NULL)       ? NULL      : (whichDTMid << DTMManager.IDENT_DTM_NODE_BITS)      + (nodeHandle & DTMManager.IDENT_NODE_DEFAULT);  }  /**   * Given a node handle, get the handle 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 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)  {    int identity = makeNodeIdentity(nodeHandle);    int firstChild = _firstch(identity);    return makeNodeHandle(firstChild);  }    /**   * Given a node handle, get the handle 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 int Handle of the node.   * @return int DTM node-number of first child, or DTM.NULL to indicate none exists.   */  public int getTypedFirstChild(int nodeHandle, int nodeType)  {    int firstChild, eType;    if (nodeType < DTM.NTYPES) {      for (firstChild = _firstch(makeNodeIdentity(nodeHandle));           firstChild != DTM.NULL;           firstChild = _nextsib(firstChild)) {        eType = _exptype(firstChild);        if (eType == nodeType               || (eType >= DTM.NTYPES                      && m_expandedNameTable.getType(eType) == nodeType)) {          return makeNodeHandle(firstChild);        }      }    } else {      for (firstChild = _firstch(makeNodeIdentity(nodeHandle));           firstChild != DTM.NULL;           firstChild = _nextsib(firstChild)) {        if (_exptype(firstChild) == nodeType) {          return makeNodeHandle(firstChild);        }      }    }    return DTM.NULL;  }  /**   * Given a node handle, advance to its last child.   * If not yet resolved, waits for more nodes to be added to the document and   * tries again.   *   * @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)  {    int identity = makeNodeIdentity(nodeHandle);    int child = _firstch(identity);    int lastChild = DTM.NULL;    while (child != DTM.NULL)    {      lastChild = child;      child = _nextsib(child);    }    return makeNodeHandle(lastChild);  }  /**   * Retrieves an attribute node by by qualified name and namespace URI.   *   * @param nodeHandle int 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 abstract int getAttributeNode(int nodeHandle, 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)  {    int nodeID = makeNodeIdentity(nodeHandle);    return makeNodeHandle(getFirstAttributeIdentity(nodeID));  }  /**   * Given a node identity, get the index of the node's first attribute.   *   * @param identity int identity of the node.   * @return Identity of first attribute, or DTM.NULL to indicate none exists.   */  protected int getFirstAttributeIdentity(int identity) {    int type = _type(identity);    if (DTM.ELEMENT_NODE == type)    {      // Assume that attributes and namespaces immediately follow the element.      while (DTM.NULL != (identity = getNextNodeIdentity(identity)))      {        // Assume this can not be null.        type = _type(identity);        if (type == DTM.ATTRIBUTE_NODE)        {          return identity;        }        else if (DTM.NAMESPACE_NODE != type)        {          break;        }      }    }    return DTM.NULL;  }  /**   * Given a node handle and an expanded type ID, get the index of the node's   * attribute of that type, if any.   *   * @param nodeHandle int Handle of the node.   * @param attType int expanded type ID of the required attribute.   * @return Handle of attribute of the required type, or DTM.NULL to indicate   * none exists.   */  protected int getTypedAttribute(int nodeHandle, int attType) {    int type = getNodeType(nodeHandle);    if (DTM.ELEMENT_NODE == type) {      int identity = makeNodeIdentity(nodeHandle);      while (DTM.NULL != (identity = getNextNodeIdentity(identity)))      {        type = _type(identity);        if (type == DTM.ATTRIBUTE_NODE)        {          if (_exptype(identity) == attType) return makeNodeHandle(identity);        }        else if (DTM.NAMESPACE_NODE != type)        {          break;        }      }    }    return DTM.NULL;  }  /**   * Given a node handle, advance to its next sibling.   * If not yet resolved, waits for more nodes to be added to the document and   * tries again.   * @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)  {  	if (nodeHandle == DTM.NULL)  	return DTM.NULL;    return makeNodeHandle(_nextsib(makeNodeIdentity(nodeHandle)));  }    /**   * Given a node handle, advance to its next sibling.   * If not yet resolved, waits for more nodes to be added to the document and   * tries again.   * @param nodeHandle int Handle of the node.   * @return int Node-number of next sibling,   * or DTM.NULL to indicate none exists.   */  public int getTypedNextSibling(int nodeHandle, int nodeType)  {  	if (nodeHandle == DTM.NULL)  	return DTM.NULL;  	int node = makeNodeIdentity(nodeHandle);  	int eType;  	while ((node = _nextsib(node)) != DTM.NULL &&   	((eType = _exptype(node)) != nodeType &&   	m_expandedNameTable.getType(eType)!= nodeType));   	//_type(node) != nodeType));            return (node == DTM.NULL ? DTM.NULL : makeNodeHandle(node));  }  /**   * Given a node handle, find its preceeding sibling.   * WARNING: DTM is asymmetric; this operation is 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)  {    if (nodeHandle == DTM.NULL)      return DTM.NULL;        if (m_prevsib != null)      return makeNodeHandle(_prevsib(makeNodeIdentity(nodeHandle)));    else    {      // If the previous sibling array is not built, we get at      // the previous sibling using the parent, firstch and       // nextsib arrays.       int nodeID = makeNodeIdentity(nodeHandle);      int parent = _parent(nodeID);      int node = _firstch(parent);      int result = DTM.NULL;      while (node != nodeID)      {        result = node;        node = _nextsib(node);      }      return makeNodeHandle(result);    }  }  /**   * Given a node handle, advance to the next attribute.   * If an attr, we advance to   * the next attr on the same node.  If not an attribute, we return NULL.   *   * @param nodeHandle int Handle of the node.   * @return int DTM node-number of the resolved attr,   * or DTM.NULL to indicate none exists.   */  public int getNextAttribute(int nodeHandle) {    int nodeID = makeNodeIdentity(nodeHandle);    if (_type(nodeID) == DTM.ATTRIBUTE_NODE) {      return makeNodeHandle(getNextAttributeIdentity(nodeID));    }    return DTM.NULL;  }  /**   * Given a node identity for an attribute, advance to the next attribute.   *   * @param identity int identity of the attribute node.  This   * <strong>must</strong> be an attribute node.   *   * @return int DTM node-identity of the resolved attr,   * or DTM.NULL to indicate none exists.   *   */  protected int getNextAttributeIdentity(int identity) {    // Assume that attributes and namespace nodes immediately follow the element    while (DTM.NULL != (identity = getNextNodeIdentity(identity))) {      int type = _type(identity);      if (type == DTM.ATTRIBUTE_NODE) {        return identity;      } else if (type != DTM.NAMESPACE_NODE) {        break;      }    }    return DTM.NULL;  }

⌨️ 快捷键说明

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