[Mulgara-svn] r369 - branches/nw-interface/src/jar/itql/java/org/mulgara/itql

pag at mulgara.org pag at mulgara.org
Thu Aug 23 12:07:30 UTC 2007


Author: pag
Date: 2007-08-23 07:07:29 -0500 (Thu, 23 Aug 2007)
New Revision: 369

Modified:
   branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java
Log:
updates to work with connections

Modified: branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java
===================================================================
--- branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java	2007-08-21 19:13:53 UTC (rev 368)
+++ branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java	2007-08-23 12:07:29 UTC (rev 369)
@@ -54,7 +54,7 @@
 import org.mulgara.query.*;
 import org.mulgara.query.ast.ApplyRules;
 import org.mulgara.query.ast.Backup;
-import org.mulgara.query.ast.CommandAst;
+import org.mulgara.query.ast.Command;
 import org.mulgara.query.ast.Commit;
 import org.mulgara.query.ast.CreateGraph;
 import org.mulgara.query.ast.Deletion;
@@ -115,7 +115,7 @@
   private String itqlLogFile = null;
 
   /** The command for the callbacks to fill, while parseCommand is running */
-  CommandAst lastCommand = null;
+  Command lastCommand = null;
   
   /** The last exception or error, to be filled in during the callback operations. */
   Throwable lastError = null;
@@ -140,9 +140,7 @@
   public TqlInterpreter(Map<String,URI> aliasMap) {
 
     // validate aliasMap parameter
-    if (aliasMap == null) {
-      throw new IllegalArgumentException("Null \"alias\" parameter");
-    }
+    if (aliasMap == null) throw new IllegalArgumentException("Null \"alias\" parameter");
 
     // set members
     this.setAliasMap(aliasMap);
@@ -171,6 +169,7 @@
     aliases.put(OWL, URI.create(OWL_NS));
     aliases.put(MULGARA, URI.create(MULGARA_NS));
     aliases.put(KRULE, URI.create(KRULE_NS));
+    aliases.put(DC, URI.create(DC_NS));
     return aliases;
   }  
 
@@ -183,13 +182,70 @@
    * Parses the given TQL command.
    *
    * @param command the command to parse in TQL syntax
+   * @return An AST for the command
+   * @throws ParserException if the syntax of the command is incorrect
+   * @throws LexerException if the syntax of the command is incorrect
+   * @throws IOException if the <var>command</var> cannot be paersed
+   * @throws IllegalArgumentException if the <var>command</var> is <code>null</code>
+   */
+  public Command parseCommand(String command) throws ParserException, LexerException, Exception {
+
+    // validate command parameter
+    if ((command == null) || command.equals("")) {
+      throw new IllegalArgumentException("Null \"command\" parameter");
+    }
+
+    // log that we're going to execute the command
+    if (logger.isDebugEnabled()) logger.debug("Parsing command " + command);
+
+    // Reset the variable incrementer in the query.
+    variableFactory.reset();
+
+    // log the iTQL command - system property itql.command.log must be set
+
+    // log the command abd push it into the lexer
+    this.logItql(command);
+    lexer.add(command);
+    // test that this is a single command
+    if (lexer.getCommandCount() > 1) {
+      logger.warn("Multiple commands given to parser");
+    }
+
+    try {
+      // if the lexer saw terminators, parse the associated commands
+      if (lexer.nextCommand()) {
+  
+        Start commandTree = null;
+  
+        // parse the command
+        Parser parser = new Parser(lexer);
+        commandTree = parser.parse();
+
+        // Build the command. This populates lastCommand
+        resetInterpreter();
+        commandTree.apply(this);
+
+        if (logger.isDebugEnabled()) logger.debug("Successfully parsed command " + command);
+      }
+    } finally {
+      flush();
+    }
+    
+    return lastCommand;
+  }
+
+
+  /**
+   * Parses the given TQL command.
+   *
+   * @param command the command to parse in TQL syntax
    * @return A {@link List} of ASTs, one for each command
    * @throws ParserException if the syntax of the command is incorrect
    * @throws LexerException if the syntax of the command is incorrect
    * @throws IOException if the <var>command</var> cannot be paersed
    * @throws IllegalArgumentException if the <var>command</var> is <code>null</code>
    */
-  public List<CommandAst> parseCommand(String command) throws ParserException, LexerException, Exception {
+  public List<Command> parseCommands(String command) throws ParserException, LexerException, Exception {
 
     // validate command parameter
     if ((command == null) || command.equals("")) {
@@ -209,7 +265,7 @@
     lexer.add(command);
     
     // create a list of AST versions of the command
-    List<CommandAst> commandList = new LinkedList<CommandAst>();
+    List<Command> commandList = new LinkedList<Command>();
 
     // if the lexer saw terminators, parse the associated commands
     while (lexer.nextCommand()) {




More information about the Mulgara-svn mailing list