1 16 19 20 package org.apache.xalan.xsltc.dom; 21 22 import org.apache.xalan.xsltc.runtime.BasisLibrary; 23 import org.apache.xml.dtm.DTMAxisIterator; 24 import org.apache.xml.dtm.ref.DTMAxisIteratorBase; 25 26 30 public final class NthIterator extends DTMAxisIteratorBase { 31 private DTMAxisIterator _source; 33 private final int _position; 34 private boolean _ready; 35 36 public NthIterator(DTMAxisIterator source, int n) { 37 _source = source; 38 _position = n; 39 } 40 41 public void setRestartable(boolean isRestartable) { 42 _isRestartable = isRestartable; 43 _source.setRestartable(isRestartable); 44 } 45 46 public DTMAxisIterator cloneIterator() { 47 try { 48 final NthIterator clone = (NthIterator) super.clone(); 49 clone._source = _source.cloneIterator(); clone._isRestartable = false; 51 return clone; 52 } 53 catch (CloneNotSupportedException e) { 54 BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR, 55 e.toString()); 56 return null; 57 } 58 } 59 60 public int next() { 61 if (_ready) { 62 _ready = false; 63 return _source.getNodeByPosition(_position); 64 } 65 return DTMAxisIterator.END; 66 82 } 83 84 public DTMAxisIterator setStartNode(final int node) { 85 if (_isRestartable) { 86 _source.setStartNode(node); 87 _ready = true; 88 } 89 return this; 90 } 91 92 public DTMAxisIterator reset() { 93 _source.reset(); 94 _ready = true; 95 return this; 96 } 97 98 public int getLast() { 99 return 1; 100 } 101 102 public int getPosition() { 103 return 1; 104 } 105 106 public void setMark() { 107 _source.setMark(); 108 } 109 110 public void gotoMark() { 111 _source.gotoMark(); 112 } 113 } 114 | Popular Tags |