00001
00025 package org.objectweb.jonas_ejb.lib;
00026
00027 import org.objectweb.jonas_ejb.deployment.ejbql.ASTAbstractSchemaName;
00028 import org.objectweb.jonas_ejb.deployment.ejbql.ASTAggregateSelectExpression;
00029 import org.objectweb.jonas_ejb.deployment.ejbql.ASTArithmeticExpression;
00030 import org.objectweb.jonas_ejb.deployment.ejbql.ASTArithmeticFactor;
00031 import org.objectweb.jonas_ejb.deployment.ejbql.ASTArithmeticLiteral;
00032 import org.objectweb.jonas_ejb.deployment.ejbql.ASTArithmeticTerm;
00033 import org.objectweb.jonas_ejb.deployment.ejbql.ASTBetweenExpression;
00034 import org.objectweb.jonas_ejb.deployment.ejbql.ASTBooleanExpression;
00035 import org.objectweb.jonas_ejb.deployment.ejbql.ASTBooleanLiteral;
00036 import org.objectweb.jonas_ejb.deployment.ejbql.ASTCmpPathExpression;
00037 import org.objectweb.jonas_ejb.deployment.ejbql.ASTCollectionMemberDeclaration;
00038 import org.objectweb.jonas_ejb.deployment.ejbql.ASTCollectionMemberExpression;
00039 import org.objectweb.jonas_ejb.deployment.ejbql.ASTCollectionValuedPathExpression;
00040 import org.objectweb.jonas_ejb.deployment.ejbql.ASTComparisonExpression;
00041 import org.objectweb.jonas_ejb.deployment.ejbql.ASTConditionalExpression;
00042 import org.objectweb.jonas_ejb.deployment.ejbql.ASTConditionalFactor;
00043 import org.objectweb.jonas_ejb.deployment.ejbql.ASTConditionalTerm;
00044 import org.objectweb.jonas_ejb.deployment.ejbql.ASTDatetimeExpression;
00045 import org.objectweb.jonas_ejb.deployment.ejbql.ASTEJBQL;
00046 import org.objectweb.jonas_ejb.deployment.ejbql.ASTEmptyCollectionComparisonExpression;
00047 import org.objectweb.jonas_ejb.deployment.ejbql.ASTEntityBeanExpression;
00048 import org.objectweb.jonas_ejb.deployment.ejbql.ASTFloatingPointLiteral;
00049 import org.objectweb.jonas_ejb.deployment.ejbql.ASTFromClause;
00050 import org.objectweb.jonas_ejb.deployment.ejbql.ASTFunctionsReturningNumerics;
00051 import org.objectweb.jonas_ejb.deployment.ejbql.ASTFunctionsReturningStrings;
00052 import org.objectweb.jonas_ejb.deployment.ejbql.ASTIdentificationVariable;
00053 import org.objectweb.jonas_ejb.deployment.ejbql.ASTIdentifier;
00054 import org.objectweb.jonas_ejb.deployment.ejbql.ASTInExpression;
00055 import org.objectweb.jonas_ejb.deployment.ejbql.ASTInputParameter;
00056 import org.objectweb.jonas_ejb.deployment.ejbql.ASTIntegerLiteral;
00057 import org.objectweb.jonas_ejb.deployment.ejbql.ASTLikeExpression;
00058 import org.objectweb.jonas_ejb.deployment.ejbql.ASTLimitClause;
00059 import org.objectweb.jonas_ejb.deployment.ejbql.ASTLimitExpression;
00060 import org.objectweb.jonas_ejb.deployment.ejbql.ASTLiteral;
00061 import org.objectweb.jonas_ejb.deployment.ejbql.ASTNullComparisonExpression;
00062 import org.objectweb.jonas_ejb.deployment.ejbql.ASTOrderByClause;
00063 import org.objectweb.jonas_ejb.deployment.ejbql.ASTOrderByItem;
00064 import org.objectweb.jonas_ejb.deployment.ejbql.ASTPath;
00065 import org.objectweb.jonas_ejb.deployment.ejbql.ASTRangeVariableDeclaration;
00066 import org.objectweb.jonas_ejb.deployment.ejbql.ASTSelectClause;
00067 import org.objectweb.jonas_ejb.deployment.ejbql.ASTSelectExpression;
00068 import org.objectweb.jonas_ejb.deployment.ejbql.ASTSingleValuedCmrPathExpression;
00069 import org.objectweb.jonas_ejb.deployment.ejbql.ASTSingleValuedPathExpression;
00070 import org.objectweb.jonas_ejb.deployment.ejbql.ASTStringExpression;
00071 import org.objectweb.jonas_ejb.deployment.ejbql.ASTStringLiteral;
00072 import org.objectweb.jonas_ejb.deployment.ejbql.ASTWhereClause;
00073 import org.objectweb.jonas_ejb.deployment.ejbql.EJBQLVisitor;
00074 import org.objectweb.jonas_ejb.deployment.ejbql.SimpleNode;
00075 import org.objectweb.medor.query.api.QueryTree;
00076 import org.objectweb.medor.query.jorm.lib.NavigatorNodeFactory;
00077
00078 import java.util.ArrayList;
00079 import java.util.Iterator;
00080 import java.util.Stack;
00081 import java.util.StringTokenizer;
00082
00093 public class EjbqlAbstractVisitor implements EJBQLVisitor {
00094
00098 protected class IdValue {
00102 private ArrayList paths = null;
00103
00107 private String[] name = null;
00108
00112 private QueryTree qt = null;
00113
00118 public IdValue(String pathName) {
00119 this();
00120 name = splitPath(pathName);
00121 }
00122
00126 public IdValue() {
00127 paths = new ArrayList();
00128 }
00129
00133 public String [] getName() {
00134 return name;
00135 }
00136
00140 public void setName(String [] name) {
00141 this.name = name;
00142 }
00143
00148 public void addPath(String path) {
00149 if (!paths.contains(path)) {
00150 paths.add(path);
00151 }
00152 }
00153
00158 public String[] getSplitedPath(int idx) {
00159 return splitPath((String) paths.get(idx));
00160 }
00161
00166 public String getMergedPath(int idx) {
00167 return (String) paths.get(idx);
00168 }
00169
00173 public int getDeclaredPathLength() {
00174 return paths.size();
00175 }
00176
00180 public QueryTree getQueryTree() {
00181 return qt;
00182 }
00183
00187 public void setQueryTree(QueryTree qt) {
00188 this.qt = qt;
00189 }
00190
00194 public String toString() {
00195 StringBuffer sb = new StringBuffer();
00196 sb = sb.append("(paths=[");
00197 Iterator ip = paths.iterator();
00198 while (ip.hasNext()) {
00199 sb = sb.append((String) ip.next() + ",");
00200 }
00201 if (name == null) {
00202 sb = sb.append("],name=null");
00203 } else {
00204 sb = sb.append("],name=");
00205 for (int i = 0; i < name.length; i++) {
00206 sb = sb.append(name[i] + ".");
00207 }
00208 }
00209 if (qt == null) {
00210 sb = sb.append(",qt=null)");
00211 } else {
00212 sb = sb.append(",qt!=null)");
00213 }
00214 return sb.toString();
00215 }
00216 }
00217
00221 protected class VisitorException extends RuntimeException {
00222
00223 Exception nestedException;
00224
00225 VisitorException(Exception nestedException) {
00226 this.nestedException = nestedException;
00227 }
00228
00229 Exception getNestedException() {
00230 return nestedException;
00231 }
00232 }
00233
00239 protected String[] splitPath(String path) {
00240 StringTokenizer st = new StringTokenizer(path, ".");
00241 String[] ret = new String[st.countTokens()];
00242 for (int i = 0; i < ret.length; i++) {
00243 ret[i] = st.nextToken();
00244 }
00245 return ret;
00246 }
00247
00254 protected String mergePath(String[] path, int begin, int length) {
00255 if (length == 0) {
00256 return "";
00257 }
00258 StringBuffer ret = new StringBuffer();
00259 for (int i = begin; i < (begin + length); i++) {
00260 ret.append(path[i]);
00261 ret.append('.');
00262 }
00263 ret.deleteCharAt(ret.length() - 1);
00264 return ret.toString();
00265 }
00266
00271 protected String mergePath(String[] path) {
00272 return (mergePath(path, 0, path.length));
00273 }
00274
00280 protected boolean endsWith(String[] path, String suffix) {
00281 return (suffix.equals(path[path.length - 1]));
00282 }
00283
00290 protected String[] basePath(String[] path) {
00291 String[] base = new String[path.length - 1];
00292 for (int i = 0; i < path.length - 1; i++) {
00293 base[i] = new String(path[i]);
00294 }
00295 return base;
00296 }
00297
00305 public Object visit(SimpleNode node) throws Exception {
00306 try {
00307 return visit((SimpleNode) node, new Stack());
00308 } catch (VisitorException e) {
00309 throw e.getNestedException();
00310 }
00311 }
00312
00319 public Object visit(SimpleNode node, Object data) {
00320 return node.childrenAccept(this, data);
00321 }
00322
00329 public Object visit(ASTEJBQL node, Object data) {
00330 return null;
00331 }
00332
00339 public Object visit(ASTFromClause node, Object data) {
00340 return null;
00341 }
00342
00349 public Object visit(ASTCollectionMemberDeclaration node, Object data) {
00350 return null;
00351 }
00352
00359 public Object visit(ASTRangeVariableDeclaration node, Object data) {
00360 return null;
00361 }
00362
00369 public Object visit(ASTSingleValuedPathExpression node, Object data) {
00370 return null;
00371 }
00372
00379 public Object visit(ASTCmpPathExpression node, Object data) {
00380 return null;
00381 }
00382
00389 public Object visit(ASTSingleValuedCmrPathExpression node, Object data) {
00390 return null;
00391 }
00392
00399 public Object visit(ASTCollectionValuedPathExpression node, Object data) {
00400 return null;
00401 }
00402
00409 public Object visit(ASTSelectClause node, Object data) {
00410 return null;
00411 }
00412
00419 public Object visit(ASTSelectExpression node, Object data) {
00420 return null;
00421 }
00422
00429 public Object visit(ASTAggregateSelectExpression node, Object data) {
00430 return null;
00431 }
00432
00439 public Object visit(ASTOrderByClause node, Object data) {
00440 return null;
00441 }
00442
00449 public Object visit(ASTOrderByItem node, Object data) {
00450 return null;
00451 }
00452
00459 public Object visit(ASTLimitClause node, Object data) {
00460 return null;
00461 }
00462
00469 public Object visit(ASTLimitExpression node, Object data) {
00470 return null;
00471 }
00472
00479 public Object visit(ASTWhereClause node, Object data) {
00480 return null;
00481 }
00482
00489 public Object visit(ASTConditionalExpression node, Object data) {
00490 return null;
00491 }
00492
00499 public Object visit(ASTConditionalTerm node, Object data) {
00500 return null;
00501 }
00502
00509 public Object visit(ASTConditionalFactor node, Object data) {
00510 return null;
00511 }
00512
00519 public Object visit(ASTBetweenExpression node, Object data) {
00520 return null;
00521 }
00522
00529 public Object visit(ASTInExpression node, Object data) {
00530 return null;
00531 }
00532
00539 public Object visit(ASTLikeExpression node, Object data) {
00540 return null;
00541 }
00542
00549 public Object visit(ASTNullComparisonExpression node, Object data) {
00550 return null;
00551 }
00552
00559 public Object visit(ASTEmptyCollectionComparisonExpression node, Object data) {
00560 return null;
00561 }
00562
00569 public Object visit(ASTCollectionMemberExpression node, Object data) {
00570 return null;
00571 }
00572
00579 public Object visit(ASTComparisonExpression node, Object data) {
00580 return null;
00581 }
00582
00589 public Object visit(ASTArithmeticExpression node, Object data) {
00590 return null;
00591 }
00592
00599 public Object visit(ASTIntegerLiteral node, Object data) {
00600 return null;
00601 }
00602
00609 public Object visit(ASTFloatingPointLiteral node, Object data) {
00610 return null;
00611 }
00612
00619 public Object visit(ASTArithmeticTerm node, Object data) {
00620 return null;
00621 }
00622
00629 public Object visit(ASTArithmeticFactor node, Object data) {
00630 return null;
00631 }
00632
00639 public Object visit(ASTStringExpression node, Object data) {
00640 return null;
00641 }
00642
00649 public Object visit(ASTDatetimeExpression node, Object data) {
00650 return null;
00651 }
00652
00659 public Object visit(ASTBooleanExpression node, Object data) {
00660 return null;
00661 }
00662
00669 public Object visit(ASTEntityBeanExpression node, Object data) {
00670 return null;
00671 }
00672
00679 public Object visit(ASTFunctionsReturningStrings node, Object data) {
00680 return null;
00681 }
00682
00689 public Object visit(ASTFunctionsReturningNumerics node, Object data) {
00690 return null;
00691 }
00692
00699 public Object visit(ASTAbstractSchemaName node, Object data) {
00700 return null;
00701 }
00702
00709 public Object visit(ASTIdentificationVariable node, Object data) {
00710 return null;
00711 }
00712
00719 public Object visit(ASTIdentifier node, Object data) {
00720 return null;
00721 }
00722
00729 public Object visit(ASTPath node, Object data) {
00730 return null;
00731 }
00732
00740 public Object visit(ASTLiteral node, Object data) {
00741 return null;
00742 }
00743
00750 public Object visit(ASTStringLiteral node, Object data) {
00751 return null;
00752 }
00753
00760 public Object visit(ASTArithmeticLiteral node, Object data) {
00761 return null;
00762 }
00763
00770 public Object visit(ASTBooleanLiteral node, Object data) {
00771 return null;
00772 }
00773
00780 public Object visit(ASTInputParameter node, Object data) {
00781 return null;
00782 }
00783 }