1 16 19 package org.apache.xpath.axes; 20 21 import org.apache.xml.dtm.DTM; 22 import org.apache.xml.dtm.DTMAxisIterator; 23 import org.apache.xpath.XPathContext; 24 25 29 public class ReverseAxesWalker extends AxesWalker 30 { 31 32 37 ReverseAxesWalker(LocPathIterator locPathIterator, int axis) 38 { 39 super(locPathIterator, axis); 40 } 41 42 48 public void setRoot(int root) 49 { 50 super.setRoot(root); 51 m_iterator = getDTM(root).getAxisIterator(m_axis); 52 m_iterator.setStartNode(root); 53 } 54 55 60 public void detach() 61 { 62 m_iterator = null; 63 super.detach(); 64 } 65 66 71 protected int getNextNode() 72 { 73 if (m_foundLast) 74 return DTM.NULL; 75 76 int next = m_iterator.next(); 77 78 if (m_isFresh) 79 m_isFresh = false; 80 81 if (DTM.NULL == next) 82 this.m_foundLast = true; 83 84 return next; 85 } 86 87 88 93 public boolean isReverseAxes() 94 { 95 return true; 96 } 97 98 108 119 protected int getProximityPosition(int predicateIndex) 120 { 121 if(predicateIndex < 0) 125 return -1; 126 127 int count = m_proximityPositions[predicateIndex]; 128 129 if (count <= 0) 130 { 131 AxesWalker savedWalker = wi().getLastUsedWalker(); 132 133 try 134 { 135 ReverseAxesWalker clone = (ReverseAxesWalker) this.clone(); 136 137 clone.setRoot(this.getRoot()); 138 139 clone.setPredicateCount(predicateIndex); 140 141 clone.setPrevWalker(null); 142 clone.setNextWalker(null); 143 wi().setLastUsedWalker(clone); 144 145 count++; 147 int next; 148 149 while (DTM.NULL != (next = clone.nextNode())) 150 { 151 count++; 152 } 153 154 m_proximityPositions[predicateIndex] = count; 155 } 156 catch (CloneNotSupportedException cnse) 157 { 158 159 } 161 finally 162 { 163 wi().setLastUsedWalker(savedWalker); 164 } 165 } 166 167 return count; 168 } 169 170 175 protected void countProximityPosition(int i) 176 { 177 if (i < m_proximityPositions.length) 178 m_proximityPositions[i]--; 179 } 180 181 190 public int getLastPos(XPathContext xctxt) 191 { 192 193 int count = 0; 194 AxesWalker savedWalker = wi().getLastUsedWalker(); 195 196 try 197 { 198 ReverseAxesWalker clone = (ReverseAxesWalker) this.clone(); 199 200 clone.setRoot(this.getRoot()); 201 202 clone.setPredicateCount(this.getPredicateCount() - 1); 203 204 clone.setPrevWalker(null); 205 clone.setNextWalker(null); 206 wi().setLastUsedWalker(clone); 207 208 int next; 211 212 while (DTM.NULL != (next = clone.nextNode())) 213 { 214 count++; 215 } 216 } 217 catch (CloneNotSupportedException cnse) 218 { 219 220 } 222 finally 223 { 224 wi().setLastUsedWalker(savedWalker); 225 } 226 227 return count; 228 } 229 230 237 public boolean isDocOrdered() 238 { 239 return false; } 241 242 243 protected DTMAxisIterator m_iterator; 244 } 245 | Popular Tags |