[Mulgara-svn] r1536 - trunk/src/jar/querylang/java/org/mulgara/protocol/http

alexhall at mulgara.org alexhall at mulgara.org
Mon Feb 23 18:18:28 UTC 2009


Author: alexhall
Date: 2009-02-23 10:18:27 -0800 (Mon, 23 Feb 2009)
New Revision: 1536

Modified:
   trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java
Log:
Refactor the output type enumeration to differentiate graph formats from answer formats in the type definition.  This will make it easier to add future output type definitions.

Modified: trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java	2009-02-20 21:58:37 UTC (rev 1535)
+++ trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java	2009-02-23 18:18:27 UTC (rev 1536)
@@ -100,6 +100,9 @@
 
   /** The default output type to use. */
   protected static final Output DEFAULT_OUTPUT_TYPE = Output.XML;
+  
+  /** The default output type to use for queries that return graph results. */
+  protected static final Output DEFAULT_GRAPH_OUTPUT_TYPE = Output.RDFXML;
 
   /** The parameter identifying the graph. */
   protected static final String DEFAULT_GRAPH_ARG = "default-graph-uri";
@@ -702,9 +705,9 @@
 
     // need graph types if constructing a graph
     if (cmd instanceof ConstructQuery) {
-      if (type == Output.XML) type = Output.RDFXML;
+      if (!type.isGraphType) type = DEFAULT_GRAPH_OUTPUT_TYPE;
     } else {
-      if (type == Output.RDFXML || type == Output.N3) type = Output.XML;
+      if (type.isGraphType) type = DEFAULT_OUTPUT_TYPE;
     }
 
     return type;
@@ -715,13 +718,17 @@
    * Enumeration of the various output types, depending on mime type.
    */
   enum Output {
-    XML("application/sparql-results+xml"),
-    JSON("application/sparql-results+json"),
-    RDFXML("application/rdf+xml"),
-    N3("text/rdf+n3");
+    XML("application/sparql-results+xml", false),
+    JSON("application/sparql-results+json", false),
+    RDFXML("application/rdf+xml", true),
+    N3("text/rdf+n3", true);
 
     final String mimeText;
-    private Output(String mimeText) { this.mimeText = mimeText; }
+    final boolean isGraphType;
+    private Output(String mimeText, boolean isGraphType) { 
+      this.mimeText = mimeText;
+      this.isGraphType = isGraphType;
+    }
 
     static private Map<String,Output> outputs = new HashMap<String,Output>();
     static {




More information about the Mulgara-svn mailing list