clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r1485964 - in /clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers: ResultSetJsonMessageBodyWriter.java ResultSetXmlMessageBodyWriter.java
Date Fri, 24 May 2013 08:17:33 GMT
Author: misl
Date: Fri May 24 08:17:32 2013
New Revision: 1485964

URL: http://svn.apache.org/r1485964
Log:
CLEREZZA-783: Use ResultSet.getResultVars() to access header data.

Modified:
    clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetJsonMessageBodyWriter.java
    clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetXmlMessageBodyWriter.java

Modified: clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetJsonMessageBodyWriter.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetJsonMessageBodyWriter.java?rev=1485964&r1=1485963&r2=1485964&view=diff
==============================================================================
--- clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetJsonMessageBodyWriter.java
(original)
+++ clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetJsonMessageBodyWriter.java
Fri May 24 08:17:32 2013
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.List;
 import java.util.Set;
 
 import javax.ws.rs.Produces;
@@ -96,22 +97,18 @@ public class ResultSetJsonMessageBodyWri
 		JSONObject root = new JSONObject();
 		JSONObject head = new JSONObject();
 		root.put("head", head);
+		createVariables(queryResult.getResultVars(), head);
 		
 		JSONObject results = new JSONObject();
 		root.put("results", results);
 		
 		JSONArray bindings = null;
-		SolutionMapping solutionMapping = null;
 		while (queryResult.hasNext()) {
 			if (bindings == null) {
 				bindings = new JSONArray();
 				results.put("bindings", bindings);
 			}
-			solutionMapping = queryResult.next();				
-			bindings.add(createResult(solutionMapping));				
-		}
-		if (solutionMapping != null) {
-			createVariable(solutionMapping, head);
+			bindings.add(createResult(queryResult.next()));				
 		}
 
 		return root;
@@ -160,15 +157,14 @@ public class ResultSetJsonMessageBodyWri
 		return result;
 	}
 
-	private void createVariable(SolutionMapping solutionMap, JSONObject head) {
-		Set<Variable> keys = solutionMap.keySet();
+	private void createVariables(List<String> variables, JSONObject head) {
 		JSONArray vars = null;
-		for (Variable key : keys) {
+		for (String variable : variables) {
 			if (vars == null) {
 				vars = new JSONArray();
 				head.put("vars", vars);
 			}
-			vars.add(key.getName());
+			vars.add(variable);
 		}
 	}
 }

Modified: clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetXmlMessageBodyWriter.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetXmlMessageBodyWriter.java?rev=1485964&r1=1485963&r2=1485964&view=diff
==============================================================================
--- clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetXmlMessageBodyWriter.java
(original)
+++ clerezza/trunk/jaxrs.rdf.providers/src/main/java/org/apache/clerezza/jaxrs/sparql/providers/ResultSetXmlMessageBodyWriter.java
Fri May 24 08:17:32 2013
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.List;
 import java.util.Set;
 
 import javax.ws.rs.Produces;
@@ -119,15 +120,12 @@ public class ResultSetXmlMessageBodyWrit
 			root.setAttribute("xmlns", "http://www.w3.org/2005/sparql-results#");
 			doc.appendChild(root);
 			Element head = doc.createElement("head");
+			createVariables(queryResult.getResultVars(), head, doc);
 			root.appendChild(head);
+
 			Element results = doc.createElement("results");
-			SolutionMapping solutionMapping = null;
 			while (queryResult.hasNext()) {
-				solutionMapping = queryResult.next();				
-				createResultElement(solutionMapping, results, doc);				
-			}
-			if (solutionMapping != null) {
-				createVariable(solutionMapping, head, doc);
+				createResultElement(queryResult.next(), results, doc);				
 			}
 			root.appendChild(results);
 
@@ -198,11 +196,10 @@ public class ResultSetXmlMessageBodyWrit
 		}
 	}
 
-	private void createVariable(SolutionMapping solutionMap, Element head, Document doc) {
-		Set<Variable> keys = solutionMap.keySet();
-		for (Variable key : keys) {
+	private void createVariables(List<String> variables, Element head, Document doc) {
+		for (String variable : variables) {
 			Element varElement = doc.createElement("variable");
-			varElement.setAttribute("name", key.getName());
+			varElement.setAttribute("name", variable);
 			head.appendChild(varElement);
 		}
 	}



Mime
View raw message