1 56 package org.objectstyle.cayenne.exp.parser; 57 58 import java.io.PrintWriter ; 59 import java.util.Map ; 60 61 import org.objectstyle.cayenne.DataObject; 62 import org.objectstyle.cayenne.ObjectId; 63 import org.objectstyle.cayenne.exp.Expression; 64 import org.objectstyle.cayenne.map.Entity; 65 66 72 public class ASTDbPath extends ASTPath { 73 ASTDbPath(int id) { 74 super(id); 75 } 76 77 public ASTDbPath() { 78 super(ExpressionParserTreeConstants.JJTDBPATH); 79 } 80 81 public ASTDbPath(Object value) { 82 super(ExpressionParserTreeConstants.JJTDBPATH); 83 setPath(value); 84 } 85 86 protected Object evaluateNode(Object o) throws Exception { 87 89 if (o instanceof Entity) { 90 return evaluateEntityNode((Entity) o); 91 } 92 93 Map map = toMap(o); 94 return (map != null) ? map.get(path) : null; 95 } 96 97 protected Map toMap(Object o) { 98 if (o instanceof Map ) { 99 return (Map ) o; 100 } 101 else if (o instanceof ObjectId) { 102 return ((ObjectId) o).getIdSnapshot(); 103 } 104 else if (o instanceof DataObject) { 105 DataObject dataObject = (DataObject) o; 106 107 ObjectId oid = dataObject.getObjectId(); 110 return (oid != null) ? oid.getIdSnapshot() : null; 111 } 112 else { 113 return null; 114 } 115 } 116 117 120 public Expression shallowCopy() { 121 ASTDbPath copy = new ASTDbPath(id); 122 copy.path = path; 123 return copy; 124 } 125 126 public void encodeAsString(PrintWriter pw) { 127 pw.print("db:"); 128 pw.print(path); 129 } 130 131 public int getType() { 132 return Expression.DB_PATH; 133 } 134 } 135 | Popular Tags |