1 16 package org.apache.myfaces.util; 17 18 import javax.faces.component.UIComponent; 19 import java.util.Iterator ; 20 import java.util.NoSuchElementException ; 21 import java.util.Stack ; 22 23 30 public class ViewIterator 31 implements Iterator 32 { 33 private UIComponent _next = null; 35 private boolean _mayHaveNext = true; 36 private UIComponent _current = null; 37 private Stack _stack = new Stack (); 38 39 42 public ViewIterator(UIComponent root) 43 { 44 _next = root; 45 _current = null; 46 } 47 48 public boolean hasNext() 49 { 50 return getNext() != null; 51 } 52 53 57 public Object next() 58 { 59 if (!hasNext()) 60 { 61 throw new NoSuchElementException (); 62 } 63 _current = _next; 64 _next = null; 65 return _current; 66 } 67 68 private UIComponent getNext() 69 { 70 if (_next == null && _mayHaveNext) 71 { 72 Iterator children = _current.getFacetsAndChildren(); 74 if (children.hasNext()) 75 { 76 _next = (UIComponent)children.next(); 77 _stack.push(children); 79 } 80 else 81 { 82 for (;;) 84 { 85 if (_stack.empty()) 86 { 87 _next = null; 88 _mayHaveNext = false; 89 break; 90 } 91 92 Iterator currentSiblings = (Iterator )_stack.peek(); 93 if (currentSiblings.hasNext()) 94 { 95 _next = (UIComponent)currentSiblings.next(); 96 break; 97 } 98 else 99 { 100 _stack.pop(); 101 } 102 } 103 } 104 } 105 return _next; 106 } 107 108 public void remove() 109 { 110 throw new UnsupportedOperationException (this.getClass().getName() + " UnsupportedOperationException"); 111 } 112 } 113 | Popular Tags |