package com.github.anno4j.model.impl;

import com.github.anno4j.Anno4j;
import org.openrdf.model.Resource;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.repository.object.ObjectConnection;
import org.openrdf.repository.object.RDFObject;

/**
 * Class to implement RDF in order to create a baseline for every object that we use in Anno4j.
 */
public class ResourceObject implements RDFObject {

    /**
     * Unique identifier for the instance.
     */
    private Resource resource = Anno4j.getInstance().getIdGenerator().generateID();

    /**
     *  The current {@link org.openrdf.repository.object.ObjectConnection} this object is attached to. Will be implemented by the proxy object.
     */
    @Override
    public ObjectConnection getObjectConnection() {
        // will be implemented by the proxy object
        return null;
    }

    /**
     * Gets Unique identifier for the instance.
     *
     * @return Value of Unique identifier for the instance..
     */
    public Resource getResource() {
        return resource;
    }

    /**
     * Sets new Unique identifier for the instance.
     *
     * @param resource New value of Unique identifier for the instance..
     */
    public void setResource(Resource resource) {
        this.resource = resource;
    }

    /**
     * Sets new Unique identifier for the instance by a given String.
     *
     * @param resourceAsString Textual representation of the new value of Unique identifier for the instance.
     */
    public void setResourceAsString(String resourceAsString) {
        this.resource = new URIImpl(resourceAsString);
    }

    /**
     * Gets new identifier for this instance as String.
     * @return identifier as String.
     */
    public String getResourceAsString() {
        return this.resource.stringValue();
    }
}

@@ -129,123 +129,719 @@
 del.
-impl.URIImpl;%0Aimport org.openrdf.repository.object.ObjectConnection;%0Aimport org.openrdf.repository.object.RDFObject
+Statement;%0Aimport org.openrdf.model.impl.URIImpl;%0Aimport org.openrdf.query.GraphQueryResult;%0Aimport org.openrdf.query.MalformedQueryException;%0Aimport org.openrdf.query.QueryEvaluationException;%0Aimport org.openrdf.query.QueryLanguage;%0Aimport org.openrdf.repository.Repository;%0Aimport org.openrdf.repository.RepositoryException;%0Aimport org.openrdf.repository.config.RepositoryConfigException;%0Aimport org.openrdf.repository.object.ObjectConnection;%0Aimport org.openrdf.repository.object.ObjectRepository;%0Aimport org.openrdf.repository.object.RDFObject;%0Aimport org.openrdf.repository.object.config.ObjectRepositoryFactory;%0Aimport org.openrdf.repository.sail.SailRepository;%0Aimport org.openrdf.sail.memory.MemoryStore
 ;%0A%0A/
@@ -2410,11 +2410,1542 @@
 );%0A    %7D
+%0A%0A    public String getNTriples()%7B%0A        StringBuilder sb = new StringBuilder();%0A        try %7B%0A            MemoryStore store = new MemoryStore();%0A            Repository sailRepository = new SailRepository(store);%0A            sailRepository.initialize();%0A            ObjectRepository objectRepository = new ObjectRepositoryFactory().createRepository(sailRepository);%0A            ObjectConnection connection = objectRepository.getConnection();%0A            connection.addObject(this);%0A            GraphQueryResult result = sailRepository.getConnection().prepareGraphQuery(QueryLanguage.SPARQL, %22CONSTRUCT %7B ?s ?p ?o. %7D WHERE %7B ?s ?p ?o. %7D %22).evaluate();%0A            while (result.hasNext()) %7B%0A                Statement item = result.next();%0A%0A                sb%0A                        .append(item.getSubject())%0A                        .append(%22 %22)%0A                        .append(item.getPredicate())%0A                        .append(%22 %22)%0A                        .append(item.getObject())%0A                        .append(%22.%22)%0A                        .append(System.getProperty(%22line.separator%22));%0A            %7D%0A            result.close();%0A            connection.close();%0A        %7D catch (RepositoryException e) %7B%0A            e.printStackTrace();%0A        %7D catch (RepositoryConfigException e) %7B%0A            e.printStackTrace();%0A        %7D catch (MalformedQueryException e) %7B%0A            e.printStackTrace();%0A        %7D catch (QueryEvaluationException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        return sb.toString();%0A    %7D
 %0A%7D%0A

each object can return ntiples