1 16 19 package org.apache.xml.dtm.ref; 20 21 import org.apache.xml.dtm.DTM; 22 import org.apache.xml.dtm.DTMAxisIterator; 23 import org.apache.xml.utils.IntVector; 24 25 import org.w3c.dom.Node ; 26 27 56 public class DTMAxisIterNodeList extends DTMNodeListBase { 57 private DTM m_dtm; 58 private DTMAxisIterator m_iter; 59 private IntVector m_cachedNodes; 60 private int m_last = -1; 61 private DTMAxisIterNodeList() { 64 } 65 66 70 public DTMAxisIterNodeList(DTM dtm, DTMAxisIterator dtmAxisIterator) { 71 if (dtmAxisIterator == null) { 72 m_last = 0; 73 } else { 74 m_cachedNodes = new IntVector(); 75 m_dtm = dtm; 76 } 77 m_iter = dtmAxisIterator; 78 } 79 80 85 public DTMAxisIterator getDTMAxisIterator() { 86 return m_iter; 87 } 88 89 90 93 102 public Node item(int index) { 103 if (m_iter != null) { 104 int node; 105 int count = m_cachedNodes.size(); 106 107 if (count > index) { 108 node = m_cachedNodes.elementAt(index); 109 return m_dtm.getNode(node); 110 } else if (m_last == -1) { 111 while (((node = m_iter.next()) != DTMAxisIterator.END) 112 && count <= index) { 113 m_cachedNodes.addElement(node); 114 count++; 115 } 116 if (node == DTMAxisIterator.END) { 117 m_last = count; 118 } else { 119 return m_dtm.getNode(node); 120 } 121 } 122 } 123 return null; 124 } 125 126 130 public int getLength() { 131 if (m_last == -1) { 132 int node; 133 while ((node = m_iter.next()) != DTMAxisIterator.END) { 134 m_cachedNodes.addElement(node); 135 } 136 m_last = m_cachedNodes.size(); 137 } 138 return m_last; 139 } 140 } 141 | Popular Tags |