NodeVector vec = getVector(); if (null != vec) return next; else if(cacheComplete() || (-1 != m_last) || (null == m_iter)) if(DTM.NULL != next) if(hasCache()) getVector().addElement(next); m_next++; int insertIndex = addNodeInDocOrder(next); if(insertIndex >= 0) m_next++; markCacheComplete();
/** * @see DTMIterator#item(int) */ public int item(int index) { setCurrentPos(index); int n = nextNode(); m_next = index; return n; }
/** * @see DTMIterator#getDTM(int) */ public DTM getDTM(int nodeHandle) { DTMManager mgr = getDTMManager(); if(null != mgr) return getDTMManager().getDTM(nodeHandle); else { assertion(false, "Can not get a DTM Unless a DTMManager has been set!"); return null; } }
/** * @see DTMIterator#setRoot(int, Object) */ public void setRoot(int nodeHandle, Object environment) { if(null != m_iter) { XPathContext xctxt = (XPathContext)environment; m_dtmMgr = xctxt.getDTMManager(); m_iter.setRoot(nodeHandle, environment); if(!m_iter.isDocOrdered()) { if(!hasCache()) setShouldCacheNodes(true); runTo(-1); m_next=0; } } else assertion(false, "Can not setRoot on a non-iterated NodeSequence!"); }
/** * Create a new NodeSequence from a (already cloned) iterator. * * @param nodeVector */ public NodeSequence(Object nodeVector) { super(nodeVector); if (nodeVector instanceof NodeVector) { SetVector((NodeVector) nodeVector); } if(null != nodeVector) { assertion(nodeVector instanceof NodeVector, "Must have a NodeVector as the object for NodeSequence!"); if(nodeVector instanceof DTMIterator) { setIter((DTMIterator)nodeVector); m_last = ((DTMIterator)nodeVector).getLength(); } } }
/** * Cast result object to a boolean. * * @return True if there is a next node in the nodeset */ public boolean bool() { return (item(0) != DTM.NULL); }
/** * If the iterator needs to cache nodes as they are fetched, * then this method returns true. */ public boolean hasCache() { final NodeVector nv = getVector(); return (nv != null); }
/** * 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); }
/** * @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; }
/** * Cast result object to a nodelist. * * @return a NodeList. * * @throws javax.xml.transform.TransformerException */ public NodeList nodelist() throws javax.xml.transform.TransformerException { org.apache.xml.dtm.ref.DTMNodeList nodelist = new org.apache.xml.dtm.ref.DTMNodeList(this); // Creating a DTMNodeList has the side-effect that it will create a clone // XNodeSet with cache and run m_iter to the end. You cannot get any node // from m_iter after this call. As a fix, we call SetVector() on the clone's // cache. See Bugzilla 14406. XNodeSet clone = (XNodeSet)nodelist.getDTMIterator(); SetVector(clone.getVector()); return nodelist; }
/** * @see DTMIterator#isMutable() */ public boolean isMutable() { return hasCache(); // though may be surprising if it also has an iterator! }
/** * Cast result object to a boolean, but allow side effects, such as the * incrementing of an iterator. * * @return True if there is a next node in the nodeset */ public boolean boolWithSideEffects() { return (nextNode() != DTM.NULL); }
/** * @see DTMIterator#getDTM(int) */ public DTM getDTM(int nodeHandle) { DTMManager mgr = getDTMManager(); if(null != mgr) return getDTMManager().getDTM(nodeHandle); else { assertion(false, "Can not get a DTM Unless a DTMManager has been set!"); return null; } }
/** * @see DTMIterator#item(int) */ public int item(int index) { setCurrentPos(index); int n = nextNode(); m_next = index; return n; }