1 5 6 package com.hp.hpl.jena.rdql.parser; 7 8 9 10 import java.io.PrintWriter ; 11 import com.hp.hpl.jena.graph.Node ; 12 import com.hp.hpl.jena.graph.query.IndexValues; 13 import com.hp.hpl.jena.graph.query.Expression; 14 import com.hp.hpl.jena.rdql.*; 15 16 public class Q_StringEqual extends ExprNode implements Expr, ExprBoolean 17 { 18 Expr left ; 19 Expr right ; 20 21 static protected boolean enableRDFLiteralSameValueAs = true ; 22 23 protected static String printName = "str=" ; 24 protected static String opSymbol = "eq" ; 25 26 Q_StringEqual(int id) { super(id); } 27 28 Q_StringEqual(RDQLParser p, int id) { super(p, id); } 29 30 protected boolean rawEval(NodeValue x, NodeValue y) 31 { 32 39 43 if ( enableRDFLiteralSameValueAs ) 44 { 45 if ( x.isNode() && x.getNode().isLiteral() && 46 y.isNode() && y.getNode().isLiteral() ) 47 { 48 Node xNode = x.getNode() ; 49 Node yNode = y.getNode() ; 50 return xNode.sameValueAs(yNode) ; 51 } 52 } 53 54 String xx = x.valueString() ; 56 String yy = y.valueString() ; 57 58 return (xx.equals(yy)) ; 59 } 60 61 public NodeValue eval(Query q, IndexValues env) 62 { 63 NodeValue x = left.eval(q, env) ; 64 NodeValue y = right.eval(q, env) ; 65 66 boolean b = rawEval(x, y) ; 67 68 NodeValueSettable result ; 69 if ( x instanceof NodeValueSettable ) 70 result = (NodeValueSettable)x ; 71 else if ( y instanceof NodeValueSettable ) 72 result = (NodeValueSettable)y ; 73 else 74 result = new WorkingVar() ; 75 76 result.setBoolean(b) ; 77 return result ; 78 } 79 80 public void jjtClose() 81 { 82 int n = jjtGetNumChildren() ; 83 if ( n != 2 ) 84 throw new QueryException("Q_StringEqual: Wrong number of children: "+n) ; 85 86 left = (Expr)jjtGetChild(0) ; 87 right = (Expr)jjtGetChild(1) ; 88 } 89 90 92 public boolean isApply() { return true ; } 93 public String getFun() { return this.getClass().getName() ; } public int argCount() { return 2; } 95 public Expression getArg(int i) 96 { 97 if ( i == 0 && left instanceof Expression ) 98 return (Expression)left ; 99 if ( i == 1 && right instanceof Expression ) 100 return (Expression)right ; 101 return null; 102 } 103 104 106 public String asInfixString() 107 { 108 return QueryPrintUtils.asInfixString2(left, right, printName, opSymbol) ; 109 } 110 111 public String asPrefixString() 112 { 113 return QueryPrintUtils.asPrefixString(left, right, printName, opSymbol) ; 114 } 115 116 public void print(PrintWriter pw, int level) 117 { 118 QueryPrintUtils.print(pw, left, right, printName, opSymbol, level) ; 119 } 120 121 public String toString() 122 { 123 return asInfixString() ; 124 } 125 } 126 127 153 | Popular Tags |