1 package net.sf.saxon.expr; 2 import net.sf.saxon.om.Item; 3 import net.sf.saxon.trans.XPathException; 4 import net.sf.saxon.type.ItemType; 5 import net.sf.saxon.type.Type; 6 import net.sf.saxon.value.BooleanValue; 7 8 import java.util.Iterator ; 9 import java.util.List ; 10 11 12 15 16 public class BooleanExpression extends BinaryExpression { 17 18 public BooleanExpression(Expression p1, int operator, Expression p2) { 19 super(p1, operator, p2); 20 } 21 22 25 26 public int computeCardinality() { 27 return StaticProperty.EXACTLY_ONE; 28 } 29 30 33 34 public Item evaluateItem(XPathContext context) throws XPathException { 35 return BooleanValue.get(effectiveBooleanValue(context)); 36 } 37 38 41 42 public boolean effectiveBooleanValue(XPathContext c) throws XPathException { 43 switch(operator) { 44 case Token.AND: 45 return operand0.effectiveBooleanValue(c) && operand1.effectiveBooleanValue(c); 46 47 case Token.OR: 48 return operand0.effectiveBooleanValue(c) || operand1.effectiveBooleanValue(c); 49 50 default: 51 throw new UnsupportedOperationException ("Unknown operator in boolean expression"); 52 } 53 } 54 55 59 60 public ItemType getItemType() { 61 return Type.BOOLEAN_TYPE; 62 } 63 64 71 72 public static void listAndComponents(Expression exp, List list) { 73 if (exp instanceof BooleanExpression && ((BooleanExpression)exp).getOperator() == Token.AND) { 74 for (Iterator iter = exp.iterateSubExpressions(); iter.hasNext();) { 75 listAndComponents((Expression)iter.next(), list); 76 } 77 } else { 78 list.add(exp); 79 } 80 } 81 } 82 83 | Popular Tags |