public synchronized void executeQuery(String query,ObjectVisitor visitor) throws OQLException {
  debugPrint("query : " + query);
  StringTokenizer st=new StringTokenizer(query);
  if (st.hasMoreTokens()) {
    String first=st.nextToken();
    if (!first.equals("select")) {
      try {
        Object res=evalScript(query);
        visitor.visit(res);
      }
 catch (      Exception e) {
        throw new OQLException(e);
      }
      return;
    }
  }
 else {
    throw new OQLException("query syntax error: no 'select' clause");
  }
  String selectExpr="";
  boolean seenFrom=false;
  while (st.hasMoreTokens()) {
    String tok=st.nextToken();
    if (tok.equals("from")) {
      seenFrom=true;
      break;
    }
    selectExpr+=" " + tok;
  }
  if (selectExpr.equals("")) {
    throw new OQLException("query syntax error: 'select' expression can not be empty");
  }
  String className=null;
  boolean isInstanceOf=false;
  String whereExpr=null;
  String identifier=null;
  if (seenFrom) {
    if (st.hasMoreTokens()) {
      String tmp=st.nextToken();
      if (tmp.equals("instanceof")) {
        isInstanceOf=true;
        if (!st.hasMoreTokens()) {
          throw new OQLException("no class name after 'instanceof'");
        }
        className=st.nextToken();
      }
 else {
        className=tmp;
      }
    }
 else {
      throw new OQLException("query syntax error: class name must follow 'from'");
    }
    if (st.hasMoreTokens()) {
      identifier=st.nextToken();
      if (identifier.equals("where")) {
        throw new OQLException("query syntax error: identifier should follow class name");
      }
      if (st.hasMoreTokens()) {
        String tmp=st.nextToken();
        if (!tmp.equals("where")) {
          throw new OQLException("query syntax error: 'where' clause expected after 'from' clause");
        }
        whereExpr="";
        while (st.hasMoreTokens()) {
          whereExpr+=" " + st.nextToken();
        }
        if (whereExpr.equals("")) {
          throw new OQLException("query syntax error: 'where' clause cannot have empty expression");
        }
      }
    }
 else {
      throw new OQLException("query syntax error: identifier should follow class name");
    }
  }
  executeQuery(new OQLQuery(selectExpr,isInstanceOf,className,identifier,whereExpr),visitor);
}

public synchronized void executeQuery ( String query , ObjectVisitor visitor ) throws OQLException { debugPrint ( "query : " + query ) ; StringTokenizer st = new StringTokenizer ( query ) ; if ( st . hasMoreTokens ( ) ) { String first = st . nextToken ( ) ; if ( ! first . equals ( "select" ) ) { try { Object res = evalScript ( query ) ; visitor . visit ( res ) ; } catch ( Exception e ) { throw new OQLException ( e ) ; } return ; } } else { throw new OQLException ( "query syntax error: no 'select' clause" ) ; } String selectExpr = "" ; boolean seenFrom = false ; while ( st . hasMoreTokens ( ) ) { String tok = st . nextToken ( ) ; if ( tok . equals ( "from" ) ) { seenFrom = true ; break ; } selectExpr += " " + tok ; } if ( selectExpr . equals ( "" ) ) { throw new OQLException ( "query syntax error: 'select' expression can not be empty" ) ; } String className = null ; boolean isInstanceOf = false ; String whereExpr = null ; String identifier = null ; if ( seenFrom ) { if ( st . hasMoreTokens ( ) ) { String tmp = st . nextToken ( ) ; if ( tmp . equals ( "instanceof" ) ) { isInstanceOf = true ; if ( ! st . hasMoreTokens ( ) ) { throw new OQLException ( "no class name after 'instanceof'" ) ; } className = st . nextToken ( ) ; } else { className = tmp ; } } else { throw new OQLException ( "query syntax error: class name must follow 'from'" ) ; } if ( st . hasMoreTokens ( ) ) { identifier = st . nextToken ( ) ; if ( identifier . equals ( "where" ) ) { throw new OQLException ( "query syntax error: identifier should follow class name" ) ; } if ( st . hasMoreTokens ( ) ) { String tmp = st . nextToken ( ) ; if ( ! tmp . equals ( "where" ) ) { throw new OQLException ( "query syntax error: 'where' clause expected after 'from' clause" ) ; } whereExpr = "" ; while ( st . hasMoreTokens ( ) ) { whereExpr += " " + st . nextToken ( ) ; } if ( whereExpr . equals ( "" ) ) { throw new OQLException ( "query syntax error: 'where' clause cannot have empty expression" ) ; } } } else { throw new OQLException ( "query syntax error: identifier should follow class name" ) ; } } executeQuery ( new OQLQuery ( selectExpr , isInstanceOf , className , identifier , whereExpr ) , visitor ) ; }
query is of the form select & lt ; java script code to select & gt ; [ from [ instanceof ] & lt ; class name & gt ; [ & lt ; identifier & gt ; ] [ where & lt ; java script boolean expression & gt ; ] ]
