1 16 package org.apache.axis2.om.impl.llom.traverse; 17 18 import org.apache.axis2.om.OMNode; 19 import org.apache.axis2.om.impl.llom.OMElementImpl; 20 21 import javax.xml.namespace.QName ; 22 23 26 public class OMChildrenQNameIterator extends OMChildrenIterator { 27 30 private QName givenQName; 31 32 35 private boolean needToMoveForward = true; 36 37 40 private boolean isMatchingNodeFound = false; 41 42 48 public OMChildrenQNameIterator(OMNode currentChild, QName givenQName) { 49 super(currentChild); 50 this.givenQName = givenQName; 51 } 52 53 60 public boolean hasNext() { 61 while (needToMoveForward) { 62 if (currentChild != null) { 63 64 if ((currentChild instanceof OMElementImpl) 66 && (isQNamesMatch( 67 ((OMElementImpl) currentChild).getQName(), 68 this.givenQName))) { 69 isMatchingNodeFound = true; 70 needToMoveForward = false; 71 } else { 72 73 currentChild = currentChild.getNextSibling(); 75 isMatchingNodeFound = needToMoveForward = !(currentChild 76 == null); 77 } 78 } else { 79 needToMoveForward = false; 80 } 81 } 82 return isMatchingNodeFound; 83 } 84 85 92 public Object next() { 93 94 needToMoveForward = true; 96 isMatchingNodeFound = false; 97 nextCalled = true; 98 removeCalled = false; 99 lastChild = currentChild; 100 currentChild = currentChild.getNextSibling(); 101 return lastChild; 102 } 103 104 113 private boolean isQNamesMatch(QName elementQName, QName qNameToBeMatched) { 114 115 if (qNameToBeMatched == null) { 117 return true; 118 } 119 120 boolean localNameMatch = 122 (qNameToBeMatched.getLocalPart() == null) 123 || (qNameToBeMatched.getLocalPart() == "") 124 || ((elementQName != null) 125 && elementQName.getLocalPart().equalsIgnoreCase( 126 qNameToBeMatched.getLocalPart())); 127 boolean namespaceURIMatch = 128 (qNameToBeMatched.getNamespaceURI() == null) 129 || (qNameToBeMatched.getNamespaceURI() == "") 130 || ((elementQName != null) 131 && elementQName.getNamespaceURI().equalsIgnoreCase( 132 qNameToBeMatched.getNamespaceURI())); 133 return localNameMatch && namespaceURIMatch; 134 } 135 } 136 | Popular Tags |