1 package org.jaxen.util; 2 3 63 64 import org.jaxen.Navigator; 65 import org.jaxen.UnsupportedAxisException; 66 import org.jaxen.JaxenRuntimeException; 67 68 import java.util.Iterator ; 69 import java.util.NoSuchElementException ; 70 import java.util.Stack ; 71 72 public class DescendantAxisIterator implements Iterator 73 { 74 75 private Stack stack = new Stack (); 76 private Iterator children; 77 private Navigator navigator; 78 79 public DescendantAxisIterator(Object contextNode, 80 Navigator navigator) throws UnsupportedAxisException 81 { 82 this(navigator, navigator.getChildAxisIterator(contextNode)); 83 } 84 85 public DescendantAxisIterator(Navigator navigator, 86 Iterator iterator) 87 { 88 this.navigator = navigator; 89 this.children = iterator; 90 } 91 92 public boolean hasNext() 93 { 94 while (!children.hasNext()) 95 { 96 if (stack.isEmpty()) 97 { 98 return false; 99 } 100 children = (Iterator ) stack.pop(); 101 } 102 return true; 103 } 104 105 public Object next() 106 { 107 try 108 { 109 if (hasNext()) 110 { 111 Object node = children.next(); 112 stack.push(children); 113 children = navigator.getChildAxisIterator(node); 114 return node; 115 } 116 throw new NoSuchElementException (); 117 } 118 catch (UnsupportedAxisException e) 119 { 120 throw new JaxenRuntimeException(e); 121 } 122 } 123 124 public void remove() 125 { 126 throw new UnsupportedOperationException (); 127 } 128 129 } 130 | Popular Tags |