/** @return the next node in the set and advance the position of the * iterator in the set. * * @throws DOMException - INVALID_STATE_ERR Raised if this method is * called after the detach method was invoked. * */ public Node nextNode() throws DOMException { if(!valid) throw new DTMDOMException(DOMException.INVALID_STATE_ERR); int handle=dtm_iter.nextNode(); if (handle==DTM.NULL) return null; return dtm_iter.getDTM(handle).getNode(handle); }
/** * Public constructor: Wrap a DTMNodeList around an existing * and preconfigured DTMIterator * * WARNING: THIS HAS THE SIDE EFFECT OF ISSUING setShouldCacheNodes(true) * AGAINST THE DTMIterator. * */ public DTMNodeList(DTMIterator dtmIterator) { if (dtmIterator != null) { int pos = dtmIterator.getCurrentPos(); try { m_iter=(DTMIterator)dtmIterator.cloneWithReset(); } catch(CloneNotSupportedException cnse) { m_iter = dtmIterator; } m_iter.setShouldCacheNodes(true); m_iter.runTo(-1); m_iter.setCurrentPos(pos); } }
int n = v.getLength(); NodeCompareElem elem = new NodeCompareElem(v.item(i)); v.setItem(((NodeCompareElem) nodes.elementAt(i)).m_node, i); v.setCurrentPos(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 Node item(int index) { if (m_iter != null) { int handle=m_iter.item(index); if (handle == DTM.NULL) { return null; } return m_iter.getDTM(handle).getNode(handle); } else { return null; } }
int n = cnl.getCurrentNode(); if(n == DTM.NULL) if(cnl.getCurrentPos() == 0) return 0; cnl = cnl.cloneWithReset(); while(DTM.NULL != (n = cnl.nextNode())) return cnl.getCurrentPos();
/** * Execute the function. The function must return * a valid object. * @param xctxt The current execution context. * @return A valid XObject. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); double sum = 0.0; int pos; while (DTM.NULL != (pos = nodes.nextNode())) { DTM dtm = nodes.getDTM(pos); XMLString s = dtm.getStringValue(pos); if (null != s) sum += s.toDouble(); } nodes.detach(); return new XNumber(sum); } }
int node = m_iterators[i].getCurrentNode(); m_iterators[i].nextNode(); m_iterators[iteratorUsed].nextNode();
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. Derived classes should try and override this and return a * value without having to do a clone operation. * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { DTMIterator iter = (DTMIterator)m_clones.getInstance(); int current = xctxt.getCurrentNode(); iter.setRoot(current, xctxt); int next = iter.nextNode(); // m_clones.freeInstance(iter); iter.detach(); return next; }
/** * Get a clone of this iterator, but don't reset the iteration in the * process, so that it may be used from the current position. * Note: Not a deep clone. * * @return A clone of this object. * * @throws CloneNotSupportedException */ public Object clone() throws CloneNotSupportedException { NodeSequence clone = (NodeSequence) super.clone(); if (null != m_iter) clone.m_iter = (DTMIterator) m_iter.clone(); if (m_cache != null) { // In making this clone of an iterator we are making // another NodeSequence object it has a reference // to the same IteratorCache object as the original // so we need to remember that more than one // NodeSequence object shares the cache. m_cache.increaseUseCount(); } return clone; }
/** * Get the next node via getNextXXX. Bottlenecked for derived class override. * @return The next node on the axis, or DTM.NULL. */ protected int getNextNode() { int next; while(DTM.NULL != (next = m_keysNodes.nextNode())) { if(DTMIterator.FILTER_ACCEPT == filterNode(next)) break; } m_lastFetched = next; return next; }
/** * The number of nodes in the list. The range of valid child node indices * is 0 to <code>length-1</code> inclusive. */ public int getLength() { return (m_iter != null) ? m_iter.getLength() : 0; } }
@Override protected boolean hasNext() throws JspTagException { DTMIterator iterator = context.getContextNodeList(); return iterator.getCurrentPos() < iterator.getLength(); }
/** * @see DTMIterator#getAxis() */ public int getAxis() { if(null != m_iter) return m_iter.getAxis(); else { assertion(false, "Can not getAxis from a non-iterated node sequence!"); return 0; } }
/** * Calling this with a value of false will cause the nodeset * to be cached. * @see DTMIterator#allowDetachToRelease(boolean) */ public void allowDetachToRelease(boolean allowRelease) { if((false == allowRelease) && !hasCache()) { setShouldCacheNodes(true); } if(null != m_iter) m_iter.allowDetachToRelease(allowRelease); super.allowDetachToRelease(allowRelease); }
/** @return the next previous in the set and advance the position of the * iterator in the set. * * @throws DOMException - INVALID_STATE_ERR Raised if this method is * called after the detach method was invoked. * */ public Node previousNode() { if(!valid) throw new DTMDOMException(DOMException.INVALID_STATE_ERR); int handle=dtm_iter.previousNode(); if (handle==DTM.NULL) return null; return dtm_iter.getDTM(handle).getNode(handle); } }
/** * @see DTMIterator#previousNode() */ public int previousNode() { if(hasCache()) { if(m_next <= 0) return DTM.NULL; else { m_next--; return item(m_next); } } else { int n = m_iter.previousNode(); m_next = m_iter.getCurrentPos(); return m_next; } }
/** * Execute the function. The function must return * a valid object. * @param xctxt The current execution context. * @return A valid XObject. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { // DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); // // We should probably make a function on the iterator for this, // // as a given implementation could optimize. // int i = 0; // // while (DTM.NULL != nl.nextNode()) // { // i++; // } // nl.detach(); DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); int i = nl.getLength(); nl.detach(); return new XNumber((double) i); } }
/** * @see DTMIterator#getCurrentNode() */ public int getCurrentNode() { if(hasCache()) { int currentIndex = m_next-1; NodeVector vec = getVector(); if((currentIndex >= 0) && (currentIndex < vec.size())) return vec.elementAt(currentIndex); else return DTM.NULL; } if(null != m_iter) { return m_iter.getCurrentNode(); } else return DTM.NULL; }