1 16 19 20 package org.apache.xalan.xsltc.dom; 21 22 import org.apache.xalan.xsltc.NodeIterator; 23 import org.apache.xalan.xsltc.runtime.BasisLibrary; 24 25 30 public abstract class NodeIteratorBase implements NodeIterator { 31 32 35 protected int _last = -1; 36 37 41 protected int _position = 0; 42 43 46 protected int _markedNode; 47 48 51 protected int _startNode = NodeIterator.END; 52 53 56 protected boolean _includeSelf = false; 57 58 61 protected boolean _isRestartable = true; 62 63 66 public void setRestartable(boolean isRestartable) { 67 _isRestartable = isRestartable; 68 } 69 70 75 abstract public NodeIterator setStartNode(int node); 76 77 81 public NodeIterator reset() { 82 final boolean temp = _isRestartable; 83 _isRestartable = true; 84 setStartNode(_includeSelf ? _startNode + 1 : _startNode); 86 _isRestartable = temp; 87 return this; 88 } 89 90 93 public NodeIterator includeSelf() { 94 _includeSelf = true; 95 return this; 96 } 97 98 103 public int getLast() { 104 if (_last == -1) { 105 final int temp = _position; 106 setMark(); 107 reset(); 108 do { 109 _last++; 110 } while (next() != END); 111 gotoMark(); 112 _position = temp; 113 } 114 return _last; 115 } 116 117 120 public int getPosition() { 121 return _position == 0 ? 1 : _position; 122 } 123 124 129 public boolean isReverse() { 130 return false; 131 } 132 133 139 public NodeIterator cloneIterator() { 140 try { 141 final NodeIteratorBase clone = (NodeIteratorBase)super.clone(); 142 clone._isRestartable = false; 143 return clone.reset(); 144 } 145 catch (CloneNotSupportedException e) { 146 BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR, 147 e.toString()); 148 return null; 149 } 150 } 151 152 156 protected final int returnNode(final int node) { 157 _position++; 158 return node; 159 } 160 161 164 protected final NodeIterator resetPosition() { 165 _position = 0; 166 return this; 167 } 168 } 169 | Popular Tags |