1 16 19 package org.apache.xalan.transformer; 20 21 import java.util.Hashtable ; 22 import java.util.Vector ; 23 24 import javax.xml.transform.TransformerException ; 25 26 import org.apache.xalan.templates.ElemNumber; 27 import org.apache.xml.dtm.DTM; 28 import org.apache.xpath.NodeSetDTM; 29 import org.apache.xpath.XPathContext; 30 31 38 public class CountersTable extends Hashtable 39 { 40 41 44 public CountersTable(){} 45 46 55 Vector getCounters(ElemNumber numberElem) 56 { 57 58 Vector counters = (Vector ) this.get(numberElem); 59 60 return (null == counters) ? putElemNumber(numberElem) : counters; 61 } 62 63 72 Vector putElemNumber(ElemNumber numberElem) 73 { 74 75 Vector counters = new Vector (); 76 77 this.put(numberElem, counters); 78 79 return counters; 80 } 81 82 85 transient private NodeSetDTM m_newFound; 86 87 95 void appendBtoFList(NodeSetDTM flist, NodeSetDTM blist) 96 { 97 98 int n = blist.size(); 99 100 for (int i = (n - 1); i >= 0; i--) 101 { 102 flist.addElement(blist.item(i)); 103 } 104 } 105 106 108 109 transient int m_countersMade = 0; 110 111 123 public int countNode(XPathContext support, ElemNumber numberElem, int node) 124 throws TransformerException 125 { 126 127 int count = 0; 128 Vector counters = getCounters(numberElem); 129 int nCounters = counters.size(); 130 131 int target = numberElem.getTargetNode(support, node); 134 135 if (DTM.NULL != target) 136 { 137 for (int i = 0; i < nCounters; i++) 138 { 139 Counter counter = (Counter) counters.elementAt(i); 140 141 count = counter.getPreviouslyCounted(support, target); 142 143 if (count > 0) 144 return count; 145 } 146 147 count = 0; 154 if (m_newFound == null) 155 m_newFound = new NodeSetDTM(support.getDTMManager()); 156 157 for (; DTM.NULL != target; 158 target = numberElem.getPreviousNode(support, target)) 159 { 160 161 if (0 != count) 165 { 166 for (int i = 0; i < nCounters; i++) 167 { 168 Counter counter = (Counter) counters.elementAt(i); 169 int cacheLen = counter.m_countNodes.size(); 170 171 if ((cacheLen > 0) 172 && (counter.m_countNodes.elementAt(cacheLen 173 - 1) == target)) 174 { 175 count += (cacheLen + counter.m_countNodesStartCount); 176 177 if (cacheLen > 0) 178 appendBtoFList(counter.m_countNodes, m_newFound); 179 180 m_newFound.removeAllElements(); 181 182 return count; 183 } 184 } 185 } 186 187 m_newFound.addElement(target); 188 189 count++; 190 } 191 192 Counter counter = new Counter(numberElem, new NodeSetDTM(support.getDTMManager())); 195 196 m_countersMade++; 198 appendBtoFList(counter.m_countNodes, m_newFound); 199 m_newFound.removeAllElements(); 200 counters.addElement(counter); 201 } 202 203 return count; 204 } 205 } 206 | Popular Tags |