static MGraph toRDF(QueryResultList<?> resultList) {
final MGraph resultGraph;
Class<?> type = resultList.getType();
if (String.class.isAssignableFrom(type)) {
resultGraph = new IndexedMGraph(); //create a new Graph
for (Object result : resultList) {
//add a triple to each reference in the result set
resultGraph.add(new TripleImpl(QUERY_RESULT_LIST, QUERY_RESULT, new UriRef(result.toString())));
}
} else {
//first determine the type of the resultList
final boolean isSignType;
if (Representation.class.isAssignableFrom(type)) {
isSignType = false;
} else if (Representation.class.isAssignableFrom(type)) {
isSignType = true;
} else {
//incompatible type -> throw an Exception
throw new IllegalArgumentException("Parsed type " + type + " is not supported");
}
//special treatment for RdfQueryResultList for increased performance
if (resultList instanceof RdfQueryResultList) {
resultGraph = ((RdfQueryResultList) resultList).getResultGraph();
if (isSignType) { //if we build a ResultList for Signs, that we need to do more things
//first remove all triples representing results
Iterator<Triple> resultTripleIt = resultGraph.filter(QUERY_RESULT_LIST, QUERY_RESULT, null);
while (resultTripleIt.hasNext()) {
resultTripleIt.next();
resultTripleIt.remove();
}
//now add the Sign specific triples and add result triples
//to the Sign IDs
for (Object result : resultList) {
UriRef signId = new UriRef(((Entity) result).getId());
EntityToRDF.addEntityTriplesToGraph(resultGraph, (Entity) result);
resultGraph.add(new TripleImpl(QUERY_RESULT_LIST, QUERY_RESULT, signId));
}
}
} else { //any other implementation of the QueryResultList interface
resultGraph = new IndexedMGraph(); //create a new graph
if (Representation.class.isAssignableFrom(type)) {
for (Object result : resultList) {
UriRef resultId;
if (!isSignType) {
EntityToRDF.addRDFTo(resultGraph, (Representation) result);