1 56 57 package org.objectstyle.cayenne.exp.parser; 58 59 import java.io.PrintWriter ; 60 61 import org.apache.commons.beanutils.PropertyUtils; 62 import org.objectstyle.cayenne.DataObject; 63 import org.objectstyle.cayenne.exp.Expression; 64 import org.objectstyle.cayenne.map.Entity; 65 66 public class ASTObjPath extends ASTPath { 67 68 71 ASTObjPath(int id) { 72 super(id); 73 } 74 75 public ASTObjPath() { 76 super(ExpressionParserTreeConstants.JJTOBJPATH); 77 } 78 79 public ASTObjPath(Object value) { 80 super(ExpressionParserTreeConstants.JJTOBJPATH); 81 setPath(value); 82 } 83 84 protected Object evaluateNode(Object o) throws Exception { 85 return (o instanceof DataObject) 86 ? ((DataObject) o).readNestedProperty(path) 87 : (o instanceof Entity) 88 ? evaluateEntityNode((Entity) o) 89 : PropertyUtils.getProperty(o, path); 90 } 91 92 95 public Expression shallowCopy() { 96 ASTObjPath copy = new ASTObjPath(id); 97 copy.path = path; 98 return copy; 99 } 100 101 public void encodeAsString(PrintWriter pw) { 102 pw.print(path); 103 } 104 105 public int getType() { 106 return Expression.OBJ_PATH; 107 } 108 } 109 | Popular Tags |