package de.dfki.km.json.jsonld.impl;


import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.ValueFactoryImpl;

import de.dfki.km.json.jsonld.JSONLDTripleCallback;

public class SesameTripleCallback implements JSONLDTripleCallback {

    private ValueFactory vf = ValueFactoryImpl.getInstance();

    @Override
	public Object triple(String s, String p, String o) {
		if (s == null || p == null || o == null) {
			// TODO: i don't know what to do here!!!!
			return null;
		}
		
		// This method is always called with three URIs as subject predicate and object
		return vf.createStatement(vf.createURI(s), vf.createURI(p), vf.createURI(o));
	}

	@Override
	public Object triple(String s, String p, String value, String datatype,
			String language) {
		
        if (s == null || p == null || value == null) {
            // TODO: i don't know what to do here!!!!
            return null;
        }
        
	    URI subject = vf.createURI(s);
	    
	    URI predicate = vf.createURI(p);
		
		Value object;
		if (language != null) {
			object = vf.createLiteral(value, language);
		} else if (datatype != null) {
			object = vf.createLiteral(value, vf.createURI(datatype));
		} else {
            object = vf.createLiteral(value);
		}
		
        return vf.createStatement(subject, predicate, object);
	}

}

@@ -61,16 +61,13 @@
 del.
-Resource
+Graph
 ;%0Aim
@@ -201,16 +201,57 @@
 actory;%0A
+import org.openrdf.model.impl.GraphImpl;%0A
 import o
@@ -476,16 +476,71 @@
 nce();%0A%0A
+    private Graph storageGraph = new GraphImpl();%0A    %0A
     @Ove
@@ -796,22 +796,34 @@
 bject%0A%09%09
-return
+Statement result =
  vf.crea
@@ -886,16 +886,61 @@
 RI(o));%0A
+%09%09storageGraph.add(result);%0A%09%09return result;%0A
 %09%7D%0A%0A%09@Ov
@@ -1535,22 +1535,34 @@
         
-return
+Statement result =
  vf.crea
@@ -1602,14 +1602,370 @@
 bject);%0A
-%09
+        storageGraph.add(result);%0A        return result;%0A%09%7D%0A%0A    /**%0A     * @return the storageGraph%0A     */%0A    public Graph getStorageGraph()%0A    %7B%0A        return storageGraph;%0A    %7D%0A%0A    /**%0A     * @param storageGraph the storageGraph to set%0A     */%0A    public void setStorageGraph(Graph storageGraph)%0A    %7B%0A        this.storageGraph = storageGraph;%0A    
 %7D%0A%0A%7D%0A

store the triples internally, as it doesn't seem like they are accessible otherwise, even though they are returned by the callback