1 28 29 package com.caucho.xpath.pattern; 30 31 import com.caucho.xpath.ExprEnvironment; 32 import com.caucho.xpath.XPathException; 33 34 import org.w3c.dom.Node ; 35 36 import java.util.logging.Level ; 37 38 41 public class NamespaceIterator extends NodeIterator { 42 protected NodeIterator _parentIter; 43 protected AbstractPattern _match; 44 45 protected NamespaceNode _node; 46 protected NamespaceNode _next; 47 48 protected NamespaceIterator(ExprEnvironment env) 49 { 50 super(env); 51 } 52 60 public NamespaceIterator(Node node, 61 NodeIterator parentIter, 62 ExprEnvironment env, 63 AbstractPattern match) 64 throws XPathException 65 { 66 super(env); 67 68 _parentIter = parentIter; 69 _match = match; 70 71 if (parentIter == null) 72 _node = NamespaceNode.create(node); 73 74 _node = findFirstMatchingNode(); 75 _next = _node; 76 } 77 78 81 public boolean hasNext() 82 { 83 if (_next == null) { 84 try { 85 _next = (NamespaceNode) nextNode(); 86 } catch (XPathException e) { 87 log.log(Level.FINE, e.toString(), e); 88 } 89 } 90 91 return _next != null; 92 } 93 94 97 public Node nextNode() 98 throws XPathException 99 { 100 if (_next != null) { 101 _node = _next; 102 _next = null; 103 104 return _node; 105 } 106 107 if (_node != null) { 108 _node = (NamespaceNode) _node.getNextSibling(); 109 _node = findFirstMatchingNode(); 110 } 111 112 _next = null; 113 114 return _node; 115 } 116 117 120 public SelectedNode nextSelectedNode() 121 throws XPathException 122 { 123 Node node = nextNode(); 124 125 return node == null ? null : new SelectedAttribute(node); 126 } 127 128 131 private NamespaceNode findFirstMatchingNode() 132 throws XPathException 133 { 134 while (true) { 135 Node parentNode; 136 137 if (_node != null) { 138 if (_match == null || _match.match(_node, _env)) { 139 _position++; 140 return _node; 141 } 142 else { 143 _node = (NamespaceNode) _node.getNextSibling(); 144 continue; 145 } 146 } 147 148 else if (_parentIter == null || 149 (parentNode = _parentIter.nextNode()) == null) 150 return null; 151 else { 152 _position = 0; 153 _size = 0; 154 _node = NamespaceNode.create(parentNode); 155 } 156 } 157 } 158 159 162 public int getContextSize() 163 { 164 return _position; 165 } 166 167 public Object clone() 168 { 169 return null; 170 } 171 172 public String toString() 173 { 174 return "NamespaceIterator[" + _match + "]"; 175 } 176 } 177 | Popular Tags |