1 16 19 20 package org.apache.xalan.xsltc.dom; 21 22 import org.apache.xml.dtm.DTMAxisIterator; 23 import org.apache.xml.dtm.ref.DTMAxisIteratorBase; 24 import org.apache.xalan.xsltc.util.IntegerArray; 25 26 32 public final class CachedNodeListIterator extends DTMAxisIteratorBase { 33 34 37 private DTMAxisIterator _source; 38 private IntegerArray _nodes = new IntegerArray(); 39 private int _numCachedNodes = 0; 40 private int _index = 0; 41 private boolean _isEnded = false; 42 43 public CachedNodeListIterator(DTMAxisIterator source) { 44 _source = source; 45 } 46 47 public void setRestartable(boolean isRestartable) { 48 } 51 52 public DTMAxisIterator setStartNode(int node) { 53 if (_isRestartable) { 54 _startNode = node; 55 _source.setStartNode(node); 56 resetPosition(); 57 58 _isRestartable = false; 59 } 60 return this; 61 } 62 63 public int next() { 64 return getNode(_index++); 65 } 66 67 public int getPosition() { 68 return _index == 0 ? 1 : _index; 69 } 70 71 public int getNodeByPosition(int pos) { 72 return getNode(pos); 73 } 74 75 public int getNode(int index) { 76 if (index < _numCachedNodes) { 77 return _nodes.at(index); 78 } 79 else if (!_isEnded){ 80 int node = _source.next(); 81 if (node != END) { 82 _nodes.add(node); 83 _numCachedNodes++; 84 } 85 else { 86 _isEnded = true; 87 } 88 return node; 89 } 90 else 91 return END; 92 } 93 94 public DTMAxisIterator cloneIterator() { 95 ClonedNodeListIterator clone = new ClonedNodeListIterator(this); 96 return clone; 97 } 98 99 public DTMAxisIterator reset() { 100 _index = 0; 101 return this; 102 } 103 104 public void setMark() { 105 _source.setMark(); 106 } 107 108 public void gotoMark() { 109 _source.gotoMark(); 110 } 111 } 112 | Popular Tags |