1 package com.genimen.djeneric.repository.oql.core.nodes; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 6 import com.genimen.djeneric.repository.oql.core.DjOqlParserEngine; 7 import com.genimen.djeneric.repository.oql.core.MatchException; 8 import com.genimen.djeneric.repository.oql.core.ParseException; 9 import com.genimen.djeneric.repository.oql.core.SimpleNode; 10 11 public class PropertyOrFunctionNode extends SimpleNode implements ValueExpression 12 { 13 boolean _isFunction = false; 14 15 public PropertyOrFunctionNode(int i) 16 { 17 super(i); 18 } 19 20 public PropertyOrFunctionNode(DjOqlParserEngine p, int i) 21 { 22 super(p, i); 23 } 24 25 public String getName() 26 { 27 if (_isFunction) return "function"; 28 return "property"; 29 } 30 31 public String toString() 32 { 33 return getName(); 34 } 35 36 public boolean isFunction() 37 { 38 return _isFunction; 39 } 40 41 public void setFunction(boolean b) 42 { 43 _isFunction = b; 44 } 45 46 public Object [] getParams() 47 { 48 ArrayList paramList = new ArrayList (); 49 for (int i = 1; i < getChildCount(); i++) 50 { 51 paramList.add(getChild(i)); 52 } 53 return paramList.toArray(new Object [0]); 54 } 55 56 public void translate(StringBuffer result, HashMap path2AliasMapping) throws ParseException 57 { 58 appendOpenBrackets(result); 59 if (isFunction()) 60 { 61 result.append(getChild(0).toString()); 62 63 result.append("("); 65 for (int i = 1; i < getChildCount(); i++) 66 { 67 getChild(i).translate(result, path2AliasMapping); 68 if (i != getChildCount() - 1) result.append(", "); 69 } 70 result.append(")"); 71 } 72 else super.translate(result, path2AliasMapping); 73 appendCloseBrackets(result); 74 } 75 76 public Object getValue(MatchingContext context) throws MatchException 77 { 78 if (isFunction()) 79 { 80 throw new MatchException("Functions not supported in OQL where clause"); 81 } 82 else 83 { 84 ValueExpression prop = (ValueExpression) getChild(0); 85 return prop.getValue(context); 86 } 87 } 88 89 protected Object evalFunction(Object obj, MatchingContext context) throws Exception 90 { 91 throw new MatchException("Functions not supported in OQL where clause"); 92 } 93 94 } | Popular Tags |