1 16 package org.apache.axis2.om.impl.llom.traverse; 17 18 import org.apache.axis2.om.OMAttribute; 19 import org.apache.axis2.om.OMElement; 20 import org.apache.axis2.om.OMNode; 21 22 import javax.xml.namespace.QName ; 23 24 27 public class OMChildrenWithSpecificAttributeIterator 28 extends OMChildrenIterator { 29 32 private QName attributeName; 33 34 37 private String attributeValue; 38 39 42 private boolean detach; 43 44 52 public OMChildrenWithSpecificAttributeIterator(OMNode currentChild, 53 QName attributeName, String attributeValue, boolean detach) { 54 super(currentChild); 55 this.attributeName = attributeName; 56 this.attributeValue = attributeValue; 57 this.detach = detach; 58 } 59 60 65 public boolean hasNext() { 66 67 if (currentChild == null) { 69 return false; 70 } 71 boolean isMatchingNodeFound = false; 72 boolean needToMoveForward = true; 73 74 while (needToMoveForward) { 76 77 if (currentChild instanceof OMElement) { 79 OMAttribute attr = 80 ((OMElement) currentChild).getFirstAttribute( 81 attributeName); 82 if ((attr != null) 83 && attr.getValue().equalsIgnoreCase(attributeValue)) { 84 isMatchingNodeFound = true; 85 needToMoveForward = false; 86 } else { 87 currentChild = currentChild.getNextSibling(); 88 needToMoveForward = !(currentChild == null); 89 } 90 } else { 91 92 currentChild = currentChild.getNextSibling(); 94 needToMoveForward = !(currentChild == null); 95 } 96 } 97 return isMatchingNodeFound; 98 } 99 100 105 public Object next() { 106 Object o = super.next(); 107 if ((o != null) && detach) { 108 ((OMElement) o).detach(); 109 } 110 return o; 111 } 112 } 113 | Popular Tags |