1 package net.sf.saxon.pull; 2 3 import net.sf.saxon.trans.XPathException; 4 5 9 public class ElementNameTracker extends PullFilter { 10 11 private int[] namestack = new int[20]; 12 int used = 0; 13 int elementJustEnded = -1; 14 15 public ElementNameTracker(PullProvider base) { 16 super(base); 17 } 18 19 29 30 public int next() throws XPathException { 31 currentEvent = super.next(); 32 if (currentEvent == START_ELEMENT) { 33 int nc = getNameCode(); 34 if (used >= namestack.length) { 35 int[] n2 = new int[used*2]; 36 System.arraycopy(namestack, 0, n2, 0, used); 37 namestack = n2; 38 } 39 namestack[used++] = nc; 40 } else if (currentEvent == END_ELEMENT) { 41 elementJustEnded = namestack[--used]; 42 } 43 return currentEvent; 44 } 45 46 59 60 public int getNameCode() { 61 if (currentEvent == END_ELEMENT) { 62 return elementJustEnded; 63 } else { 64 return super.getNameCode(); 65 } 66 } 67 } 68 69 | Popular Tags |