1 package net.sf.saxon.sort; 2 3 import net.sf.saxon.expr.*; 4 import net.sf.saxon.om.NamePool; 5 import net.sf.saxon.om.SequenceIterator; 6 import net.sf.saxon.trans.XPathException; 7 import net.sf.saxon.type.ItemType; 8 9 13 public class DocumentSorter extends UnaryExpression { 14 15 private NodeOrderComparer comparer; 16 17 public DocumentSorter(Expression base) { 18 super(base); 19 int props = base.getSpecialProperties(); 20 if (((props & StaticProperty.CONTEXT_DOCUMENT_NODESET) != 0) || 21 (props & StaticProperty.SINGLE_DOCUMENT_NODESET) != 0) { 22 comparer = LocalOrderComparer.getInstance(); 23 } else { 24 comparer = GlobalOrderComparer.getInstance(); 25 } 26 } 27 28 public Expression simplify(StaticContext env) throws XPathException { 29 operand = operand.simplify(env); 30 if ((operand.getSpecialProperties() & StaticProperty.ORDERED_NODESET) != 0) { 31 return operand; 33 } 34 return this; 35 } 36 37 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 38 operand = operand.optimize(opt, env, contextItemType); 39 if ((operand.getSpecialProperties() & StaticProperty.ORDERED_NODESET) != 0) { 40 return operand; 42 } 43 return this; 44 } 45 46 47 public int computeSpecialProperties() { 48 return operand.getSpecialProperties() | StaticProperty.ORDERED_NODESET; 49 } 50 51 54 55 public Expression promote(PromotionOffer offer) throws XPathException { 56 Expression exp = offer.accept(this); 57 if (exp != null) { 58 return exp; 59 } else { 60 operand = doPromotion(operand, offer); 61 return this; 62 } 63 } 64 65 public SequenceIterator iterate(XPathContext context) throws XPathException { 66 return new DocumentOrderIterator(operand.iterate(context), comparer); 67 } 68 69 public boolean effectiveBooleanValue(XPathContext context) throws XPathException { 70 return operand.effectiveBooleanValue(context); 71 } 72 73 77 78 protected String displayOperator(NamePool pool) { 79 if (comparer instanceof LocalOrderComparer) { 80 return "intra-document sort and deduplicate"; 81 } else { 82 return "sort and deduplicate"; 83 } 84 } 85 86 } 87 88 89 | Popular Tags |