1 5 6 package com.hp.hpl.jena.rdql.parser; 7 8 9 import java.io.PrintWriter ; 10 import com.hp.hpl.jena.graph.query.IndexValues; 11 import com.hp.hpl.jena.graph.query.Expression ; 12 import com.hp.hpl.jena.rdql.*; 13 14 21 22 26 27 public class Q_LogicalOr extends ExprNode implements Expr, ExprBoolean 28 { 29 Expr left ; 30 Expr right ; 31 32 private String printName = "or" ; 33 private String opSymbol = "||" ; 34 35 Q_LogicalOr(int id) { super(id); } 36 37 Q_LogicalOr(RDQLParser p, int id) { super(p, id); } 38 39 public NodeValue eval(Query q, IndexValues env) 40 { 41 NodeValue x = left.eval(q, env) ; 42 NodeValue y = right.eval(q, env) ; 43 44 if ( ! x.isBoolean() ) 45 throw new EvalTypeException("Q_LogicalOr: Wanted a boolean: "+x) ; 46 if ( ! y.isBoolean() ) 47 throw new EvalTypeException("Q_LogicalOr: Wanted a boolean: "+y) ; 48 49 NodeValueSettable result ; 50 if ( x instanceof NodeValueSettable ) 51 result = (NodeValueSettable)x ; 52 else if ( y instanceof NodeValueSettable ) 53 result = (NodeValueSettable)y ; 54 else 55 result = new WorkingVar() ; 56 57 boolean b = (x.getBoolean() || y.getBoolean()) ; 58 result.setBoolean(b) ; 59 return result ; 60 } 61 62 public void jjtClose() 63 { 64 int n = jjtGetNumChildren() ; 65 if ( n != 2 ) 66 throw new QueryException("Q_LogicalOr: Wrong number of children: "+n) ; 67 68 left = (Expr)jjtGetChild(0) ; 69 right = (Expr)jjtGetChild(1) ; 70 } 71 72 75 public boolean isApply() { return true ; } 76 public String getFun() { return super.constructURI(this.getClass().getName()) ; } 77 public int argCount() { return 2; } 78 public Expression getArg(int i) 79 { 80 if ( i == 0 && left instanceof Expression ) 81 return (Expression)left ; 82 if ( i == 1 && right instanceof Expression ) 83 return (Expression)right ; 84 return null; 85 } 86 87 public String asInfixString() 88 { 89 return QueryPrintUtils.asInfixString2(left, right, printName, opSymbol) ; 90 } 91 92 public String asPrefixString() 93 { 94 return QueryPrintUtils.asPrefixString(left, right, printName, opSymbol) ; 95 } 96 97 public void print(PrintWriter pw, int level) 98 { 99 QueryPrintUtils.print(pw, left, right, printName, opSymbol, level) ; 100 } 101 102 public String toString() 103 { 104 return asInfixString() ; 105 } 106 } 107 108 134 | Popular Tags |