001/* 002 * Copyright (c) 2000 World Wide Web Consortium, 003 * (Massachusetts Institute of Technology, Institut National de 004 * Recherche en Informatique et en Automatique, Keio University). All 005 * Rights Reserved. This program is distributed under the W3C's Software 006 * Intellectual Property License. This program is distributed in the 007 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even 008 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 009 * PURPOSE. 010 * See W3C License http://www.w3.org/Consortium/Legal/ for more details. 011 */ 012 013package org.w3c.dom.traversal; 014 015import org.w3c.dom.Node; 016import org.w3c.dom.DOMException; 017 018/** 019 * <code>Iterators</code> are used to step through a set of nodes, e.g. the 020 * set of nodes in a <code>NodeList</code>, the document subtree governed by 021 * a particular <code>Node</code>, the results of a query, or any other set 022 * of nodes. The set of nodes to be iterated is determined by the 023 * implementation of the <code>NodeIterator</code>. DOM Level 2 specifies a 024 * single <code>NodeIterator</code> implementation for document-order 025 * traversal of a document subtree. Instances of these iterators are created 026 * by calling <code>DocumentTraversal</code> 027 * <code>.createNodeIterator()</code>. 028 * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>Document Object Model (DOM) Level 2 Traversal and Range Specification</a>. 029 * @since DOM Level 2 030 */ 031public interface NodeIterator { 032 /** 033 * The root node of the <code>NodeIterator</code>, as specified when it 034 * was created. 035 */ 036 public Node getRoot(); 037 038 /** 039 * This attribute determines which node types are presented via the 040 * iterator. The available set of constants is defined in the 041 * <code>NodeFilter</code> interface. Nodes not accepted by 042 * <code>whatToShow</code> will be skipped, but their children may still 043 * be considered. Note that this skip takes precedence over the filter, 044 * if any. 045 */ 046 public int getWhatToShow(); 047 048 /** 049 * The <code>NodeFilter</code> used to screen nodes. 050 */ 051 public NodeFilter getFilter(); 052 053 /** 054 * The value of this flag determines whether the children of entity 055 * reference nodes are visible to the iterator. If false, they and 056 * their descendants will be rejected. Note that this rejection takes 057 * precedence over <code>whatToShow</code> and the filter. Also note 058 * that this is currently the only situation where 059 * <code>NodeIterators</code> may reject a complete subtree rather than 060 * skipping individual nodes. 061 * <br> 062 * <br> To produce a view of the document that has entity references 063 * expanded and does not expose the entity reference node itself, use 064 * the <code>whatToShow</code> flags to hide the entity reference node 065 * and set <code>expandEntityReferences</code> to true when creating the 066 * iterator. To produce a view of the document that has entity reference 067 * nodes but no entity expansion, use the <code>whatToShow</code> flags 068 * to show the entity reference node and set 069 * <code>expandEntityReferences</code> to false. 070 */ 071 public boolean getExpandEntityReferences(); 072 073 /** 074 * Returns the next node in the set and advances the position of the 075 * iterator in the set. After a <code>NodeIterator</code> is created, 076 * the first call to <code>nextNode()</code> returns the first node in 077 * the set. 078 * @return The next <code>Node</code> in the set being iterated over, or 079 * <code>null</code> if there are no more members in that set. 080 * @exception DOMException 081 * INVALID_STATE_ERR: Raised if this method is called after the 082 * <code>detach</code> method was invoked. 083 */ 084 public Node nextNode() 085 throws DOMException; 086 087 /** 088 * Returns the previous node in the set and moves the position of the 089 * <code>NodeIterator</code> backwards in the set. 090 * @return The previous <code>Node</code> in the set being iterated over, 091 * or <code>null</code> if there are no more members in that set. 092 * @exception DOMException 093 * INVALID_STATE_ERR: Raised if this method is called after the 094 * <code>detach</code> method was invoked. 095 */ 096 public Node previousNode() 097 throws DOMException; 098 099 /** 100 * Detaches the <code>NodeIterator</code> from the set which it iterated 101 * over, releasing any computational resources and placing the iterator 102 * in the INVALID state. After <code>detach</code> has been invoked, 103 * calls to <code>nextNode</code> or <code>previousNode</code> will 104 * raise the exception INVALID_STATE_ERR. 105 */ 106 public void detach(); 107 108}