1 /*
2 * Copyright (C) 2002 Carsten Krebs (Team-Konzept GmbH & Co.KG)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 package com.teamkonzept.dom4jb.saxon;
19
20 import java.util.NoSuchElementException;
21
22 import org.w3c.dom.Node;
23
24 import com.teamkonzept.dom4jb.schema.ContentIterator;
25
26 /*** %TODO% der iterator sollte auf dom4jb.dom.Node Objekten arbeiten und sich
27 * das ganze hin u. her gecaste sparen.
28 * --> dom4jb.dom.Node so erweitern, daß man direkt an die Nodes ran kann.
29 */
30 public class DescendantAxisIterator implements ContentIterator {
31
32 private Node nextNode;
33 private Node currNode;
34
35 public DescendantAxisIterator( final Node node ) {
36 this.nextNode = node;
37 this.currNode = null;
38 }
39
40 public boolean hasNext() {
41 if ( nextNode != null ) {
42 return true;
43 }
44
45 nextNode = currNode.getFirstChild();
46 if ( nextNode != null ) {
47 return true;
48 }
49
50 do {
51 nextNode = currNode.getNextSibling();
52 if ( nextNode != null ) {
53 return true;
54 }
55
56 currNode = currNode.getParentNode();
57 } while ( currNode != null );
58
59 nextNode = null;
60 return false;
61 }
62
63 public com.teamkonzept.dom4jb.dom.Node next() {
64 if ( hasNext() ) {
65 currNode = nextNode;
66 nextNode = null;
67 return (com.teamkonzept.dom4jb.dom.Node)currNode;
68 }
69 throw new NoSuchElementException( "end of descendant axis reached!" );
70 }
71 }
This page was automatically generated by Maven