if(!results.getHandledTuple() || results.getBindingSets().isEmpty()) {
return null;
} else {
List<String> fieldNames = results.getBindingNames();
SPARQLResult result = new SPARQLResult(new LinkedHashSet<String>(fieldNames));
//List<?> bindings = resultMap.get("results").get("bindings");
for(BindingSet nextRow : results.getBindingSets()) {
Map<String,RDFNode> row = new HashMap<String, RDFNode>();
for(String nextBindingName : fieldNames) {
if(nextRow.hasBinding(nextBindingName)) {
Binding nextBinding = nextRow.getBinding(nextBindingName);
//Map<String,String> nodeDef = (Map<String,String>) entry.getValue();
Value nodeDef = nextBinding.getValue();
RDFNode node = null;
if(nodeDef instanceof org.openrdf.model.URI) {
node = new URI(nodeDef.stringValue());
} else if(nodeDef instanceof org.openrdf.model.BNode) {
node = new BNode(((org.openrdf.model.BNode)nodeDef).getID());
} else if(nodeDef instanceof org.openrdf.model.Literal) {
org.openrdf.model.Literal nodeLiteral = (org.openrdf.model.Literal)nodeDef;
if(nodeLiteral.getLanguage() != null) {
node = new Literal(nodeLiteral.getLabel(), nodeLiteral.getLanguage());
} else if(nodeLiteral.getDatatype() != null) {
node = new Literal(nodeLiteral.getLabel(), new URI(nodeLiteral.getDatatype().stringValue()));
} else {
node = new Literal(nodeLiteral.getLabel());
}
} else {
log.error("unknown result node type: {}",nodeDef);
}
if(node != null) {
row.put(nextBindingName, node);
}
}
}
result.add(row);
}
return result;
}
default:
log.error("error evaluating SPARQL Select Query {}: {} {}",new Object[] {query,response.getStatusLine().getStatusCode(),response.getStatusLine().getReasonPhrase()});