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.value.SequenceExtent; 8 9 12 13 public class Reverser extends UnaryExpression { 14 15 public Reverser(Expression base) { 16 super(base); 17 } 18 19 20 21 public int computeSpecialProperties() { 22 int baseProps = operand.getSpecialProperties(); 23 if ((baseProps & StaticProperty.REVERSE_DOCUMENT_ORDER) != 0) { 24 return (baseProps & 25 (~StaticProperty.REVERSE_DOCUMENT_ORDER)) | 26 StaticProperty.ORDERED_NODESET; 27 } else if ((baseProps & StaticProperty.ORDERED_NODESET) != 0) { 28 return (baseProps & 29 (~StaticProperty.ORDERED_NODESET)) | 30 StaticProperty.REVERSE_DOCUMENT_ORDER; 31 } else { 32 return baseProps; 33 } 34 } 35 36 39 40 public Expression promote(PromotionOffer offer) throws XPathException { 41 Expression exp = offer.accept(this); 42 if (exp != null) { 43 return exp; 44 } else { 45 operand = doPromotion(operand, offer); 46 return this; 47 } 48 } 49 50 public SequenceIterator iterate(XPathContext context) throws XPathException { 51 SequenceIterator forwards = operand.iterate(context); 52 if (forwards instanceof ReversibleIterator) { 53 return ((ReversibleIterator)forwards).getReverseIterator(); 54 } else { 55 SequenceExtent extent = new SequenceExtent(forwards); 56 return extent.reverseIterate(); 57 } 58 } 59 60 public boolean effectiveBooleanValue(XPathContext context) throws XPathException { 61 return operand.effectiveBooleanValue(context); 62 } 63 64 68 69 protected String displayOperator(NamePool pool) { 70 return "reverse order"; 71 } 72 } 73 74 75 | Popular Tags |