1 5 6 package com.hp.hpl.jena.rdql.parser; 7 8 9 import org.apache.commons.logging.*; 10 11 import com.hp.hpl.jena.graph.query.Expression; 12 import com.hp.hpl.jena.graph.query.IndexValues; 13 import com.hp.hpl.jena.graph.query.Valuator; 14 import com.hp.hpl.jena.graph.query.VariableIndexes; 15 import com.hp.hpl.jena.rdql.Constraint; 16 import com.hp.hpl.jena.rdql.EvalFailureException; 17 import com.hp.hpl.jena.rdql.Query; 18 19 21 22 abstract class ExprNode 23 extends SimpleNode implements 25 Expression , Valuator , Constraint , Expr { 29 static Log log = LogFactory.getLog(ExprNode.class) ; 30 Query query ; 31 VariableIndexes varIndexes ; 32 33 public ExprNode(RDQLParser p, int i) { super(p, i); } 34 public ExprNode(int i) { super(i); } 35 36 37 public boolean isSatisfied(Query q, IndexValues env) 39 { 40 return evalBool( q, env ) ; 41 } 42 43 public void postParse(Query q) 44 { 45 super.postParse(q) ; 46 query = q ; 47 } 48 49 51 public Valuator prepare(VariableIndexes vi) 52 { 53 varIndexes = vi ; 54 if (children != null) 55 { 56 for (int i = 0; i < children.length; ++i) 57 { 58 Object n = children[i]; 59 if ( n instanceof Expression ) 60 { 61 ((Expression)n).prepare(vi); 62 } 63 } 64 } 65 return this ; 68 } 69 70 74 public Object evalObject( IndexValues iv ) 75 { 76 return evalNode( query, iv ) ; 77 } 78 79 83 public boolean evalBool( IndexValues iv ) 84 { 85 return evalBool( query, iv ) ; 86 } 87 88 93 protected boolean evalBool( Query q, IndexValues iv) 94 { 95 NodeValue v = evalNode( q, iv ) ; 96 return v == null ? false : v.getBoolean() ; 97 } 98 99 107 public NodeValue evalNode( Query q, IndexValues env ) 108 { 109 try { 110 return eval(q, env) ; 111 } 112 catch (EvalFailureException e) { 114 return null ; 117 } 118 catch (Exception e) 119 { 120 log.warn("RDQL : general exception!", e) ; 121 return null ; 123 } 124 } 125 126 public boolean isVariable() { return false; } 129 public String getName() { return null; } 131 public boolean isConstant() { return false; } 133 public Object getValue() { return null; } 135 public boolean isApply() { return false; } 137 public String getFun() { return null; } public int argCount() { return 0; } public Expression getArg(int i) { return null; } 140 141 static final String exprBaseURI = "urn:x-jena:expr:" ; 142 protected String constructURI(String className) 143 { 144 if ( className.lastIndexOf('.') > -1 ) 145 className = className.substring(className.lastIndexOf('.')+1) ; 146 return exprBaseURI+className ; 147 } 148 149 public String toString() 152 { 153 return asInfixString() ; 154 } 155 } 156 157 183 | Popular Tags |