1 28 29 package com.caucho.xpath.pattern; 30 31 import com.caucho.xpath.ExprEnvironment; 32 33 import org.w3c.dom.Node ; 34 import org.w3c.dom.NodeList ; 35 36 39 public class SingleNodeIterator extends NodeIterator implements NodeList { 40 protected Node _node; 41 42 public SingleNodeIterator(ExprEnvironment env, Node node) 43 { 44 super(env); 45 46 _node = node; 47 } 48 49 52 public int getPosition() 53 { 54 return _node == null ? 1 : 0; 55 } 56 59 public boolean hasNext() 60 { 61 return _node != null; 62 } 63 64 67 public Node nextNode() 68 { 69 if (_node != null) { 70 Node next = _node; 71 _node = null; 72 return next; 73 } 74 else 75 return null; 76 } 77 78 81 public int getLength() 82 { 83 return _node != null ? 1 : 0; 84 } 85 86 89 public Node item(int i) 90 { 91 return i == 0 ? _node : null; 92 } 93 94 97 public Object clone() 98 { 99 return new SingleNodeIterator(_env, _node); 100 } 101 } 102 | Popular Tags |