1 package com.icl.saxon.style; 2 import com.icl.saxon.*; 3 import com.icl.saxon.om.*; 4 import com.icl.saxon.expr.*; 5 import javax.xml.transform.*; 6 import java.util.*; 7 8 14 15 public class GroupActivation implements NodeEnumeration { 16 17 private SAXONGroup group; 18 private NodeEnumeration nodes; 19 private Expression groupkey; 20 private Context context; 21 private NodeInfo next = null; 22 private Value nextValue = null; 23 private NodeInfo current = null; 24 private Value currentValue = null; 25 private int position = 0; 26 27 public GroupActivation(SAXONGroup group, Expression groupkey, NodeEnumeration nodes, Context c) 28 throws XPathException 29 { 30 this.group = group; 31 this.groupkey = groupkey; 32 this.nodes = nodes; 33 this.context = c; 34 this.position = 0; 35 this.current = null; 36 this.currentValue = null; 37 lookAhead(); 38 } 39 40 private void lookAhead() throws XPathException { 41 if (nodes.hasMoreElements()) { 42 next = nodes.nextElement(); 43 context.setCurrentNode(next); 44 context.setContextNode(next); 45 context.setPosition(position+1); 46 nextValue = groupkey.evaluate(context); 47 } else { 48 next = null; 49 } 50 } 51 52 public boolean hasMoreElements() { 53 return next != null; 54 } 55 56 public NodeInfo nextElement() throws XPathException { 57 current = next; 58 currentValue = nextValue; 59 position++; 60 lookAhead(); 61 context.setCurrentNode(current); 62 context.setContextNode(current); 63 context.setPosition(position); 64 return current; 65 } 66 67 public boolean sameAsNext() throws XPathException { 68 if (next==null) return false; 69 return (currentValue.equals(nextValue)); 70 } 71 72 public boolean isSorted() { 73 return nodes.isSorted(); 74 } 75 76 public boolean isReverseSorted() { 77 return nodes.isReverseSorted(); 78 } 79 80 public boolean isPeer() { 81 return nodes.isPeer(); 82 } 83 84 } 85 86 | Popular Tags |