1 19 20 21 package org.apache.cayenne.exp.parser; 22 23 import java.io.PrintWriter ; 24 25 import org.apache.cayenne.DataObject; 26 import org.apache.cayenne.exp.Expression; 27 import org.apache.cayenne.map.Entity; 28 import org.apache.cayenne.reflect.PropertyUtils; 29 30 public class ASTObjPath extends ASTPath { 31 32 35 ASTObjPath(int id) { 36 super(id); 37 } 38 39 public ASTObjPath() { 40 super(ExpressionParserTreeConstants.JJTOBJPATH); 41 } 42 43 public ASTObjPath(Object value) { 44 super(ExpressionParserTreeConstants.JJTOBJPATH); 45 setPath(value); 46 } 47 48 protected Object evaluateNode(Object o) throws Exception { 49 return (o instanceof DataObject) 50 ? ((DataObject) o).readNestedProperty(path) 51 : (o instanceof Entity) 52 ? evaluateEntityNode((Entity) o) 53 : PropertyUtils.getProperty(o, path); 54 } 55 56 59 public Expression shallowCopy() { 60 ASTObjPath copy = new ASTObjPath(id); 61 copy.path = path; 62 return copy; 63 } 64 65 public void encodeAsString(PrintWriter pw) { 66 pw.print(path); 67 } 68 69 public int getType() { 70 return Expression.OBJ_PATH; 71 } 72 } 73 | Popular Tags |