1 4 package gnu.kawa.xml; 5 import gnu.mapping.*; 6 import gnu.lists.*; 7 8 public class Children extends MethodProc 9 { 10 public static final Children children = new Children(); 11 12 public int numArgs() { return 0x1001; } 13 14 public static void children (TreeList tlist, int index, Consumer consumer) 15 { 16 int child = tlist.gotoChildrenStart(index); 17 if (child < 0) 18 return; 19 int limit = tlist.nextDataIndex(index); 20 for (;;) 21 { 22 int ipos = child << 1; 23 int next = tlist.nextNodeIndex(child, limit); 25 int next0=next; 27 if (next == child) 28 next = tlist.nextDataIndex(child); 29 if (next < 0) 30 break; 31 if (consumer instanceof PositionConsumer) 32 ((PositionConsumer) consumer).writePosition(tlist, ipos); 33 else 34 tlist.consumeIRange(child, next, consumer); 35 child = next; 36 } 37 } 38 39 public static void children (Object node, Consumer consumer) 40 { 41 if (node instanceof TreeList) 42 { 43 children((TreeList) node, 0, consumer); 44 } 45 else if (node instanceof SeqPosition && ! (node instanceof TreePosition)) 46 { 47 SeqPosition pos = (SeqPosition) node; 48 if (pos.sequence instanceof TreeList) 49 children((TreeList) pos.sequence, pos.ipos >> 1, consumer); 50 } 51 } 52 53 public void apply (CallContext ctx) 54 { 55 Consumer consumer = ctx.consumer; 56 Object node = ctx.getNextArg(); 57 ctx.lastArg(); 58 if (node instanceof Values) 59 { 60 TreeList tlist = (TreeList) node; 61 int index = 0; 62 for (;;) 63 { 64 int kind = tlist.getNextKind(index << 1); 65 if (kind == Sequence.EOF_VALUE) 66 break; 67 if (kind == Sequence.OBJECT_VALUE) 68 children(tlist.getPosNext(index << 1), consumer); 69 else 70 children(tlist, index, consumer); 71 index = tlist.nextDataIndex(index); 72 } 73 } 74 else 75 children(node, consumer); 76 } 77 } 78 | Popular Tags |