[Mulgara-svn] r1317 - in trunk/src/jar: query/java/org/mulgara/parser querylang/java/org/mulgara/itql querylang/java/org/mulgara/sparql

pag at mulgara.org pag at mulgara.org
Wed Oct 15 06:59:18 UTC 2008


Author: pag
Date: 2008-10-14 23:59:17 -0700 (Tue, 14 Oct 2008)
New Revision: 1317

Modified:
   trunk/src/jar/query/java/org/mulgara/parser/Interpreter.java
   trunk/src/jar/querylang/java/org/mulgara/itql/TqlInterpreter.java
   trunk/src/jar/querylang/java/org/mulgara/sparql/SparqlInterpreter.java
Log:
Added a method for setting the default graph for an interpreter. This is to be ignored by interpreters that don't require a default graph

Modified: trunk/src/jar/query/java/org/mulgara/parser/Interpreter.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/parser/Interpreter.java	2008-10-15 06:57:54 UTC (rev 1316)
+++ trunk/src/jar/query/java/org/mulgara/parser/Interpreter.java	2008-10-15 06:59:17 UTC (rev 1317)
@@ -1,6 +1,8 @@
 package org.mulgara.parser;
 
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.List;
 
 
@@ -67,37 +69,51 @@
   public static final String FOAF_NS = "http://xmlns.com/foaf/0.1/";
 
   /**
-  * Parses the given TQL command.
-  *
-  * @param command the command to parse in TQL syntax
-  * @return An AST for the command
-  * @throws MulgaraParserException if the syntax of the command is incorrect
-  * @throws MulgaraLexerException if the syntax of the command is incorrect
-  * @throws IOException if the <var>command</var> cannot be parsed
-  * @throws IllegalArgumentException if the <var>command</var> is <code>null</code>
-  */
+   * Parses the given TQL command.
+   * @param command the command to parse in TQL syntax
+   * @return An AST for the command
+   * @throws MulgaraParserException if the syntax of the command is incorrect
+   * @throws MulgaraLexerException if the syntax of the command is incorrect
+   * @throws IOException if the <var>command</var> cannot be parsed
+   * @throws IllegalArgumentException if the <var>command</var> is <code>null</code>
+   */
   public Command parseCommand(String command) throws MulgaraParserException, MulgaraLexerException, IllegalArgumentException, IOException;
   
   /**
-  * 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 MulgaraParserException if the syntax of the command is incorrect
-  * @throws MulgaraLexerException if the syntax of the command is incorrect
-  * @throws IOException if the <var>command</var> cannot be parsed
-  * @throws IllegalArgumentException if the <var>command</var> is <code>null</code>
-  */
+   * 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 MulgaraParserException if the syntax of the command is incorrect
+   * @throws MulgaraLexerException if the syntax of the command is incorrect
+   * @throws IOException if the <var>command</var> cannot be parsed
+   * @throws IllegalArgumentException if the <var>command</var> is <code>null</code>
+   */
   public List<Command> parseCommands(String command) throws MulgaraParserException, MulgaraLexerException, IOException, IllegalArgumentException;
   
   /**
-  * Parse a string into a {@link Query}. Convenience method over parseCommand.
-  *
-  * @param queryString a string containing an ITQL query
-  * @return the corresponding {@link Query} instance
-  * @throws IOException if <var>queryString</var> can't be buffered.
-  * @throws MulgaraLexerException if <var>queryString</var> can't be tokenized.
-  * @throws MulgaraParserException if <var>queryString</var> is not syntactic.
-  */
+   * Parse a string into a {@link Query}. Convenience method over parseCommand.
+   * @param queryString a string containing an ITQL query
+   * @return the corresponding {@link Query} instance
+   * @throws IOException if <var>queryString</var> can't be buffered.
+   * @throws MulgaraLexerException if <var>queryString</var> can't be tokenized.
+   * @throws MulgaraParserException if <var>queryString</var> is not syntactic.
+   */
   public Query parseQuery(String queryString) throws IOException, MulgaraLexerException, MulgaraParserException;
+
+  /**
+   * Sets the default graph to use when one is not specified. May not be supported by the protocol
+   * in which case it should be ignored.
+   * @param graph A string with the URI of the graph to use by default.
+   * @return The current interpreter object. This is returned to facilitate chaining of commands.
+   * @throws URISyntaxException If the <var>graph</var> could not be interpreted as a valid URI.
+   */
+  public Interpreter setDefaultGraphUri(String graph) throws URISyntaxException;
+
+  /**
+   * Sets the default graph to use when one is not specified. May not be supported by the protocol
+   * in which case it should be ignored.
+   * @param graph A string with the URI of the graph to use by default.
+   * @return The current interpreter object. This is returned to facilitate chaining of commands.
+   */
+  public Interpreter setDefaultGraphUri(URI graph);
 }
\ No newline at end of file

Modified: trunk/src/jar/querylang/java/org/mulgara/itql/TqlInterpreter.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/itql/TqlInterpreter.java	2008-10-15 06:57:54 UTC (rev 1316)
+++ trunk/src/jar/querylang/java/org/mulgara/itql/TqlInterpreter.java	2008-10-15 06:59:17 UTC (rev 1317)
@@ -59,10 +59,11 @@
 
 /**
  * Interactive TQL (ITQL) command interpreter.
- * <p>
  * Performs parsing and converting TQL requests to query objects for execution;
  * Based on ItqlInterpreter.
- * </p>
+ * 
+ * <em>This class is non-reentrant. Parsing should be serialized, or else use a new TqlInterpreters
+ * for each thread.</em>
  *
  * @created 2007-08-09
  * @author Paul Gearon
@@ -1048,6 +1049,18 @@
   }
 
 
+  /** @see org.mulgara.parser.Interpreter#setDefaultGraphUri(java.lang.String) */
+  public Interpreter setDefaultGraphUri(String graph) throws URISyntaxException {
+    return this;
+  }
+
+
+  /** @see org.mulgara.parser.Interpreter#setDefaultGraphUri(java.net.URI) */
+  public Interpreter setDefaultGraphUri(URI graph) {
+    return this;
+  }
+
+
   /**
    * Builds a list of {@link org.mulgara.query.Variable}s from a list of
    * {@link org.mulgara.itql.node.PVariable}s. Note. Variables in both the

Modified: trunk/src/jar/querylang/java/org/mulgara/sparql/SparqlInterpreter.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/sparql/SparqlInterpreter.java	2008-10-15 06:57:54 UTC (rev 1316)
+++ trunk/src/jar/querylang/java/org/mulgara/sparql/SparqlInterpreter.java	2008-10-15 06:59:17 UTC (rev 1317)
@@ -14,9 +14,11 @@
 import static org.jrdf.vocabulary.RDF.TYPE;
 import static org.jrdf.vocabulary.RDFS.LITERAL;
 import static org.mulgara.query.rdf.Mulgara.NODE_TYPE_GRAPH;
+import static org.mulgara.query.rdf.Mulgara.NULL_GRAPH;
 
 import java.io.IOException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -76,7 +78,7 @@
 public class SparqlInterpreter implements Interpreter {
 
   /** The default graph to use if none has been set. */
-  private static final List<URI> INTERNAL_DEFAULT_GRAPH_URIS = Collections.singletonList(URI.create("local:null"));
+  private static final List<URI> INTERNAL_DEFAULT_GRAPH_URIS = Collections.singletonList(URI.create(NULL_GRAPH));
 
   /** The column variables used to build a graph. */
   private static final Variable[] GRAPH_VARS = GraphAnswer.getGraphVariables();
@@ -118,7 +120,7 @@
 
   /**
    * Sets the single default graph to use in parsed queries.
-   * @param graph The graph URI to use as the default graph, or <code>null</code> if the
+   * @param graphUri The graph URI to use as the default graph, or <code>null</code> if the
    *        default graph is not desired.
    */
   public SparqlInterpreter setDefaultGraphUri(URI graphUri) {
@@ -128,6 +130,16 @@
   }
 
   /**
+   * Sets the single default graph to use in parsed queries.
+   * @param graph The graph URI to use as the default graph, or <code>null</code> if the
+   *        default graph is not desired.
+   * @throws URISyntaxException The graph was not a valid URI.
+   */
+  public SparqlInterpreter setDefaultGraphUri(String graph) throws URISyntaxException {
+    return setDefaultGraphUri(new URI(graph));
+  }
+
+  /**
    * Gets the default graph to use when none has been parsed from the query.
    * @return The graph that parsed queries will default to when no FROM graph is supplied.
    */




More information about the Mulgara-svn mailing list