locpathiterator.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,082 行 · 第 1/3 页
JAVA
1,082 行
* * @throws javax.xml.transform.TransformerException */ public boolean bool(XPathContext xctxt) throws javax.xml.transform.TransformerException { return (asNode(xctxt) != DTM.NULL); } /** * <meta name="usage" content="advanced"/> * Set if this is an iterator at the upper level of * the XPath. * * @param b true if this location path is at the top level of the * expression. */ public void setIsTopLevel(boolean b) { m_isTopLevel = b; } /** * <meta name="usage" content="advanced"/> * Get if this is an iterator at the upper level of * the XPath. * * @return true if this location path is at the top level of the * expression. */ public boolean getIsTopLevel() { return m_isTopLevel; } /** * Initialize the context values for this expression * after it is cloned. * * @param execContext The XPath runtime context for this * transformation. */ public void setRoot(int context, Object environment) { m_context = context; XPathContext xctxt = (XPathContext)environment; m_execContext = xctxt; m_cdtm = xctxt.getDTM(context); m_currentContextNode = context; // only if top level? // Yech, shouldn't have to do this. -sb if(null == m_prefixResolver) m_prefixResolver = xctxt.getNamespaceContext(); m_lastFetched = DTM.NULL; m_foundLast = false; m_pos = 0; m_length = -1; if (m_isTopLevel) this.m_stackFrame = xctxt.getVarStack().getStackFrame(); // reset(); } /** * Set the next position index of this iterator. * * @param next A value greater than or equal to zero that indicates the next * node position to fetch. */ protected void setNextPosition(int next) { assertion(false, "setNextPosition not supported in this iterator!"); } /** * Get the current position, which is one less than * the next nextNode() call will retrieve. i.e. if * you call getCurrentPos() and the return is 0, the next * fetch will take place at index 1. * * @return A value greater than or equal to zero that indicates the next * node position to fetch. */ public final int getCurrentPos() { return m_pos; } /** * If setShouldCacheNodes(true) is called, then nodes will * be cached. They are not cached by default. * * @param b True if this iterator should cache nodes. */ public void setShouldCacheNodes(boolean b) { assertion(false, "setShouldCacheNodes not supported by this iterater!"); } /** * Tells if this iterator can have nodes added to it or set via * the <code>setItem(int node, int index)</code> method. * * @return True if the nodelist can be mutated. */ public boolean isMutable() { return false; } /** * Set the current position in the node set. * * @param i Must be a valid index greater * than or equal to zero and less than m_cachedNodes.size(). */ public void setCurrentPos(int i) { assertion(false, "setCurrentPos not supported by this iterator!"); } /** * Increment the current position in the node set. */ public void incrementCurrentPos() { m_pos++; } /** * Get the length of the cached nodes. * * <p>Note: for the moment at least, this only returns * the size of the nodes that have been fetched to date, * it doesn't attempt to run to the end to make sure we * have found everything. This should be reviewed.</p> * * @return The size of the current cache list. */ public int size() { assertion(false, "size() not supported by this iterator!"); return 0; } /** * Returns the <code>index</code> th item in the collection. If * <code>index</code> is greater than or equal to the number of nodes in * the list, this returns <code>null</code> . * @param index Index into the collection. * @return The node at the <code>index</code> th position in the * <code>NodeList</code> , or <code>null</code> if that is not a valid * index. */ public int item(int index) { assertion(false, "item(int index) not supported by this iterator!"); return 0; } /** * Sets the node at the specified index of this vector to be the * specified node. The previous component at that position is discarded. * * <p>The index must be a value greater than or equal to 0 and less * than the current size of the vector. * The iterator must be in cached mode.</p> * * <p>Meant to be used for sorted iterators.</p> * * @param node Node to set * @param index Index of where to set the node */ public void setItem(int node, int index) { assertion(false, "setItem not supported by this iterator!"); } /** * The number of nodes in the list. The range of valid child node indices * is 0 to <code>length-1</code> inclusive. * * @return The number of nodes in the list, always greater or equal to zero. */ public int getLength() { // Tell if this is being called from within a predicate. boolean isPredicateTest = (this == m_execContext.getSubContextList()); // And get how many total predicates are part of this step. int predCount = getPredicateCount(); // If we have already calculated the length, and the current predicate // is the first predicate, then return the length. We don't cache // the anything but the length of the list to the first predicate. if (-1 != m_length && isPredicateTest && m_predicateIndex < 1) return m_length; // I'm a bit worried about this one, since it doesn't have the // checks found above. I suspect it's fine. -sb if (m_foundLast) return m_pos; // Create a clone, and count from the current position to the end // of the list, not taking into account the current predicate and // predicates after the current one. int pos = (m_predicateIndex >= 0) ? getProximityPosition() : m_pos; LocPathIterator clone; try { clone = (LocPathIterator) clone(); } catch (CloneNotSupportedException cnse) { return -1; } // We want to clip off the last predicate, but only if we are a sub // context node list, NOT if we are a context list. See pos68 test, // also test against bug4638. if (predCount > 0 && isPredicateTest) { // Don't call setPredicateCount, because it clones and is slower. clone.m_predCount = m_predicateIndex; // The line above used to be: // clone.m_predCount = predCount - 1; // ...which looks like a dumb bug to me. -sb } int next; while (DTM.NULL != (next = clone.nextNode())) { pos++; } if (isPredicateTest && m_predicateIndex < 1) m_length = pos; return pos; } /** * Tells if this NodeSetDTM is "fresh", in other words, if * the first nextNode() that is called will return the * first node in the set. * * @return true of nextNode has not been called. */ public boolean isFresh() { return (m_pos == 0); } /** * Returns the previous node in the set and moves the position of the * iterator backwards in the set. * @return The previous <code>Node</code> in the set being iterated over, * or<code>null</code> if there are no more members in that set. */ public int previousNode() { throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null)); //"This NodeSetDTM can not iterate to a previous node!"); } /** * This attribute determines which node types are presented via the * iterator. The available set of constants is defined in the * <code>NodeFilter</code> interface. * * <p>This is somewhat useless at this time, since it doesn't * really return information that tells what this iterator will * show. It is here only to fullfill the DOM NodeIterator * interface.</p> * * @return For now, always NodeFilter.SHOW_ALL & ~NodeFilter.SHOW_ENTITY_REFERENCE. * @see org.w3c.dom.traversal.NodeIterator */ public int getWhatToShow() { // TODO: ?? return DTMFilter.SHOW_ALL & ~DTMFilter.SHOW_ENTITY_REFERENCE; } /** * The filter used to screen nodes. Not used at this time, * this is here only to fullfill the DOM NodeIterator * interface. * * @return Always null. * @see org.w3c.dom.traversal.NodeIterator */ public DTMFilter getFilter() { return null; } /** * The root node of the Iterator, as specified when it was created. * * @return The "root" of this iterator, which, in XPath terms, * is the node context for this iterator. */ public int getRoot() { return m_context; } /** * The value of this flag determines whether the children of entity * reference nodes are visible to the iterator. If false, they will be * skipped over. * <br> To produce a view of the document that has entity references * expanded and does not expose the entity reference node itself, use the * whatToShow flags to hide the entity reference node and set * expandEntityReferences to true when creating the iterator. To produce * a view of the document that has entity reference nodes but no entity * expansion, use the whatToShow flags to show the entity reference node * and set expandEntityReferences to false. * * @return Always true, since entity reference nodes are not * visible in the XPath model. */ public boolean getExpandEntityReferences() { return true; } /** Control over whether it is OK for detach to reset the iterator. */ protected boolean m_allowDetach = true; /** * Specify if it's OK for detach to release the iterator for reuse. * * @param allowRelease true if it is OK for detach to release this iterator * for pooling. */ public void allowDetachToRelease(boolean allowRelease) { m_allowDetach = allowRelease; } /** * Detaches the iterator from the set which it iterated over, releasing * any computational resources and placing the iterator in the INVALID * state. After<code>detach</code> has been invoked, calls to * <code>nextNode</code> or<code>previousNode</code> will raise the * exception INVALID_STATE_ERR.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?