1 16 package org.apache.axis2.om.impl.llom.traverse; 17 18 import org.apache.axis2.om.OMException; 19 import org.apache.axis2.om.OMNode; 20 21 import java.util.Iterator ; 22 23 26 public class OMChildrenIterator implements Iterator { 27 30 protected OMNode currentChild; 31 32 35 protected OMNode lastChild; 36 37 40 protected boolean nextCalled = false; 41 42 45 protected boolean removeCalled = false; 46 47 52 public OMChildrenIterator(OMNode currentChild) { 53 this.currentChild = currentChild; 54 } 55 56 70 public void remove() { 71 if (!nextCalled) { 72 throw new IllegalStateException ( 73 "next method has not yet being called"); 74 } 75 if (removeCalled) { 76 throw new IllegalStateException ("remove has already being called"); 77 } 78 removeCalled = true; 79 80 if (lastChild == null) { 82 throw new OMException("cannot remove a child at this stage!"); 83 } 84 lastChild.detach(); 85 } 86 87 94 public boolean hasNext() { 95 return (currentChild != null); 96 } 97 98 105 public Object next() { 106 nextCalled = true; 107 removeCalled = false; 108 if (hasNext()) { 109 lastChild = currentChild; 110 currentChild = currentChild.getNextSibling(); 111 return lastChild; 112 } 113 return null; 114 } 115 } 116 | Popular Tags |