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 UnionIterator extends NodeIterator { 42 private NodeIterator _leftIter; 43 private NodeIterator _rightIter; 44 45 private Node _node; 46 47 53 public UnionIterator(ExprEnvironment env, 54 NodeIterator leftIter, NodeIterator rightIter) 55 throws XPathException 56 { 57 super(env); 58 59 _leftIter = leftIter; 60 _rightIter = rightIter; 61 62 _node = leftIter.nextNode(); 63 if (_node == null) { 64 _leftIter = null; 65 _node = _rightIter.nextNode(); 66 } 67 } 68 69 72 public boolean hasNext() 73 { 74 return _node != null; 75 } 76 77 80 public Node nextNode() 81 throws XPathException 82 { 83 Node next = _node; 84 85 if (next == null) 86 return null; 87 88 if (_leftIter != null) { 89 _node = _leftIter.nextNode(); 90 if (_node == null) { 91 _leftIter = null; 92 _node = _rightIter.nextNode(); 93 } 94 } 95 else 96 _node = _rightIter.nextNode(); 97 98 return next; 99 } 100 101 104 public Object clone() 105 { 106 try { 107 UnionIterator clone; 108 clone = new UnionIterator(_env, 109 (NodeIterator) _leftIter.clone(), 110 (NodeIterator) _rightIter.clone()); 111 112 clone._node = _node; 113 clone._position = _position; 114 115 return clone; 116 } catch (Exception e) { 117 log.log(Level.FINE, e.toString(), e); 118 119 return null; 120 } 121 } 122 } 123 | Popular Tags |