FileDocCategorySizeDatePackage
DTMNodeIterator.javaAPI DocJava SE 6 API5935Tue Jun 10 00:22:58 BST 2008com.sun.org.apache.xml.internal.dtm.ref

DTMNodeIterator

public class DTMNodeIterator extends Object implements NodeIterator
DTMNodeIterator gives us an implementation of the DTMNodeIterator which returns DOM nodes. Please note that this is not necessarily equivlaent to a DOM NodeIterator operating over the same document. In particular:
  • If there are several Text nodes in logical succession (ie, across CDATASection and EntityReference boundaries), we will return only the first; the caller is responsible for stepping through them. (%REVIEW% Provide a convenience routine here to assist, pending proposed DOM Level 3 getAdjacentText() operation?)
  • Since the whole XPath/XSLT architecture assumes that the source document is not altered while we're working with it, we do not promise to implement the DOM NodeIterator's "maintain current position" response to document mutation.
  • Since our design for XPath NodeIterators builds a stateful filter directly into the traversal object, getNodeFilter() is not supported.

State: In progress!!

Fields Summary
private DTMIterator
dtm_iter
private boolean
valid
Constructors Summary
public DTMNodeIterator(DTMIterator dtmIterator)
Public constructor: Wrap a DTMNodeIterator around an existing and preconfigured DTMIterator


  //================================================================
  // Methods unique to this class

              
    
    
      try
      {
        dtm_iter=(DTMIterator)dtmIterator.clone();
      }
      catch(CloneNotSupportedException cnse)
      {
        throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(cnse);
      }
    
Methods Summary
public voiddetach()
Detaches the NodeIterator from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.

      // Theoretically, we could release dtm_iter at this point. But
      // some of the operations may still want to consult it even though
      // navigation is now invalid.
      valid=false;
    
public com.sun.org.apache.xml.internal.dtm.DTMIteratorgetDTMIterator()
Access the wrapped DTMIterator. I'm not sure whether anyone will need this or not, but let's write it and think about it.

      return dtm_iter;
    
public booleangetExpandEntityReferences()
The value of this flag determines whether the children of entity reference nodes are visible to the iterator.

return
false, always (the DTM model flattens entity references)

      return false;
    
public org.w3c.dom.traversal.NodeFiltergetFilter()
Return a handle to the filter used to screen nodes. This is ill-defined in Xalan's usage of Nodeiterator, where we have built stateful XPath-based filtering directly into the traversal object. We could return something which supports the NodeFilter interface and allows querying whether a given node would be permitted if it appeared as our next node, but in the current implementation that would be very complex -- and just isn't all that useful.

throws
DOMException -- NOT_SUPPORTED_ERROR because I can't think of anything more useful to do in this case

      throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
    
public org.w3c.dom.NodegetRoot()

return
The root node of the NodeIterator, as specified when it was created.

      int handle=dtm_iter.getRoot();
      return dtm_iter.getDTM(handle).getNode(handle);
    
public intgetWhatToShow()
Return a mask describing which node types are presented via the iterator.

      return dtm_iter.getWhatToShow();
    
public org.w3c.dom.NodenextNode()

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.

      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 org.w3c.dom.NodepreviousNode()

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.

      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);