1 23 24 29 30 package com.sun.jdo.spi.persistence.support.sqlstore.query.jqlc; 31 32 import persistence.antlr.Token; 33 import persistence.antlr.CommonAST; 34 import persistence.antlr.collections.AST; 35 import persistence.antlr.ASTFactory; 36 37 import com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.Type; 38 import com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc; 39 40 54 public class JQLAST 55 extends CommonAST 56 { 57 58 private static char SEPARATOR = '\n'; 59 60 61 private static String INDENT = " "; 63 protected int line = 0; 64 protected int column = 0; 65 protected Type jqlType; 66 protected RetrieveDesc rd; 67 protected Object value; 68 69 public JQLAST() 70 { 71 } 72 73 public JQLAST(int type, String text, Type jqlType) 74 { 75 initialize(type, text, jqlType); 76 } 77 78 public JQLAST(int type, String text, Type jqlType, Object value) 79 { 80 initialize(type, text, jqlType, value); 81 } 82 83 public JQLAST(Token t) 84 { 85 initialize(t); 86 } 87 88 public JQLAST(JQLAST ast) 89 { 90 initialize(ast); 91 } 92 93 public void initialize(int type) 94 { 95 setType(type); 96 } 97 98 public void initialize(int type, String text) 99 { 100 setType(type); 101 setText(text); 102 } 103 104 public void initialize(Token t) 105 { 106 setType(t.getType()); 107 setText(t.getText()); 108 setLine(t.getLine()); 109 setColumn(t.getColumn()); 110 } 111 112 public void initialize(int type, String text, Type jqlType) 113 { 114 setType(type); 115 setText(text); 116 setJQLType(jqlType); 117 } 118 119 public void initialize(int type, String text, Type jqlType, Object value) 120 { 121 setType(type); 122 setText(text); 123 setJQLType(jqlType); 124 setValue(value); 125 } 126 127 public void initialize(AST ast) 128 { 129 initialize((JQLAST)ast); 130 } 131 132 public void initialize(JQLAST ast) 133 { 134 setType(ast.getType()); 135 setText(ast.getText()); 136 setLine(ast.getLine()); 137 setColumn(ast.getColumn()); 138 setJQLType(ast.getJQLType()); 139 setValue(ast.getValue()); 140 setRetrieveDesc(ast.getRetrieveDesc()); 141 setValue(ast.getValue()); 142 } 143 144 public void setLine(int line) 145 { 146 this.line = line; 147 } 148 149 public int getLine() 150 { 151 return line; 152 } 153 154 public void setColumn(int column) 155 { 156 this.column = column; 157 } 158 159 public int getColumn() 160 { 161 return column; 162 } 163 164 public void setJQLType(Type jqlType) 165 { 166 this.jqlType = jqlType; 167 } 168 169 public Type getJQLType() 170 { 171 return jqlType; 172 } 173 174 public void setRetrieveDesc(RetrieveDesc rd) 175 { 176 this.rd = rd; 177 } 178 179 public RetrieveDesc getRetrieveDesc() 180 { 181 return rd; 182 } 183 184 public void setValue(Object value) 185 { 186 this.value = value; 187 } 188 189 public Object getValue() 190 { 191 return value; 192 } 193 194 198 public String toString() 199 { 200 StringBuffer repr = new StringBuffer (); 201 Object jqlType = getJQLType(); 202 RetrieveDesc rd = getRetrieveDesc(); 203 repr.append((getText() == null ? "null" : getText())); repr.append(" ["); repr.append(getType()); 208 repr.append(", ("); repr.append(getLine() + "/" + getColumn()); repr.append(")"); repr.append(", "); repr.append(jqlType); 215 repr.append(", "); repr.append(getRetrieveDescRepr(rd)); 218 repr.append("]"); return repr.toString(); 220 } 221 222 232 public String getTreeRepr(String title) 233 { 234 return title + this.getTreeRepr(0); 235 } 236 237 238 private String getTreeRepr(int level) 239 { 240 StringBuffer repr = new StringBuffer (); 241 repr.append(SEPARATOR); 243 repr.append(getIndent(level)); 244 repr.append(this.toString()); 245 for (JQLAST node = (JQLAST)this.getFirstChild(); 247 node != null; 248 node = (JQLAST)node.getNextSibling()) { 249 repr.append(node.getTreeRepr(level+1)); 250 } 251 return repr.toString(); 252 } 253 254 255 public static String getRetrieveDescRepr(RetrieveDesc rd) 256 { 257 StringBuffer buf = new StringBuffer (); 258 buf.append("RD:"); if (rd == null) 260 { 261 buf.append("null"); } 263 else 264 { 265 String pcClassName = rd.getPersistenceCapableClass().toString(); 266 if (pcClassName.startsWith("class ")) buf.append(pcClassName.substring(6)); 268 else 269 buf.append(pcClassName); 270 buf.append("@"); buf.append(System.identityHashCode(rd)); 272 } 273 return buf.toString(); 274 } 275 276 277 private String getIndent(int level) 278 { 279 StringBuffer buf = new StringBuffer (); 280 for (int i = 0; i < level; i++) { 281 buf.append(INDENT); 282 } 283 return buf.toString(); 284 } 285 286 289 public static class Factory 290 extends ASTFactory 291 { 292 293 private static Factory factory = new Factory(); 294 295 299 public static Factory getInstance() 300 { 301 return factory; 302 } 303 304 305 protected Factory() 306 { 307 this.theASTNodeTypeClass = JQLAST.class; 308 this.theASTNodeType = this.theASTNodeTypeClass.getName(); 309 } 310 311 312 public AST create() 313 { 314 return new JQLAST(); 315 } 316 } 317 } 318 319 | Popular Tags |