1 2 12 package com.versant.core.ejb.query; 13 14 import com.versant.core.metadata.FieldMetaData; 15 import com.versant.core.metadata.ClassMetaData; 16 17 20 public class PathNode extends Node { 21 22 public static final int WHERE = 1; 23 public static final int SELECT = 2; 24 public static final int GROUP_BY = 3; 25 public static final int ORDER_BY = 4; 26 public static final int AGGREGATE = 5; 27 public static final int CONSTRUCTOR = 6; 28 public static final int JOIN = 7; 29 public static final int COLLECTION_MEMBER = 8; 30 31 private String [] list = new String [4]; 32 private int size; 33 private int parentType; 34 35 private NavBase navBase; 36 private FieldMetaData fmd; 37 38 41 public PathNode(int parentType) { 42 this.parentType = parentType; 43 } 44 45 48 public int getParentType() { 49 return parentType; 50 } 51 52 public void add(String identifier) { 53 if (size == list.length) { 54 String [] a = new String [list.length + 4]; 55 System.arraycopy(list, 0, a, 0, list.length); 56 list = a; 57 } 58 list[size++] = identifier; 59 } 60 61 public String get(int i) { 62 if (i >= size) { 63 throw new ArrayIndexOutOfBoundsException (i + " >= " + size); 64 } 65 return list[i]; 66 } 67 68 public int size() { 69 return size; 70 } 71 72 public Object arrive(NodeVisitor v, Object msg) { 73 return v.arrivePathNode(this, msg); 74 } 75 76 public String getParentTypeString() { 77 switch (parentType) { 78 case WHERE: return "WHERE"; 79 case SELECT: return "SELECT"; 80 case GROUP_BY: return "GROUP_BY"; 81 case ORDER_BY: return "ORDER_BY"; 82 case AGGREGATE: return "AGGREGATE"; 83 case CONSTRUCTOR: return "CONSTRUCTOR"; 84 case JOIN: return "JOIN"; 85 case COLLECTION_MEMBER: return "COLLECTION_MEMBER"; 86 } 87 return "<? parentType " + parentType + " ?>"; 88 } 89 90 public String toStringImp() { 91 if (size == 0) { 92 return "<? no identifiers in PathExpression?>"; 93 } 94 StringBuffer s = new StringBuffer (); 95 s.append(list[0]); 96 for (int i = 1; i < size; i++) { 97 s.append('.'); 98 s.append(list[i]); 99 } 100 if (fmd != null) { 101 s.append('%'); 102 s.append(fmd.getQName()); 103 } else if (navBase != null) { 104 s.append('%'); 105 s.append(navBase.getNavClassMetaData().qname); 106 } 107 return s.toString(); 108 } 109 110 115 public NavBase getNavBase() { 116 return navBase; 117 } 118 119 123 public FieldMetaData getFmd() { 124 return fmd; 125 } 126 127 public void resolve(ResolveContext rc) { 128 if (size == 1) { String name = get(0); 130 navBase = rc.checkIdVarExists(name, this); 131 } else { navBase = rc.resolveJoinPath(this, false, false, size - 1); 133 ClassMetaData cmd = navBase.getNavClassMetaData(); 134 String name = get(size - 1); 135 fmd = cmd.getFieldMetaData(name); 136 if (fmd == null) { 137 throw rc.createUserException("No such field '" + name + 138 "' on " + cmd.qname, this); 139 } 140 } 141 } 142 143 } 144 145 | Popular Tags |