1 package net.sf.saxon.expr; 2 import net.sf.saxon.om.Item; 3 import net.sf.saxon.sort.AtomicComparer; 4 import net.sf.saxon.trans.DynamicError; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.type.ItemType; 7 import net.sf.saxon.type.Type; 8 import net.sf.saxon.value.AtomicValue; 9 import net.sf.saxon.value.BooleanValue; 10 import net.sf.saxon.ConversionContext; 11 12 import java.util.Comparator ; 13 14 15 20 21 public class SingletonComparison extends BinaryExpression { 22 23 private AtomicComparer comparer; 24 25 public SingletonComparison(Expression p1, int operator, Expression p2) { 26 super(p1, operator, p2); 27 } 28 29 public void setComparator(Comparator comp, ConversionContext conversion) { 30 if (comp instanceof AtomicComparer) { 31 comparer = (AtomicComparer)comp; 32 } else { 33 comparer = new AtomicComparer(comp, conversion); 34 } 35 } 36 37 40 41 public int computeCardinality() { 42 return StaticProperty.EXACTLY_ONE; 43 } 44 45 49 50 public ItemType getItemType() { 51 return Type.BOOLEAN_TYPE; 52 } 53 54 59 60 public Item evaluateItem(XPathContext context) throws XPathException { 61 return BooleanValue.get(effectiveBooleanValue(context)); 62 } 63 64 69 70 public boolean effectiveBooleanValue(XPathContext context) throws XPathException { 71 AtomicValue v1 = (AtomicValue)operand0.evaluateItem(context); 72 if (v1==null) return false; 73 AtomicValue v2 = (AtomicValue)operand1.evaluateItem(context); 74 if (v2==null) return false; 75 76 try { 77 return GeneralComparison.compare(v1, operator, v2, comparer, context); 78 } catch (DynamicError e) { 79 if (e.getXPathContext() == null) { 81 e.setXPathContext(context); 82 } 83 if (e.getLocator() == null) { 84 e.setLocator(this); 85 } 86 throw e; 87 } 88 } 89 90 protected String displayOperator() { 91 return "singleton " + super.displayOperator(); 92 } 93 94 } 95 96 | Popular Tags |