1 2 12 package com.versant.core.jdo.query; 13 14 import com.versant.core.metadata.FieldMetaData; 15 import com.versant.core.metadata.ClassMetaData; 16 import com.versant.core.common.Debug; 17 18 import com.versant.core.common.BindingSupportImpl; 19 20 24 public class FieldNode extends LeafNode { 25 26 public String lexeme; 27 30 public FieldMetaData fmd; 31 35 public boolean useCandidateExtent; 36 37 public boolean resolved; 38 39 public FieldNode() { 40 } 41 42 public FieldNode(Node parent, String lexeme) { 43 this.parent = parent; 44 this.lexeme = lexeme; 45 } 46 47 public Object accept(NodeVisitor visitor, Object [] results) { 48 return visitor.visitFieldNode(this, results); 49 } 50 51 public String toString() { 52 return super.toString() + " " + (fmd != null ? fmd.toString() : lexeme) + " asValue " + asValue; 53 } 54 55 59 public void resolve(QueryParser comp, ClassMetaData cmd, boolean ordering) { 60 if (Debug.DEBUG) System.out.println("### FieldNode.resolve " + this); 61 final boolean fnn = parent instanceof FieldNavNode; 62 if (!ordering) { 63 if (!resolved && !fnn) { 64 VarNode v = comp.findVar(lexeme); 65 Node rep; 66 if (v != null) { 67 if (!v.bound && ((parent instanceof BinaryNode) 71 || (parent instanceof MethodNode && parent.childList == this))) { 72 v.insertVarBindingNode(parent); 73 } else { 74 v.bound = true; 75 if (Debug.DEBUG) { 76 System.out.println("### bound " + this); 77 } 78 } 79 if (v.parent != null) rep = new VarNodeProxy(v); 80 else rep = v; 81 } else { 82 rep = v; 83 } 84 if (rep == null) { 85 ParamNode p = comp.findParam(lexeme); 86 if (p != null && p.parent != null) rep = new ParamNodeProxy(p); 87 else rep = p; 88 } 89 if (rep == null && lexeme.equals("this")) { 90 rep = new ReservedFieldNode(ReservedFieldNode.TYPE_THIS, "this"); 91 rep.resolve(comp, cmd, false); 92 } 93 if (rep != null) { 94 parent.replaceChild(this, rep); 95 return; 96 } 97 } 98 } 99 100 fmd = cmd.getFieldMetaData(lexeme); 101 102 if (fmd == null) { 103 if (parent instanceof FieldNavNode) { 104 FieldNavNode fNN = (FieldNavNode) parent; 105 if (fNN.embedded) { 106 FieldMetaData[] fmds = cmd.fields; 107 for (int i = 0; i < fmds.length; i++) { 108 FieldMetaData fieldMetaData = fmds[i]; 109 if (fieldMetaData.name.equals(fNN.fmd.name + "/" + lexeme)) { 110 fmd = fieldMetaData; 111 break; 112 } 113 } 114 } 115 } 116 } 117 118 if (fmd == null) { 119 parent.replaceChild(this, new AsValueNode(lexeme)); 121 return; 122 } 123 if (fmd == null) { 124 String msg; 125 if (fnn) { 126 msg = "Field '" + lexeme + "' not found on " + 127 cmd.qname; 128 } else { 129 msg = "Identifier '" + lexeme + "' is not a parameter, " + 130 "variable or field of " + cmd.qname; 131 } 132 throw BindingSupportImpl.getInstance().runtime(msg); 133 } 134 135 138 if (fmd.classMetaData != cmd) { 139 cmd = fmd.classMetaData; 140 } 141 } 142 143 public Field visit(MemVisitor visitor, Object obj) { 144 return visitor.visitFieldNode(this, obj); 145 } 146 147 public Object arrive(NodeVisitor v, Object msg) { 148 return v.arriveFieldNode(this, msg); 149 } 150 151 } 152 153 | Popular Tags |