You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2015/03/22 23:04:44 UTC

[01/14] clerezza git commit: CLEREZZA-975: Harmonizing versions for usage in typerenderinglauncher

Repository: clerezza
Updated Branches:
  refs/heads/rdf-commons 3e0524aab -> 8a337849c


CLEREZZA-975: Harmonizing versions for usage in typerenderinglauncher

Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/ed16bacd
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/ed16bacd
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/ed16bacd

Branch: refs/heads/rdf-commons
Commit: ed16bacd57b09951db893b5c3876a5cb36ccfb43
Parents: 3e0524a
Author: Reto Gmuer <re...@apache.org>
Authored: Sun Mar 22 17:34:11 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Sun Mar 22 17:34:11 2015 +0000

----------------------------------------------------------------------
 rdf.utils/pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/ed16bacd/rdf.utils/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.utils/pom.xml b/rdf.utils/pom.xml
index 16e120c..0f6b648 100644
--- a/rdf.utils/pom.xml
+++ b/rdf.utils/pom.xml
@@ -24,14 +24,14 @@
     <parent>
         <artifactId>clerezza</artifactId>
         <groupId>org.apache.clerezza</groupId>
-        <version>1.0.0-SNAPSHOT</version>
+        <version>7-SNAPSHOT</version>
         <relativePath>../parent</relativePath>
     </parent>
     <groupId>org.apache.clerezza</groupId>
     <artifactId>rdf.utils</artifactId>
     <packaging>bundle</packaging>
     <version>1.0.0-SNAPSHOT</version>
-    <name>Clerezza - SCB Utilities</name>
+    <name>Clerezza - RDF - Utilities</name>
     <description>Utility classed to deal with Clerezza Models</description>
     <dependencies>
         <dependency>


[12/14] clerezza git commit: Removed obsolete imports

Posted by re...@apache.org.
Removed obsolete imports

Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/be0f3781
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/be0f3781
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/be0f3781

Branch: refs/heads/rdf-commons
Commit: be0f3781c9a3bded3778ece0b477f27603721721
Parents: dac431c
Author: Reto Gmuer <re...@apache.org>
Authored: Sun Mar 22 21:02:53 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Sun Mar 22 21:02:53 2015 +0000

----------------------------------------------------------------------
 .../java/org/apache/clerezza/rdf/core/test/GraphTest.java     | 7 -------
 1 file changed, 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/be0f3781/rdf/core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphTest.java
----------------------------------------------------------------------
diff --git a/rdf/core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphTest.java b/rdf/core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphTest.java
index 4741e2e..06feaac 100644
--- a/rdf/core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphTest.java
+++ b/rdf/core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphTest.java
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Set;
 import org.apache.commons.rdf.BlankNode;
 import org.apache.commons.rdf.Literal;
@@ -34,14 +33,8 @@ import org.apache.commons.rdf.Iri;
 import org.apache.commons.rdf.impl.utils.TripleImpl;
 import org.junit.Test;
 import org.apache.commons.rdf.Language;
-import org.apache.commons.rdf.event.AddEvent;
-import org.apache.commons.rdf.event.FilterTriple;
-import org.apache.commons.rdf.event.GraphEvent;
-import org.apache.commons.rdf.event.GraphListener;
-import org.apache.commons.rdf.event.RemoveEvent;
 import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
 import org.apache.commons.rdf.impl.utils.TypedLiteralImpl;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
 import org.junit.Assert;
 
 


[09/14] clerezza git commit: CLEREZZA-966: moved jena.tdb.storage into the hierarchy

Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
new file mode 100644
index 0000000..b8df417
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
@@ -0,0 +1,717 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.io.File;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
+import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
+import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
+import org.apache.clerezza.rdf.core.access.QueryableTcProvider;
+import org.apache.clerezza.rdf.core.access.TcProvider;
+import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.jena.tdb.internals.ModelGraph;
+import org.apache.clerezza.rdf.jena.tdb.internals.Symbols;
+import org.apache.clerezza.rdf.jena.tdb.internals.UriRefSet;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.MapMaker;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.tdb.TDB;
+import com.hp.hpl.jena.tdb.TDBFactory;
+import org.apache.clerezza.rdf.core.access.TcManager;
+
+/**
+ * {@link WeightedTcProvider} implementation for Jena TDB that uses a single
+ * {@link TDBFactory#createDataset(String) Dataset} to store all created
+ * {@link Graph} and {@link MGraph} instances.<p>
+ * The {@link #TDB_DIR} is uses to configure the directory on the disc. It
+ * supports property substitution <code>'${property}'</code> based on properties defined
+ * in the {@link BundleContext#getProperty(String)} and 
+ * {@link System#getProperty(String)}. This is to easily allow configurations
+ * such as <code>"${myHome}/myRdfStore"</code><p>
+ * The {@link #DEFAULT_GRAPH_NAME} property can be used to define the
+ * name of the Graph that exposes the {@link Dataset#getDefaultModel()} as
+ * both {@link TcProvider#getGraph(UriRef)} and {@link TcProvider#getMGraph(UriRef)}.
+ * This easily allows to access the union graph of the Jena TDB dataset.<p>
+ * This {@link TcProvider} {@link ConfigurationPolicy#REQUIRE requires} an
+ * configuration and uses the {@link Component#configurationFactory() 
+ * configuration factory}. Therefore it will be bot active until a valid
+ * configuration is parsed to the {@link ConfigurationAdmin} service. However
+ * it supports multiple instances to be created.<p>
+ * Users that want to use multiple instances will need to use special filters
+ * to ensure that the correct instance is injected to components. As by default
+ * the instance with the highest {@link #WEIGHT} will be used by Clerezza
+ * to create instances. A good practice to filter for multiple instances is
+ * to add an additional user defined key to the configuration that can later
+ * be used for filtering. Such additional keys will be savely ignored by
+ * this implementation.<p>
+ * 
+ * @author Rupert Westenthaler, MInto van der Sluis
+ *
+ */
+@Component(metatype=true, immediate=true,
+    configurationFactory=true, policy=ConfigurationPolicy.OPTIONAL)
+@Service({WeightedTcProvider.class, TcProvider.class, QueryableTcProvider.class})
+@Properties(value={
+    @Property(name=SingleTdbDatasetTcProvider.TDB_DIR),
+    @Property(name=SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME),
+    @Property(name=SingleTdbDatasetTcProvider.SYNC_INTERVAL, intValue=SingleTdbDatasetTcProvider.DEFAULT_SYNC_INTERVAL),
+    @Property(name=SingleTdbDatasetTcProvider.WEIGHT, intValue=105),
+    @Property(name=TcManager.GENERAL_PURPOSE_TC, boolValue = true)
+})
+public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements WeightedTcProvider {
+
+    public static final String TDB_DIR = "tdb-dir";
+    public static final String DEFAULT_GRAPH_NAME = "default-graph-name";
+    public static final String WEIGHT = "weight";
+    public static final String SYNC_INTERVAL = "sync-interval";
+    public static final String USE_GRAPH_NAME_SUFFIXES = "use-graph-name-suffixes";
+    
+    public static final int DEFAULT_SYNC_INTERVAL = 6;
+    public static final int MIN_SYNC_INTERVAL = 3;
+    
+    private final Logger log = LoggerFactory.getLogger(SingleTdbDatasetTcProvider.class);
+
+    private int weight;
+    private ModelGraph graphNameIndex;
+    private int syncInterval = DEFAULT_SYNC_INTERVAL;
+    private SyncThread syncThread;
+
+    private final ReadWriteLock datasetLock = new ReentrantReadWriteLock();;
+    private UriRef defaultGraphName;
+
+    // Ensure that models not yet garbage collected get properly synced.
+    private final ConcurrentMap<UriRef, ModelGraph> syncModels = new MapMaker().weakValues().makeMap();
+    
+    /**
+     * This background thread ensures that changes to {@link Model}s are
+     * synchronized with the file system. Only {@link ModelGraph}s where
+     * <code>{@link ModelGraph#isReadWrite()} == true</code> are synced.<p>
+     * This is similar to the synchronize thread used by the {@link TdbTcProvider}.
+     * This thread is started during the 
+     * {@link ScalableSingleTdbDatasetTcProvider#activate(ComponentContext) activation}
+     * ad the shutdown is requested during 
+     * {@link ScalableSingleTdbDatasetTcProvider#deactivate(ComponentContext) deactivation}
+     */
+    class SyncThread extends Thread {
+        private boolean stopRequested = false;
+
+        @Override
+        public void run() {
+            while (!stopRequested) {
+                try {
+                    Thread.sleep(syncInterval*1000);
+                } catch (InterruptedException ex) {
+                    interrupt();
+                }
+                if (!stopRequested) {
+                    datasetLock.writeLock().lock();
+                    try {
+                        for(ModelGraph mg : syncModels.values()){
+                            if(mg.isReadWrite()){
+                                mg.sync();
+                            } //else we do not need to sync read-only models
+                        }
+                    } finally {
+                        datasetLock.writeLock().unlock();
+                    }
+                }
+            }
+        }
+        
+        public void requestStop() {
+            stopRequested = true;
+        }
+    }
+
+    /**
+     * Default constructor used by OSGI
+     */
+    public SingleTdbDatasetTcProvider(){}
+    
+    /**
+     * Creates a TDB single dataset {@link TcProvider} based on the parsed
+     * configuration.<p>
+     * The following properties are supported:<ul>
+     * <li> {@link #TDB_DIR} (required): The directory used by Jena TDB. Property
+     * substitution "${property-name}" with {@link System#getProperties()} is
+     * supported.
+     * <li> {@link #DEFAULT_GRAPH_NAME}: The name ({@link UriRef}) of the
+     * {@link Graph} that exports the union graph. This graph allows to query
+     * triples in any named model managed by this {@link TcProvider}.
+     * <li> {@link #SYNC_INTERVAL}: The sync interval that
+     * is used to write changes in the graph to the file system. If missing
+     * the {@link #DEFAULT_SYNC_INTERVAL} is used. Values lower than 
+     * {@link #MIN_SYNC_INTERVAL} are ignored
+     * <li>{@link #WEIGHT}: The weight of this {@link TcProvider}. If missing
+     * <code>0</code> is used as weight.
+     * </ul>
+     * <b>NOTE</b> Users need to call {@link #close()} to free up system 
+     * resources when they are no longer need this instance.
+     * @param config The configuration
+     * @throws IOException the 
+     * @throws ConfigurationException 
+     */
+    public SingleTdbDatasetTcProvider(Dictionary<String,Object> config) throws ConfigurationException, IOException{
+        activate(null,config);
+    }
+    /**
+     * Activate method used by OSGI
+     * @param ctx
+     * @throws ConfigurationException
+     * @throws IOException
+     */
+    @Activate
+    @SuppressWarnings("unchecked")
+    protected void activate(ComponentContext ctx) throws ConfigurationException, IOException {
+        activate(ctx.getBundleContext(),ctx.getProperties());
+    }
+
+    /**
+     * Internally used for activation to support  the instantiation via
+     * {@link #ScalableSingleTdbDatasetTcProvider(Dictionary)} - to be used outside
+     * an OSGI container.
+     * @param bc the BundleContext or <code>null</code> if activating outside
+     * an OSGI container. The BundleContext is just used to lookup properties
+     * for {@link #substituteProperty(String, BundleContext)}.
+     * @param config The configuration for this Instance. Note that {@link #TDB_DIR}
+     * is required to be present.
+     * @throws ConfigurationException if the parsed configuration is invalid
+     * @throws IOException on any error while creating/accessing the Jena TDB
+     * directory.
+     */
+    private void activate(BundleContext bc,Dictionary<String,Object> config) throws ConfigurationException, IOException {
+        log.info("Activating scalable single Dataset TDB provider");
+        Object value = config.get(WEIGHT);
+        if(value instanceof Number){
+            weight = ((Number)value).intValue();
+        } else if(value != null){
+            try {
+                weight = new BigDecimal(value.toString()).intValueExact();
+            } catch (RuntimeException e) {
+                throw new ConfigurationException(WEIGHT, "Unable to parse integer weight!", e);
+            }
+        } else { //weight not defined
+            weight = 0;
+        }
+        value = config.get(SYNC_INTERVAL);
+        if(value instanceof Number){
+            syncInterval = Math.max(((Number)value).intValue(),MIN_SYNC_INTERVAL);
+        } else if(value != null){
+            try {
+                syncInterval = Math.max(new BigDecimal(value.toString()).intValueExact(),MIN_SYNC_INTERVAL);
+            } catch (RuntimeException e) {
+                throw new ConfigurationException(SYNC_INTERVAL, "Unable to parse integer weight!", e);
+            }
+        } else { //sync interval not defined
+            syncInterval = DEFAULT_SYNC_INTERVAL;
+        }
+        value = config.get(TDB_DIR);
+        File dataDir;
+        if(value != null && !value.toString().isEmpty()){
+            dataDir = new File(substituteProperty(value.toString(),bc)).getAbsoluteFile();
+        } else {
+            value = config.get(Constants.SERVICE_PID);
+            if(value == null){
+                throw new ConfigurationException(TDB_DIR, "No Data Directory for "
+                    + "the Jena TDB store parsed. Also unable to use the "
+                    + "'service.pid' property as default because this property "
+                    + "is not present in the parsed configuration.");
+            }
+            dataDir = bc.getDataFile("singleTdb"+File.separatorChar+value.toString());
+            log.info("No TDB directory parsed - use default '{}'",dataDir);
+        }
+        //parse the default graph name
+        value = config.get(DEFAULT_GRAPH_NAME);
+        if(value != null && !value.toString().isEmpty()){
+            try {
+                new URI(value.toString());
+                defaultGraphName = new UriRef(value.toString());
+            } catch (URISyntaxException e) {
+                throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The parsed name '"
+                        + value + "'for the default graph (union over all "
+                		+ "named graphs managed by this Jena TDB dataset) MUST BE "
+                        + "an valid URI or NULL do deactivate this feature!",e);
+            }
+        } else {
+            defaultGraphName = null; //deactivate the default graph name
+        }
+        
+        //validate the parsed directory!
+        if(!dataDir.exists()){
+            if(dataDir.mkdirs()){
+                log.info("Created Jena TDB data directory {}",dataDir);
+            } else {
+                throw new ConfigurationException(TDB_DIR, "Unable to create Jena TDB data directory '"+dataDir+"'!");
+            }
+        } else if(!dataDir.isDirectory()){
+            throw new ConfigurationException("tdb.dir", "Configured jena TDB data directory '"
+                    + dataDir+"' already exists, but is not a Directory!");
+        } //else exists and is a directory ... nothing to do
+        TDB.getContext().set(TDB.symUnionDefaultGraph, true);
+        setDataset( TDBFactory.createDataset(dataDir.getAbsolutePath()) );
+        graphNameIndex = new ModelGraph(datasetLock, getDataset().getDefaultModel(),true);
+
+        // Remove existing default graph names from the index (if might have changed
+        // in the mean time).
+        removeDefaultGraphFromIndex();
+
+        //finally ensure the the defaultGraphName is not also used as a graph/mgraph name
+        if (defaultGraphName != null) {
+          if (isExistingGraphName(defaultGraphName)) {
+            throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The configured default graph name '"
+                +defaultGraphName+"' is already used as a Graph or MGraph name!");
+          } else {
+            addToIndex( defaultGraphName, Symbols.Default );
+            addToIndex( defaultGraphName, Symbols.Graph );
+          }
+        }
+
+        syncThread = new SyncThread();
+        syncThread.setDaemon(true);
+        syncThread.setName("SyncDaemon for Jena TDB "+dataDir.getAbsolutePath());
+        syncThread.start();
+    }
+    
+    /**
+     * call close in finalisation
+     */
+    @Override
+    protected void finalize() throws Throwable {
+        close();
+        super.finalize();
+    }
+
+    /**
+     * Closes this {@link TcProvider} instance and frees up all system resources.
+     * This method needs only to be called when using this TcProvider outside
+     * an OSGI environment.
+     */
+    public void close(){
+        deactivate(null);
+    }
+
+    /**
+     * Deactivates this component. Called by the OSGI environment if this
+     * component gets deactivated.
+     * @param ctx the ComponentContext. May be <code>null</code>
+     */
+    @Deactivate
+    protected void deactivate(ComponentContext ctx) {
+        if(syncThread != null){
+            syncThread.requestStop();
+            syncThread = null;
+        }
+    	Dataset dataset = getDataset();
+        if(dataset != null){ //avoid NPE on multiple calls
+            datasetLock.writeLock().lock();
+            try {
+                for(ModelGraph mg : syncModels.values()){
+                    mg.close(); //close also syncs!
+                }
+                syncModels.clear();
+
+                graphNameIndex.close();
+                graphNameIndex = null;
+
+                TDB.sync(dataset);
+                dataset.close();
+                setDataset(null);
+            } finally {
+                datasetLock.writeLock().unlock();
+            }
+        }
+    }
+    
+    /**
+     * Internal method used to retrieve an existing Jena {@link ModelGraph} 
+     * instance from {@link #syncModels} or initializes a new Jena TDB {@link Model}
+     * and Clerezza {@link Graph}s/{@link MGraph}s.
+     * @param name the name of the Graph to initialize/create
+     * @param readWrite if <code>true</code> a {@link MGraph} is initialized.
+     * Otherwise a {@link Graph} is created.
+     * @param create if this method is allowed to create an new {@link Model} or
+     * if an already existing model is initialized.
+     * @return the initialized {@link Model} and @link Graph} or {@link MGraph}.
+     * The returned instance will be also cached in {@link #syncModels}. 
+     * @throws NoSuchEntityException If <code>create == false</code> and no
+     * {@link Model} for the parsed <code>name</code> exists.
+     */
+    private ModelGraph getModelGraph(UriRef name, boolean readWrite,boolean create) throws NoSuchEntityException {
+        ModelGraph modelGraph = null;
+        datasetLock.readLock().lock();
+        try {
+            if(readWrite) {
+                // Reuse existing model if not yet garbage collected.
+                modelGraph = syncModels.get(name);
+            }
+            if((modelGraph != null || isExistingGraphName(name)) && create){
+                throw new EntityAlreadyExistsException(name);
+            } else if(modelGraph == null){
+                String modelName = name.getUnicodeString();
+                modelGraph = new ModelGraph(datasetLock, name.equals(defaultGraphName) ? 
+                		getDataset().getNamedModel("urn:x-arq:UnionGraph") : 
+                			getDataset().getNamedModel(modelName),readWrite);
+                if(readWrite) {
+                    // Keep track of readwrite model to be able to sync them.
+                    this.syncModels.put(name, modelGraph);
+                }
+            }
+        } finally {
+            datasetLock.readLock().unlock();
+        }
+        return modelGraph;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#getGraph(org.apache.clerezza.rdf.core.UriRef)
+     */
+    @Override
+    public Graph getGraph(UriRef name) throws NoSuchEntityException {
+        if(name == null){
+            throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
+        }
+        datasetLock.readLock().lock();
+        try {
+            if (isExistingGraphName(name, Symbols.Graph) || name.equals(defaultGraphName)){
+                return getModelGraph(name,false,false).getGraph();
+            } else {
+                throw new NoSuchEntityException(name);
+            }
+        } finally {
+            datasetLock.readLock().unlock();
+        }
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#getMGraph(org.apache.clerezza.rdf.core.UriRef)
+     */
+    @Override
+    public MGraph getMGraph(UriRef name) throws NoSuchEntityException {
+        if(name == null){
+            throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
+        }
+        datasetLock.readLock().lock();
+        try {
+            if(isExistingGraphName(name, Symbols.MGraph)){
+                return getModelGraph(name,true,false).getMGraph();
+            } else {
+                throw new NoSuchEntityException(name);
+            }
+        } finally {
+            datasetLock.readLock().unlock();
+        }
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#getTriples(org.apache.clerezza.rdf.core.UriRef)
+     */
+    @Override
+    public TripleCollection getTriples(UriRef name) throws NoSuchEntityException {
+        if(name == null){
+            throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
+        }
+        datasetLock.readLock().lock();
+        try {
+            if(isExistingGraphName(name, Symbols.Graph) || name.equals(defaultGraphName)){
+                return getGraph(name);
+            } else if(isExistingGraphName(name, Symbols.MGraph)){
+                return getMGraph(name);
+            } else {
+                throw new NoSuchEntityException(name);
+            }
+        } finally {
+            datasetLock.readLock().unlock();
+        }
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#listGraphs()
+     */
+    @Override
+    public Set<UriRef> listGraphs() {
+        datasetLock.readLock().lock();
+        try {
+            return new HashSet(new UriRefSet( graphNameIndex, Symbols.Graph ));
+        } finally {
+            datasetLock.readLock().unlock();
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#listMGraphs()
+     */
+    @Override
+    public Set<UriRef> listMGraphs() {
+        datasetLock.readLock().lock();
+        try {
+            return  new HashSet(new UriRefSet( graphNameIndex, Symbols.MGraph ));
+        } finally {
+            datasetLock.readLock().unlock();
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#listTripleCollections()
+     */
+    @Override
+    public Set<UriRef> listTripleCollections() {
+        datasetLock.readLock().lock();
+        try {
+            return  new HashSet(new UriRefSet( graphNameIndex, null ));
+        } finally {
+            datasetLock.readLock().unlock();
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#createMGraph(org.apache.clerezza.rdf.core.UriRef)
+     */
+    @Override
+    public MGraph createMGraph(UriRef name) throws UnsupportedOperationException,
+                                           EntityAlreadyExistsException {
+        if(name == null){
+            throw new IllegalArgumentException("The parsed MGrpah name MUST NOT be NULL!");
+        }
+        datasetLock.writeLock().lock();
+        try {
+            if(isExistingGraphName(name)){
+                throw new EntityAlreadyExistsException(name);
+            }
+            MGraph graph = getModelGraph(name,true,true).getMGraph();
+            addToIndex( name, Symbols.MGraph);
+            return graph;
+        } finally {
+            datasetLock.writeLock().unlock();
+        }
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#createGraph(org.apache.clerezza.rdf.core.UriRef, org.apache.clerezza.rdf.core.TripleCollection)
+     */
+    @Override
+    public Graph createGraph(UriRef name, TripleCollection triples) throws UnsupportedOperationException,
+                                                                   EntityAlreadyExistsException {
+        if(name == null){
+            throw new IllegalArgumentException("The parsed Grpah name MUST NOT be NULL!");
+        }
+        ModelGraph mg;
+        datasetLock.writeLock().lock();
+        try {
+            if(isExistingGraphName(name)){
+                throw new EntityAlreadyExistsException(name);
+            }
+            mg = getModelGraph(name,false,true);
+            addToIndex( name, Symbols.Graph);
+            
+            //add the parsed data!
+            if(triples != null) { //load the initial and final set of triples
+                mg.getJenaAdapter().addAll(triples);
+                mg.sync();
+            }
+        } finally {
+            datasetLock.writeLock().unlock();
+        }
+        return mg.getGraph();
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#deleteTripleCollection(org.apache.clerezza.rdf.core.UriRef)
+     */
+    @Override
+    public void deleteTripleCollection(UriRef name) throws UnsupportedOperationException,
+                                                   NoSuchEntityException,
+                                                   EntityUndeletableException {
+        if(name == null){
+            throw new IllegalArgumentException("The parsed MGrpah name MUST NOT be NULL!");
+        }
+        datasetLock.writeLock().lock();
+        try {
+            if(isExistingGraphName(name,Symbols.MGraph)){
+                ModelGraph mg = getModelGraph(name, true, false);
+                mg.delete();
+                removeFromIndex( name, Symbols.MGraph );
+            } else if(isExistingGraphName(name,Symbols.Graph)){
+                ModelGraph mg = getModelGraph(name, false, false);
+                mg.delete();
+                removeFromIndex( name, Symbols.Graph );
+            } else if (name.equals(defaultGraphName)){
+                throw new EntityUndeletableException(defaultGraphName);
+            }
+            //delete the graph from the initModels list
+            syncModels.remove(name);
+        } finally {
+            datasetLock.writeLock().unlock();
+        }
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#getNames(org.apache.clerezza.rdf.core.Graph)
+     */
+    @Override
+    public Set<UriRef> getNames(Graph graph) {
+        //TODO: this method would require to compare the triples within the graph
+        //      because an equals check will not work with BNodes. 
+        Set<UriRef> graphNames = new HashSet<UriRef>();
+        for( Iterator<Triple> iterator = graphNameIndex.getMGraph().iterator(); iterator.hasNext(); ) {
+            Triple triple = iterator.next();
+            UriRef graphName = new UriRef(triple.getSubject().toString());
+            Graph currentGraph = getModelGraph(graphName, false, false).getGraph();
+            if(graph.equals(currentGraph)){
+                graphNames.add(graphName);
+            }
+        }
+        return graphNames;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.access.WeightedTcProvider#getWeight()
+     */
+    @Override
+    public int getWeight() {
+        return weight;
+    }
+    
+    /**
+     * Substitutes ${property.name} with the values retrieved via <ul>
+     * <li> {@link BundleContext#getProperty(String)} or
+     * <li> {@link System#getProperty(String, String)} if the parsed
+     * {@link BundleContext} is <code>null</code>
+     * </ul>
+     * Substitutes with an empty string if the property is not present. If
+     * the substitution does not end with {@link File#separatorChar}, than it is
+     * appended to allow easily creating paths relative to root directory available
+     * as property regardless if the property includes/excludes the final
+     * separator char.
+     * <p>
+     * Nested substitutions are NOT supported. However multiple substitutions are supported.
+     * <p>
+     * If someone knows a default implementation feel free to replace!
+     * 
+     * @param value
+     *            the value to substitute
+     * @param bundleContext
+     *            If not <code>null</code> the {@link BundleContext#getProperty(String)} is used instead of
+     *            the {@link System#getProperty(String)}. By that it is possible to use OSGI only properties
+     *            for substitution.
+     * @return the substituted value
+     */
+    private static String substituteProperty(String value, BundleContext bundleContext) {
+        int prevAt = 0;
+        int foundAt = 0;
+        StringBuilder substitution = new StringBuilder();
+        while ((foundAt = value.indexOf("${", prevAt)) >= prevAt) {
+            substitution.append(value.substring(prevAt, foundAt));
+            String propertyName = value.substring(foundAt + 2, value.indexOf('}', foundAt));
+            String propertyValue = bundleContext == null ? // if no bundleContext is available
+            System.getProperty(propertyName) : // use the System properties
+                    bundleContext.getProperty(propertyName);
+            if(propertyValue != null) {
+                substitution.append(propertyValue);
+                if(propertyValue.charAt(propertyValue.length()-1) != File.separatorChar){
+                    substitution.append(File.separatorChar);
+                }
+            } //else nothing to append
+            prevAt = foundAt + propertyName.length() + 3; // +3 -> "${}".length
+        }
+        substitution.append(value.substring(prevAt, value.length()));
+        return substitution.toString();
+    }
+
+    /**
+     * Checks whether the given graph name already exists as the specified resource (either graph or mgraph).
+     * @param graphName the graph name
+     * @param graphType the resource type
+     * @return true if a resource with the given name and type already exists, false otherwise.
+     */
+    private boolean isExistingGraphName(UriRef graphName, UriRef graphType) {
+        return graphNameIndex.getMGraph().filter(graphName, RDF.type, graphType).hasNext();
+    }
+
+    /**
+     * Checks whether the given graph name already exists as either a graph or mgraph.
+     * @param graphName the graph name
+     * @return true if a graph or mgraph with the given name already exists, false otherwise.
+     */
+    private boolean isExistingGraphName(UriRef graphName) {
+        return isExistingGraphName(graphName, null);
+    }
+    
+    /**
+     * Adds a new graphname to the index of graphnames  
+     * @param graphName name of the graph
+     * @param graphType resourcetype for the graph to add.
+     */
+    private void addToIndex(UriRef graphName, UriRef graphType) {
+        graphNameIndex.getMGraph().add(new TripleImpl(graphName, RDF.type, graphType));
+        graphNameIndex.sync();
+    }
+    
+    /**
+     * Removes a graphanem from the index of graphnames
+     * @param graphName name of the graph to remove
+     * @param graphType resource type of the graph to remove.
+     */
+    private void removeFromIndex(UriRef graphName, UriRef graphType) {
+        MGraph index = graphNameIndex.getMGraph();
+        Iterator<Triple> triplesToRemove = index.filter(graphName, RDF.type, graphType);
+        for( ; triplesToRemove.hasNext(); ) {
+            triplesToRemove.next();
+            triplesToRemove.remove();
+        }
+        graphNameIndex.sync();
+    }
+    
+    private void removeDefaultGraphFromIndex() {
+      MGraph index = graphNameIndex.getMGraph();
+      Iterator<Triple> triplesToRemove = index.filter(null, RDF.type, Symbols.Default);
+      for( ; triplesToRemove.hasNext(); ) {
+          Triple triple = triplesToRemove.next();
+          triplesToRemove.remove();
+          removeFromIndex( UriRef.class.cast(triple.getSubject()), Symbols.Graph );
+      }
+      graphNameIndex.sync();
+    }
+} 

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
new file mode 100644
index 0000000..f8924fc
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
@@ -0,0 +1,434 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.tdb.TDB;
+import com.hp.hpl.jena.tdb.TDBFactory;
+import com.hp.hpl.jena.tdb.base.block.FileMode;
+import com.hp.hpl.jena.tdb.sys.SystemTDB;
+import java.io.File;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+import java.util.logging.Level;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
+import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
+import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.util.PrivilegedMGraphWrapper;
+import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+
+/**
+ * A {@link org.apache.clerezza.rdf.core.access.WeightedTcProvider} based on
+ * Jena TDB.
+ *
+ * @see <a href="http://jena.hpl.hp.com/wiki/TDB/JavaAPI">
+ * TDB/JavaAPI</a>
+ *
+ * @author reto, hasan
+ *
+ *
+ */
+@Component(metatype = true, immediate = true)
+@Service(WeightedTcProvider.class)
+@Properties({
+    @Property(name = "weight", intValue = 107),
+    @Property(name = TcManager.GENERAL_PURPOSE_TC, boolValue = true)})
+public class TdbTcProvider implements WeightedTcProvider {
+
+    static {
+        //not sure what the perfomance implication of this is
+        //it is only needed so that on windows the files of a dataset can be deleteds
+        SystemTDB.setFileMode(FileMode.direct);
+    }
+    @Property(intValue = 6, description = "Specifies the number of seconds to wait "
+            + "between synchronizations of the TDB datasets to the filesystem")
+    public static final String SYNC_INTERVAL = "sync-interval";
+    private int syncInterval = 6;
+    /**
+     * directory where all graphs are stored
+     */
+    private static final String DATA_PATH_NAME = "tdb-data/";
+    private String dataPathString = DATA_PATH_NAME;
+    private Map<UriRef, LockableMGraph> mGraphMap = new HashMap<UriRef, LockableMGraph>();
+    private Map<UriRef, Graph> graphMap = new HashMap<UriRef, Graph>();
+    private Map<File, com.hp.hpl.jena.graph.Graph> dir2JenaGraphMap = new HashMap<File, com.hp.hpl.jena.graph.Graph>();
+    private Map<File, Lock> dir2Lock = new HashMap<File, Lock>();
+    private final Map<File, Dataset> dir2Dataset = new HashMap<File, Dataset>();
+    private static final Logger log = LoggerFactory.getLogger(TdbTcProvider.class);
+    private int weight = 107;
+
+    class SyncThread extends Thread {
+
+        private boolean stopRequested = false;
+
+        @Override
+        public void run() {
+            while (!stopRequested) {
+                try {
+                    Thread.sleep(syncInterval * 1000);
+                } catch (InterruptedException ex) {
+                    interrupt();
+                }
+                if (!stopRequested) {
+                    syncWithFileSystem();
+                }
+            }
+        }
+
+        public void requestStop() {
+            stopRequested = true;
+        }
+    }
+    private SyncThread syncThread;
+
+    public TdbTcProvider() {
+    }
+
+    TdbTcProvider(File directory) {
+        dataPathString = directory.getAbsolutePath();
+        loadMGraphs();
+        loadGraphs();
+    }
+
+    public void activate(ComponentContext cCtx) {
+        log.info("Activating TDB provider");
+        if (cCtx != null) {
+            weight = (Integer) cCtx.getProperties().get("weight");
+            dataPathString = cCtx.getBundleContext().
+                    getDataFile(DATA_PATH_NAME).getAbsolutePath();
+            syncInterval = Integer.parseInt(cCtx.getProperties().get(SYNC_INTERVAL).toString());
+        }
+        loadMGraphs();
+        loadGraphs();
+        syncThread = new SyncThread();
+        syncThread.start();
+    }
+
+    public void deactivate(ComponentContext cCtx) {
+        syncThread.requestStop();
+        syncThread = null;
+        for (com.hp.hpl.jena.graph.Graph jenaGraph : dir2JenaGraphMap.values()) {
+            jenaGraph.close();
+        }
+        synchronized (dir2Dataset) {
+            for (Dataset dataset : dir2Dataset.values()) {
+                dataset.close();
+            }
+        }
+    }
+
+    @Override
+    public int getWeight() {
+        return weight;
+    }
+
+    @Override
+    public Graph getGraph(UriRef name) throws NoSuchEntityException {
+        if (!graphMap.containsKey(name)) {
+            throw new NoSuchEntityException(name);
+        }
+        return graphMap.get(name);
+    }
+
+    @Override
+    public synchronized MGraph getMGraph(UriRef name) throws NoSuchEntityException {
+        if (!mGraphMap.containsKey(name)) {
+            throw new NoSuchEntityException(name);
+        }
+        return mGraphMap.get(name);
+    }
+
+    @Override
+    public TripleCollection getTriples(UriRef name) throws NoSuchEntityException {
+        try {
+            return getMGraph(name);
+        } catch (NoSuchEntityException e) {
+            return getGraph(name);
+        }
+    }
+
+    @Override
+    public synchronized MGraph createMGraph(UriRef name)
+            throws UnsupportedOperationException, EntityAlreadyExistsException {
+        File tcDir = getMGraphDir(name);
+        if (tcDir.exists()) {
+            throw new EntityAlreadyExistsException(name);
+        }
+        tcDir.mkdirs();
+        File otimizationIndicator = new File(tcDir, "fixed.opt");
+        try {
+            otimizationIndicator.createNewFile();
+        } catch (IOException ex) {
+            throw new RuntimeException(ex);
+        }
+        LockableMGraph result = new LockableMGraphWrapper(getMGraph(tcDir));
+        dir2Lock.put(tcDir, result.getLock().writeLock());
+        mGraphMap.put(name, result);
+        return result;
+    }
+
+    @Override
+    public Graph createGraph(UriRef name, TripleCollection triples)
+            throws UnsupportedOperationException, EntityAlreadyExistsException {
+        File tcDir = getGraphDir(name);
+        if (tcDir.exists()) {
+            throw new EntityAlreadyExistsException(name);
+        }
+
+        if (triples == null) {
+            triples = new SimpleMGraph();
+        }
+        tcDir.mkdirs();
+        File otimizationIndicator = new File(tcDir, "fixed.opt");
+        try {
+            otimizationIndicator.createNewFile();
+        } catch (IOException ex) {
+            throw new RuntimeException(ex);
+        }
+        MGraph mGraph = getMGraph(tcDir);
+        mGraph.addAll(triples);
+        Graph result = mGraph.getGraph();
+        TDB.sync(dir2Dataset.get(tcDir));
+        graphMap.put(name, result);
+        return result;
+    }
+
+    @Override
+    public void deleteTripleCollection(UriRef name)
+            throws UnsupportedOperationException, NoSuchEntityException,
+            EntityUndeletableException {
+        syncWithFileSystem();
+        if (deleteTcDir(getGraphDir(name))) {
+            graphMap.remove(name);
+            return;
+        }
+        if (deleteTcDir(getMGraphDir(name))) {
+            mGraphMap.remove(name);
+            return;
+        }
+        throw new NoSuchEntityException(name);
+    }
+
+    private boolean deleteTcDir(File tcDir) {
+        if (tcDir.exists()) {
+            dir2JenaGraphMap.get(tcDir).close();
+            dir2JenaGraphMap.remove(tcDir);
+            synchronized (dir2Dataset) {
+                dir2Dataset.get(tcDir).close();
+                dir2Dataset.remove(tcDir);
+            }
+            try {
+                delete(tcDir);
+            } catch (IOException ex) {
+                for (int i = 0; i < 10; i++) {
+                    try {
+                        System.gc();
+                        delete(tcDir);
+                    } catch (IOException ex1) {
+                        try {
+                            Thread.sleep(10);
+                        } catch (InterruptedException ex2) {
+                            Thread.currentThread().interrupt();
+                        }
+                        continue;
+                    }
+                    return true;
+                }
+                throw new RuntimeException(ex);
+            }
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Cleans the content of the specified directory recursively.
+     *
+     * @param dir Abstract path denoting the directory to clean.
+     */
+    private static void cleanDirectory(File dir) throws IOException {
+        File[] files = dir.listFiles();
+        if (files != null && files.length > 0) {
+            for (File file : files) {
+                delete(file);
+            }
+        }
+    }
+
+    /**
+     * Deletes the specified file or directory.
+     *
+     * @param file Abstract path denoting the file or directory to clean.
+     */
+    protected static void delete(File file) throws IOException {
+        if (file.isDirectory()) {
+            cleanDirectory(file);
+        }
+        //better but only in java 7
+        //java.nio.file.Files.delete(file.toPath());
+        if (!file.delete()) {
+            throw new IOException("couldn't delete " + file.getAbsolutePath());
+        }
+    }
+
+    @Override
+    public Set<UriRef> getNames(Graph graph) {
+        //this could be done more efficiently with an index, could be done with
+        //a MultiBidiMap (BidiMap allowing multiple keys for the same value)
+        Set<UriRef> result = new HashSet<UriRef>();
+        for (UriRef name : listGraphs()) {
+            if (getGraph(name).equals(graph)) {
+                result.add(name);
+            }
+        }
+        return result;
+    }
+
+    @Override
+    public Set<UriRef> listTripleCollections() {
+        Set<UriRef> result = new HashSet<UriRef>();
+        result.addAll(listGraphs());
+        result.addAll(listMGraphs());
+        return result;
+    }
+
+    @Override
+    public Set<UriRef> listGraphs() {
+        return graphMap.keySet();
+    }
+
+    @Override
+    public Set<UriRef> listMGraphs() {
+        return mGraphMap.keySet();
+    }
+
+    private Graph getGraph(File tcDir) {
+        return getMGraph(tcDir).getGraph();
+    }
+
+    private File getGraphDir(UriRef name) {
+        File base = new File(dataPathString);
+        return getTcDir(new File(base, "graph"), name);
+    }
+
+    private MGraph getMGraph(File tcDir) {
+        Dataset dataset = TDBFactory.createDataset(tcDir.getAbsolutePath());
+        Model model = dataset.getDefaultModel();
+        //Model model = TDBFactory.createModel(tcDir.getAbsolutePath());
+        final com.hp.hpl.jena.graph.Graph jenaGraph = model.getGraph();
+        dir2JenaGraphMap.put(tcDir, jenaGraph);
+        //dataset.
+        synchronized (dir2Dataset) {
+            dir2Dataset.put(tcDir, dataset);
+        }
+        return new PrivilegedMGraphWrapper(new JenaGraphAdaptor(jenaGraph));
+    }
+
+    private File getMGraphDir(UriRef name) {
+        File base = new File(dataPathString);
+        return getTcDir(new File(base, "mgraph"), name);
+    }
+
+    private File getTcDir(File directory, UriRef name) {
+        try {
+            String subDirName = URLEncoder.encode(name.getUnicodeString(), "utf-8");
+            return new File(directory, subDirName);
+        } catch (UnsupportedEncodingException ex) {
+            throw new RuntimeException("utf-8 not supported", ex);
+        }
+    }
+
+    private void loadGraphs() {
+        File graphsDir = new File(new File(dataPathString), "graph");
+        if (graphsDir.exists()) {
+            for (String graphDirName : graphsDir.list()) {
+                try {
+                    UriRef uri = new UriRef(URLDecoder.decode(graphDirName, "utf-8"));
+                    log.info("loading: " + graphDirName);
+                    graphMap.put(uri, getGraph(new File(graphsDir, graphDirName)));
+                } catch (UnsupportedEncodingException ex) {
+                    throw new RuntimeException("utf-8 not supported", ex);
+                } catch (Exception e) {
+                    log.error("Could not load tdb graph in " + graphDirName, e);
+                }
+            }
+        }
+    }
+
+    private void loadMGraphs() {
+        File mGraphsDir = new File(new File(dataPathString), "mgraph");
+        if (mGraphsDir.exists()) {
+            for (String mGraphDirName : mGraphsDir.list()) {
+                try {
+                    UriRef uri = new UriRef(URLDecoder.decode(mGraphDirName, "utf-8"));
+                    log.info("loading: " + mGraphDirName);
+                    final File tcDir = new File(mGraphsDir, mGraphDirName);
+                    final LockableMGraphWrapper lockableMGraph = new LockableMGraphWrapper(getMGraph(tcDir));
+                    mGraphMap.put(uri, lockableMGraph);
+                    dir2Lock.put(tcDir, lockableMGraph.getLock().writeLock());
+                } catch (UnsupportedEncodingException ex) {
+                    throw new RuntimeException("utf-8 not supported", ex);
+                } catch (Exception e) {
+                    log.error("Could not load tdb graph in " + mGraphDirName, e);
+                }
+            }
+        }
+    }
+
+    public void syncWithFileSystem() {
+        synchronized (dir2Dataset) {
+            for (Map.Entry<File, Dataset> entry : dir2Dataset.entrySet()) {
+                Lock l = dir2Lock.get(entry.getKey());
+                if (l == null) {
+                    return;
+                }
+                l.lock();
+                try {
+                    TDB.sync(entry.getValue());
+                } finally {
+                    l.unlock();
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider b/rdf/jena/tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider
new file mode 100644
index 0000000..5dbaf81
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider
@@ -0,0 +1 @@
+org.apache.clerezza.rdf.jena.tdb.storage.TdbTcProvider
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties b/rdf/jena/tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties
new file mode 100644
index 0000000..b2488eb
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -0,0 +1,47 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Deactivate properties for component because those are not common for Apache Clerezza
+#org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider.name=Apache Stanbol Clerezza \
+#Single Jena TDB Provider
+#org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider.description=Tc Provider \
+#implementation that stores Clerezza TripleCollections as named graphs in a single Jena \
+#TDB store.
+
+#==============================================================
+#Properties and Options used to configure TDB dataset providers
+#==============================================================
+
+tdb-dir.name=Jena TDB directory
+tdb-dir.description= The directory for Jena the TDB database. This field \
+supports property substitution: '${property}' will be replaced with the value \
+of the 'property' available via the BundleContext or the system properties \
+(e.g. "${myHome}/myRdfStore")
+default-graph-name.name=Default Graph Name
+default-graph-name.description=The URI name of the default graph of the Jena \
+TDB database. Requests to the TcProvider with this URI will return an MGraph \
+that is the union over all the graphs managed by this TcProvider. If empty or \
+not defined the default graph is not exposed.
+weight.name=Weight
+weight.description=The weight of this TcProvider. Set to an low value (e.g. \
+value < 0) if you want to inject this instance by using a Filter. Set to a high \
+value (e.g. values > 1000) if you want this instance to be the default used by \
+Clerezza.
+sync-interval.name=Sync Interval
+sync-interval.description=The interval in seconds until changes are saved to \
+the file system. Sync will always occur if this provider is deactivated. However \
+on crashes all data since the last sync will be lost. The default is 6sec. \
+Higher values will reduce the overhead for periodically writing to the file \
+system.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
new file mode 100644
index 0000000..ac0dc89
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
@@ -0,0 +1,261 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.service.cm.ConfigurationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.wymiwyg.commons.util.Util;
+
+
+public class MultiThreadedSingleTdbDatasetTest {
+    
+    private Logger log = LoggerFactory.getLogger(MultiThreadedSingleTdbDatasetTest.class);
+    
+    private static final String TEST_GRAPH_URI_PREFIX = "http://www.example.org/multiThreadTest";
+    private int[] graphNum = new int[]{0};
+    /** 
+     * how many threads to start
+     */
+    private static final int TEST_THREAD_COUNT = 25;
+    private static final int VALIDATE_THREAD_COUNT = 2;
+    /**
+     * how many seconds to let them run
+     */
+    private static final int DELAY = 15;
+    
+    
+    protected final List<MGraph> mGraphs = new ArrayList<MGraph>();
+    protected final List<Set<Triple>> testTriplesList = new ArrayList<Set<Triple>>();
+    private Random random = new Random();
+
+    class TestThread extends Thread {
+
+        private boolean stopRequested;
+        private int addedTripleCount = 0;
+
+        public TestThread(final int id) {
+            setName("Test Thread "+id);
+            start();
+        }
+
+        public void requestStop() {
+            stopRequested = true;
+        }
+
+        @Override
+        public void run() {
+            while (!stopRequested) {
+                float r;
+                synchronized (random) {
+                    r = random.nextFloat();
+                }
+                MGraph graph;
+                Set<Triple> testTriples;
+                if(r > 0.995){
+                    int num;
+                    synchronized (graphNum) {
+                        num = graphNum[0];
+                        graphNum[0]++;
+                    }
+                    graph = provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+num));
+                    log.info(" ... creating the {}. Grpah", num+1);
+                    testTriples = new HashSet<Triple>();
+                    synchronized (mGraphs) {
+                        mGraphs.add(graph);
+                        testTriplesList.add(testTriples);
+                    }
+                } else { //map the range [0..0.995] to the mGraphs
+                    synchronized (mGraphs) {
+                        int num = Math.round(r*(float)(mGraphs.size()-1)/0.995f);
+                        graph = mGraphs.get(num);
+                        testTriples = testTriplesList.get(num);
+                    }
+                }
+                Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
+                Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
+                graph.add(triple);
+                addedTripleCount++;
+                if ((addedTripleCount % 100) == 0) {
+                    testTriples.add(triple);
+                }
+            }
+        }
+
+        public int getAddedTripleCount() {
+            return addedTripleCount;
+        }
+
+    }
+    /**
+     * Iterates over max. the first 10 triples of a Graph
+     * while acquiring a read lock on the graph.
+     * @author westei
+     *
+     */
+    class ValidatorThread extends Thread {
+        
+        boolean stopRequested = false;
+        
+        public ValidatorThread(int id) {
+            setName("Validator Thread "+id);
+            start();
+        }
+        
+        public void requestStop() {
+            stopRequested = true;
+        }
+
+        @Override
+        public void run() {
+            while (!stopRequested) {
+                float r;
+                synchronized (random) {
+                    r = random.nextFloat();
+                }
+                int num = Math.round(r*(float)(mGraphs.size()-1));
+                LockableMGraph graph;
+                synchronized (mGraphs) {
+                    graph = (LockableMGraph)mGraphs.get(num);
+                }
+                int elem = 0;
+                graph.getLock().readLock().lock();
+                try {
+                    Iterator<Triple> it = graph.iterator();
+                    while(it.hasNext() && elem < 10){
+                        elem++;
+                        it.next();
+                    }
+                } finally {
+                    graph.getLock().readLock().unlock();
+                }
+                //iterate inly every 200ms
+                try {
+                    Thread.sleep(200);
+                } catch (InterruptedException e) {
+                    //ignore
+                }
+            }
+        }
+        
+        
+        
+    }
+
+    
+    
+    private static File tempFile;
+    private static Dictionary<String,Object> config;
+    private static SingleTdbDatasetTcProvider provider;
+    @BeforeClass
+    public static void setup() throws IOException, ConfigurationException {
+        tempFile = File.createTempFile("tdbdatasettest", null);
+        tempFile.delete();
+        tempFile.mkdirs();
+        config = new Hashtable<String,Object>();
+        config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
+        provider = new SingleTdbDatasetTcProvider(config);
+    }
+    @Before
+    public void createGraphs(){
+        mGraphs.add(provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+graphNum[0])));
+        testTriplesList.add(new HashSet<Triple>());
+        graphNum[0]++;
+        mGraphs.add(provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+graphNum[0])));
+        testTriplesList.add(new HashSet<Triple>());
+        graphNum[0]++;
+    }
+    @Test
+    public void perform() throws InterruptedException {
+        TestThread[] threads =  new TestThread[TEST_THREAD_COUNT];
+        for (int i = 0; i < threads.length; i++) {
+            threads[i] = new TestThread(i);
+        }
+        ValidatorThread[] validators = new ValidatorThread[VALIDATE_THREAD_COUNT];
+        for(int i = 0; i < validators.length; i++) {
+            validators [i] = new ValidatorThread(i);
+        }
+        Thread.sleep(DELAY*1000);
+        for (TestThread testThread : threads) {
+            testThread.requestStop();
+        }
+        for (ValidatorThread validator : validators) {
+            validator.requestStop();
+        }
+        for (TestThread testThread : threads) {
+            testThread.join();
+        }
+        for (ValidatorThread validator : validators) {
+            validator.join();
+        }
+        int addedTriples = 0;
+        for (TestThread testThread : threads) {
+            addedTriples += testThread.getAddedTripleCount();
+        }
+        int graphTriples = 0;
+        log.info("Test created {} graphs with {} triples", mGraphs.size(), addedTriples);
+        for(int i = 0;i < mGraphs.size(); i++){
+            MGraph graph = mGraphs.get(i);
+            graphTriples += graph.size();
+            log.info("  > Grpah {}: {} triples",i,graph.size());
+            for (Triple testTriple : testTriplesList.get(i)) {
+                Assert.assertTrue(graph.contains(testTriple));
+            }
+        }
+        Assert.assertEquals(addedTriples, graphTriples);
+    }
+    @AfterClass
+    public static void cleanUpDirectory() throws IOException {
+        provider.deactivate(null);
+        try {
+            TdbTcProvider.delete(tempFile);
+        } catch (IOException e) {
+            System.err.println("Failed removing tempfile "+tempFile);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
new file mode 100644
index 0000000..91791c3
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
@@ -0,0 +1,143 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.felix.scr.annotations.Activate;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.wymiwyg.commons.util.Util;
+
+
+public class MultiThreadedTest {
+    
+    
+    
+    /** 
+     * how many threads to start
+     */
+    private static final int THREAD_COUNT = 200;
+    /**
+     * how many seconds to let them run
+     */
+    private static final int DELAY = 15;
+    
+    
+    private MGraph mGraph;
+    private Set<Triple> testTriples = Collections.synchronizedSet(new HashSet<Triple>()); 
+
+    class TestThread extends Thread {
+
+        private final int id;
+        private boolean stopRequested;
+        private int addedTripleCount = 0;
+        private Object exception;
+
+        public TestThread(final int id) {
+            this.id = id;
+            start();
+        }
+
+        public void requestStop() {
+            stopRequested = true;
+        }
+
+        @Override
+        public void run() {
+            while (!stopRequested) {
+                try {
+                    Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
+                    Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
+                    mGraph.add(triple);
+                    addedTripleCount++;
+                    if ((addedTripleCount % 100) == 0) {
+                        testTriples.add(triple);
+                    }
+                } catch (Exception e) {
+                    exception = e;
+                }
+            }
+        }
+
+        public int getAddedTripleCount() {
+            return addedTripleCount;
+        }
+
+    }
+
+    
+    
+    @Before
+    public void setUp() throws IOException {
+        File tempFile;
+        UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
+        TdbTcProvider tdbTcProvider;
+        tempFile = File.createTempFile("tdbtest", null);
+        tempFile.delete();
+        tempFile.mkdirs();
+        tdbTcProvider = new TdbTcProvider(tempFile);
+        tdbTcProvider.activate(null);
+        mGraph = tdbTcProvider.createMGraph(MGRAPHNAME);
+    }
+
+    @Test
+    public void perform() throws InterruptedException {
+        TestThread[] threads =  new TestThread[THREAD_COUNT];
+        for (int i = 0; i < threads.length; i++) {
+            threads[i] = new TestThread(i);
+        }
+        Thread.sleep(DELAY*1000);
+        for (TestThread testThread : threads) {
+            testThread.requestStop();
+        }
+        for (TestThread testThread : threads) {
+            testThread.join();
+        }
+        int addedTriples = 0;
+        for (TestThread testThread : threads) {
+            addedTriples += testThread.getAddedTripleCount();
+        }
+        Assert.assertEquals(addedTriples, mGraph.size());
+        for (Triple testTriple : testTriples) {
+            Assert.assertTrue(mGraph.contains(testTriple));
+        }
+        for (TestThread testThread : threads) {
+            Assert.assertNull(testThread.exception);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
new file mode 100644
index 0000000..76505b3
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
@@ -0,0 +1,150 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcProvider;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.felix.scr.annotations.Activate;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.service.cm.ConfigurationException;
+import org.wymiwyg.commons.util.Util;
+
+
+public class MultiThreadedTestSingleTdb {
+    
+    
+    
+    /** 
+     * how many threads to start
+     */
+    private static final int THREAD_COUNT = 100;
+    /**
+     * how many seconds to let them run
+     */
+    private static final int DELAY = 15;
+    
+    
+    private MGraph mGraph;
+    private Set<Triple> testTriples = Collections.synchronizedSet(new HashSet<Triple>()); 
+
+    class TestThread extends Thread {
+
+        private final int id;
+        private boolean stopRequested;
+        private int addedTripleCount = 0;
+        private Object exception;
+
+        public TestThread(final int id) {
+            this.id = id;
+            start();
+        }
+
+        public void requestStop() {
+            stopRequested = true;
+        }
+
+        @Override
+        public void run() {
+            while (!stopRequested) {
+                try {
+                    Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
+                    Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
+                    mGraph.add(triple);
+                    addedTripleCount++;
+                    if ((addedTripleCount % 100) == 0) {
+                        testTriples.add(triple);
+                    }
+                } catch (Exception e) {
+                    exception = e;
+                }
+            }
+        }
+
+        public int getAddedTripleCount() {
+            return addedTripleCount;
+        }
+
+    }
+
+    
+    
+    @Before
+    public void setUp() throws IOException, ConfigurationException {
+        File tempFile;
+        UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
+        TcProvider tdbTcProvider;
+        tempFile = File.createTempFile("tdbtest", null);
+        tempFile.delete();
+        tempFile.mkdirs();
+        Dictionary<String, Object> dict = new Hashtable<String, Object>();
+        dict.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
+        tdbTcProvider = new SingleTdbDatasetTcProvider(dict);
+        //tdbTcProvider.activate(null);
+        mGraph = tdbTcProvider.createMGraph(MGRAPHNAME);
+    }
+
+    @Test
+    public void perform() throws InterruptedException {
+        TestThread[] threads =  new TestThread[THREAD_COUNT];
+        for (int i = 0; i < threads.length; i++) {
+            threads[i] = new TestThread(i);
+        }
+        Thread.sleep(DELAY*1000);
+        for (TestThread testThread : threads) {
+            testThread.requestStop();
+        }
+        for (TestThread testThread : threads) {
+            testThread.join();
+        }
+        int addedTriples = 0;
+        for (TestThread testThread : threads) {
+            addedTriples += testThread.getAddedTripleCount();
+        }
+        Assert.assertEquals(addedTriples, mGraph.size());
+        for (Triple testTriple : testTriples) {
+            Assert.assertTrue(mGraph.contains(testTriple));
+        }
+        for (TestThread testThread : threads) {
+            Assert.assertNull(testThread.exception);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
new file mode 100644
index 0000000..cc3741b
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
@@ -0,0 +1,56 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.test.MGraphTest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.osgi.service.cm.ConfigurationException;
+
+public class SingleTdbDatasetMGraphTest extends MGraphTest {
+
+    private static final String MGRAPHNAME_PREFIX = "http://text.example.org/testGraph";
+    private static UriRef UNION_GRAPH_NAME = new UriRef("http://www.example.org/unionGraph");
+    private static int testGraphCounter = 0;
+
+    private static File tempFile;
+    private static Dictionary<String,Object> config;
+    private static SingleTdbDatasetTcProvider provider;
+
+    @BeforeClass
+    public static void setup() throws IOException, ConfigurationException {
+        tempFile = File.createTempFile("tdbdatasettest", null);
+        tempFile.delete();
+        tempFile.mkdirs();
+        config = new Hashtable<String,Object>();
+        config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
+        config.put(SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME, UNION_GRAPH_NAME.getUnicodeString());
+        provider = new SingleTdbDatasetTcProvider(config);
+    }
+    
+    @AfterClass
+    public static void cleanUpDirectory() throws IOException {
+        for(int i = 0; i < testGraphCounter;i++){
+            provider.deleteTripleCollection(new UriRef(MGRAPHNAME_PREFIX+i));
+        }
+        provider.deactivate(null);
+        try {
+            TdbTcProvider.delete(tempFile);
+        } catch (IOException e) {
+            System.err.println("Couldn't remove "+tempFile);
+        }
+    }
+
+    @Override
+    protected MGraph getEmptyMGraph() {
+        MGraph graph = provider.createMGraph(new UriRef(MGRAPHNAME_PREFIX+testGraphCounter));
+        testGraphCounter++;
+        return graph;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
new file mode 100644
index 0000000..b3849dd
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
@@ -0,0 +1,168 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
+import org.apache.clerezza.rdf.core.access.TcProvider;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.core.test.TcProviderTest;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.service.cm.ConfigurationException;
+
+public class SingleTdbDatasetTcProviderTest extends TcProviderTest {
+
+    private static File tempFile;
+    private static Dictionary<String,Object> config;
+    private static SingleTdbDatasetTcProvider provider;
+    private static UriRef UNION_GRAPH_NAME = new UriRef("http://www.example.org/unionGraph");
+    
+    @Before
+    public void setup() throws IOException, ConfigurationException {
+        tempFile = File.createTempFile("tdbdatasettest", null);
+        tempFile.delete();
+        tempFile.mkdirs();
+        config = new Hashtable<String,Object>();
+        config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
+        config.put(SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME, UNION_GRAPH_NAME.getUnicodeString());
+        //config.put(SingleTdbDatasetTcProvider.USE_GRAPH_NAME_SUFFIXES, true);
+    }
+    
+    @Override
+    protected TcProvider getInstance() {
+        //tests want us to deactivate/activate the TcProvider on multiple calls
+        //to getInstance within the same test
+        if(provider !=null){
+            try {
+                provider.deactivate(null);
+                provider = null;
+            } catch (Exception e) {
+                System.err.println("Error cleaning up: "+e.getMessage());
+            }
+        }
+        try {
+            provider = new SingleTdbDatasetTcProvider(config);
+        } catch (Exception e) {
+            throw new RuntimeException("forwarding ...",e);
+        }
+        return provider;
+    }
+
+    @After
+    public void cleanData() throws IOException{
+        //We need to remove all remaining data after a test
+        if(provider != null){
+            try {
+                provider.deactivate(null);
+                TdbTcProvider.delete(tempFile);
+                provider = null;
+            } catch (Exception e) {
+                System.err.println("Error cleaning up: "+e.getMessage());
+            }
+        }
+    }
+    
+    /**
+     * The union graph is read only!
+     */
+    @Test(expected=NoSuchEntityException.class)
+    public void testUnionMgraph(){
+        TcProvider provider = getInstance();
+        provider.getMGraph(UNION_GRAPH_NAME);
+    }
+    
+    /**
+     * Assert union graph on an empty dataset
+     */
+    @Test
+    public void testEmptyUnionGraph(){
+        TcProvider provider = getInstance();
+        Graph graph = provider.getGraph(UNION_GRAPH_NAME);
+        Assert.assertNotNull(graph);
+    }
+    
+    @Test
+    public void testUnionGraph() throws Exception{
+        TcProvider provider = getInstance();
+        UriRef type = new UriRef("http://www.w3.org/2000/01/rdf-schema#type");
+        UriRef name = new UriRef("http://schema.org/name");
+        UriRef personType = new UriRef("http://schema.org/Person");
+        UriRef companyType = new UriRef("http://schema.org/Company");
+        UriRef worksFor = new UriRef("http://schema.org/works-for");
+
+        //create a graph with persons
+        MGraph persons = new SimpleMGraph();
+        UriRef tim = new UriRef("http://people.org/tim.johnson");
+        persons.add(new TripleImpl(tim, type, personType));
+        persons.add(new TripleImpl(tim, name, new PlainLiteralImpl("Tim Johnson")));
+        UriRef john = new UriRef("http://people.org/john.swenson");
+        persons.add(new TripleImpl(john, type, personType));
+        persons.add(new TripleImpl(john, name, new PlainLiteralImpl("John Swenson")));
+        provider.createGraph(new UriRef("urn:persons"), persons.getGraph());
+        
+        //create a MGraph with data about persons
+        MGraph orgdata = provider.createMGraph(new UriRef("urn:orgdata"));
+        UriRef talinor = new UriRef("http://company.org/talinor");
+        orgdata.add(new TripleImpl(talinor, type, companyType));
+        orgdata.add(new TripleImpl(talinor, name, new PlainLiteralImpl("Talinor Inc.")));
+        orgdata.add(new TripleImpl(john, worksFor, talinor));
+        UriRef kondalor = new UriRef("http://company.org/kondalor");
+        orgdata.add(new TripleImpl(kondalor, type, companyType));
+        orgdata.add(new TripleImpl(kondalor, name, new PlainLiteralImpl("Kondalor Ges.m.b.H.")));
+        orgdata.add(new TripleImpl(tim, worksFor, kondalor));
+        
+        //now get the union graph
+        Graph data = provider.getGraph(UNION_GRAPH_NAME);
+        Assert.assertNotNull(data);
+        //CLEREZZA-714: getTriples need to correctly return the UnionGraph
+        data = (Graph)provider.getTriples(UNION_GRAPH_NAME);
+        Assert.assertNotNull(data);
+        //NOTE: Jena TDB does not support getSize for the union graph
+//        int expectedTripleCount = persons.size()+orgdata.size();
+//        Assert.assertEquals("Uniongraph has "+data.size()
+//            +" triples (expected "+expectedTripleCount+")",
+//            expectedTripleCount, data.size());
+        Iterator<Triple> it = data.filter(null, type, companyType);
+        Set<UriRef> expected = new HashSet<UriRef>(Arrays.asList(talinor,kondalor));
+        while(it.hasNext()){
+            NonLiteral subject = it.next().getSubject();
+            Assert.assertTrue("Unexpected "+subject, expected.remove(subject));
+        }
+        Assert.assertTrue("Missing "+expected, expected.isEmpty());
+
+        it = data.filter(null, type, personType);
+        expected = new HashSet<UriRef>(Arrays.asList(john,tim));
+        while(it.hasNext()){
+            NonLiteral subject = it.next().getSubject();
+            Assert.assertTrue("Unexpected "+subject, expected.remove(subject));
+        }
+        Assert.assertTrue("Missing "+expected, expected.isEmpty());
+    }
+    
+    @Test
+    public void testListGraph(){
+    	TcProvider provider = getInstance();
+    	//No union graph in listMGraphs
+    	Set<UriRef> mgl = provider.listMGraphs();
+        Assert.assertFalse("Mgraph list don't contain the read-only union-graph", mgl.contains(UNION_GRAPH_NAME));
+        //Union graph in listGraphs
+        Set<UriRef> gl = provider.listGraphs();
+        Assert.assertTrue("Graph list contain the read-only union-graph", gl.contains(UNION_GRAPH_NAME));
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
new file mode 100644
index 0000000..e09c0e4
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Iterator;
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TypedLiteral;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.core.test.MGraphTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class TdbMGraphTest extends MGraphTest {
+    private static File tempFile;
+    final private UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
+    static private TdbTcProvider tdbTcProvider;
+
+    @BeforeClass
+    public static void setupDirectory() throws IOException {
+        tempFile = File.createTempFile("tdbtest", null);
+        tempFile.delete();
+        tempFile.mkdirs();
+        tdbTcProvider = new TdbTcProvider(tempFile);
+    }
+
+    @AfterClass
+    public static void cleanUpDirectory() throws IOException {
+        try {
+            TdbTcProvider.delete(tempFile);
+        } catch (IOException e) {
+            System.err.println("failed to delete temp directory: "+tempFile);
+        }
+    }
+
+    @After
+    public void cleanUpGraph() {
+        tdbTcProvider.deleteTripleCollection(MGRAPHNAME);
+    }
+
+    @Override
+    protected MGraph getEmptyMGraph() {
+        return tdbTcProvider.createMGraph(MGRAPHNAME);
+    }
+
+    @Test
+    public void dateStorage() {
+        MGraph graph = getEmptyMGraph();
+        Date date = new Date(0);
+        LiteralFactory literalFactory = LiteralFactory.getInstance();
+        TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
+        Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), dateLiteral);
+        graph.add(triple);
+        Assert.assertTrue(graph.contains(triple));
+    }
+
+    @Test
+    public void dateStorage2() {
+        MGraph graph = getEmptyMGraph();
+        Date date = new Date(0);
+        LiteralFactory literalFactory = LiteralFactory.getInstance();
+        TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
+        System.out.println(dateLiteral);
+        UriRef property = new UriRef("http://example.com/property");
+        Triple triple = new TripleImpl(new BNode(), property, dateLiteral);
+        graph.add(triple);
+
+        Triple tripleFromGraph = null;
+        Iterator<Triple> propertyTriples = graph.filter(null, property, dateLiteral);
+        if (propertyTriples.hasNext()) {
+            tripleFromGraph = propertyTriples.next();
+        } else {
+            Assert.assertTrue(false);
+        }
+        Assert.assertEquals(dateLiteral, tripleFromGraph.getObject());
+    }
+
+}


[10/14] clerezza git commit: CLEREZZA-966: moved jena.tdb.storage into the hierarchy

Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
deleted file mode 100644
index ac0dc89..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
+++ /dev/null
@@ -1,261 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-import java.util.Set;
-
-
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.osgi.service.cm.ConfigurationException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.wymiwyg.commons.util.Util;
-
-
-public class MultiThreadedSingleTdbDatasetTest {
-    
-    private Logger log = LoggerFactory.getLogger(MultiThreadedSingleTdbDatasetTest.class);
-    
-    private static final String TEST_GRAPH_URI_PREFIX = "http://www.example.org/multiThreadTest";
-    private int[] graphNum = new int[]{0};
-    /** 
-     * how many threads to start
-     */
-    private static final int TEST_THREAD_COUNT = 25;
-    private static final int VALIDATE_THREAD_COUNT = 2;
-    /**
-     * how many seconds to let them run
-     */
-    private static final int DELAY = 15;
-    
-    
-    protected final List<MGraph> mGraphs = new ArrayList<MGraph>();
-    protected final List<Set<Triple>> testTriplesList = new ArrayList<Set<Triple>>();
-    private Random random = new Random();
-
-    class TestThread extends Thread {
-
-        private boolean stopRequested;
-        private int addedTripleCount = 0;
-
-        public TestThread(final int id) {
-            setName("Test Thread "+id);
-            start();
-        }
-
-        public void requestStop() {
-            stopRequested = true;
-        }
-
-        @Override
-        public void run() {
-            while (!stopRequested) {
-                float r;
-                synchronized (random) {
-                    r = random.nextFloat();
-                }
-                MGraph graph;
-                Set<Triple> testTriples;
-                if(r > 0.995){
-                    int num;
-                    synchronized (graphNum) {
-                        num = graphNum[0];
-                        graphNum[0]++;
-                    }
-                    graph = provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+num));
-                    log.info(" ... creating the {}. Grpah", num+1);
-                    testTriples = new HashSet<Triple>();
-                    synchronized (mGraphs) {
-                        mGraphs.add(graph);
-                        testTriplesList.add(testTriples);
-                    }
-                } else { //map the range [0..0.995] to the mGraphs
-                    synchronized (mGraphs) {
-                        int num = Math.round(r*(float)(mGraphs.size()-1)/0.995f);
-                        graph = mGraphs.get(num);
-                        testTriples = testTriplesList.get(num);
-                    }
-                }
-                Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
-                Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
-                graph.add(triple);
-                addedTripleCount++;
-                if ((addedTripleCount % 100) == 0) {
-                    testTriples.add(triple);
-                }
-            }
-        }
-
-        public int getAddedTripleCount() {
-            return addedTripleCount;
-        }
-
-    }
-    /**
-     * Iterates over max. the first 10 triples of a Graph
-     * while acquiring a read lock on the graph.
-     * @author westei
-     *
-     */
-    class ValidatorThread extends Thread {
-        
-        boolean stopRequested = false;
-        
-        public ValidatorThread(int id) {
-            setName("Validator Thread "+id);
-            start();
-        }
-        
-        public void requestStop() {
-            stopRequested = true;
-        }
-
-        @Override
-        public void run() {
-            while (!stopRequested) {
-                float r;
-                synchronized (random) {
-                    r = random.nextFloat();
-                }
-                int num = Math.round(r*(float)(mGraphs.size()-1));
-                LockableMGraph graph;
-                synchronized (mGraphs) {
-                    graph = (LockableMGraph)mGraphs.get(num);
-                }
-                int elem = 0;
-                graph.getLock().readLock().lock();
-                try {
-                    Iterator<Triple> it = graph.iterator();
-                    while(it.hasNext() && elem < 10){
-                        elem++;
-                        it.next();
-                    }
-                } finally {
-                    graph.getLock().readLock().unlock();
-                }
-                //iterate inly every 200ms
-                try {
-                    Thread.sleep(200);
-                } catch (InterruptedException e) {
-                    //ignore
-                }
-            }
-        }
-        
-        
-        
-    }
-
-    
-    
-    private static File tempFile;
-    private static Dictionary<String,Object> config;
-    private static SingleTdbDatasetTcProvider provider;
-    @BeforeClass
-    public static void setup() throws IOException, ConfigurationException {
-        tempFile = File.createTempFile("tdbdatasettest", null);
-        tempFile.delete();
-        tempFile.mkdirs();
-        config = new Hashtable<String,Object>();
-        config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
-        provider = new SingleTdbDatasetTcProvider(config);
-    }
-    @Before
-    public void createGraphs(){
-        mGraphs.add(provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+graphNum[0])));
-        testTriplesList.add(new HashSet<Triple>());
-        graphNum[0]++;
-        mGraphs.add(provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+graphNum[0])));
-        testTriplesList.add(new HashSet<Triple>());
-        graphNum[0]++;
-    }
-    @Test
-    public void perform() throws InterruptedException {
-        TestThread[] threads =  new TestThread[TEST_THREAD_COUNT];
-        for (int i = 0; i < threads.length; i++) {
-            threads[i] = new TestThread(i);
-        }
-        ValidatorThread[] validators = new ValidatorThread[VALIDATE_THREAD_COUNT];
-        for(int i = 0; i < validators.length; i++) {
-            validators [i] = new ValidatorThread(i);
-        }
-        Thread.sleep(DELAY*1000);
-        for (TestThread testThread : threads) {
-            testThread.requestStop();
-        }
-        for (ValidatorThread validator : validators) {
-            validator.requestStop();
-        }
-        for (TestThread testThread : threads) {
-            testThread.join();
-        }
-        for (ValidatorThread validator : validators) {
-            validator.join();
-        }
-        int addedTriples = 0;
-        for (TestThread testThread : threads) {
-            addedTriples += testThread.getAddedTripleCount();
-        }
-        int graphTriples = 0;
-        log.info("Test created {} graphs with {} triples", mGraphs.size(), addedTriples);
-        for(int i = 0;i < mGraphs.size(); i++){
-            MGraph graph = mGraphs.get(i);
-            graphTriples += graph.size();
-            log.info("  > Grpah {}: {} triples",i,graph.size());
-            for (Triple testTriple : testTriplesList.get(i)) {
-                Assert.assertTrue(graph.contains(testTriple));
-            }
-        }
-        Assert.assertEquals(addedTriples, graphTriples);
-    }
-    @AfterClass
-    public static void cleanUpDirectory() throws IOException {
-        provider.deactivate(null);
-        try {
-            TdbTcProvider.delete(tempFile);
-        } catch (IOException e) {
-            System.err.println("Failed removing tempfile "+tempFile);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
deleted file mode 100644
index 91791c3..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.felix.scr.annotations.Activate;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.wymiwyg.commons.util.Util;
-
-
-public class MultiThreadedTest {
-    
-    
-    
-    /** 
-     * how many threads to start
-     */
-    private static final int THREAD_COUNT = 200;
-    /**
-     * how many seconds to let them run
-     */
-    private static final int DELAY = 15;
-    
-    
-    private MGraph mGraph;
-    private Set<Triple> testTriples = Collections.synchronizedSet(new HashSet<Triple>()); 
-
-    class TestThread extends Thread {
-
-        private final int id;
-        private boolean stopRequested;
-        private int addedTripleCount = 0;
-        private Object exception;
-
-        public TestThread(final int id) {
-            this.id = id;
-            start();
-        }
-
-        public void requestStop() {
-            stopRequested = true;
-        }
-
-        @Override
-        public void run() {
-            while (!stopRequested) {
-                try {
-                    Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
-                    Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
-                    mGraph.add(triple);
-                    addedTripleCount++;
-                    if ((addedTripleCount % 100) == 0) {
-                        testTriples.add(triple);
-                    }
-                } catch (Exception e) {
-                    exception = e;
-                }
-            }
-        }
-
-        public int getAddedTripleCount() {
-            return addedTripleCount;
-        }
-
-    }
-
-    
-    
-    @Before
-    public void setUp() throws IOException {
-        File tempFile;
-        UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
-        TdbTcProvider tdbTcProvider;
-        tempFile = File.createTempFile("tdbtest", null);
-        tempFile.delete();
-        tempFile.mkdirs();
-        tdbTcProvider = new TdbTcProvider(tempFile);
-        tdbTcProvider.activate(null);
-        mGraph = tdbTcProvider.createMGraph(MGRAPHNAME);
-    }
-
-    @Test
-    public void perform() throws InterruptedException {
-        TestThread[] threads =  new TestThread[THREAD_COUNT];
-        for (int i = 0; i < threads.length; i++) {
-            threads[i] = new TestThread(i);
-        }
-        Thread.sleep(DELAY*1000);
-        for (TestThread testThread : threads) {
-            testThread.requestStop();
-        }
-        for (TestThread testThread : threads) {
-            testThread.join();
-        }
-        int addedTriples = 0;
-        for (TestThread testThread : threads) {
-            addedTriples += testThread.getAddedTripleCount();
-        }
-        Assert.assertEquals(addedTriples, mGraph.size());
-        for (Triple testTriple : testTriples) {
-            Assert.assertTrue(mGraph.contains(testTriple));
-        }
-        for (TestThread testThread : threads) {
-            Assert.assertNull(testThread.exception);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
deleted file mode 100644
index 76505b3..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Set;
-
-
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.felix.scr.annotations.Activate;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.service.cm.ConfigurationException;
-import org.wymiwyg.commons.util.Util;
-
-
-public class MultiThreadedTestSingleTdb {
-    
-    
-    
-    /** 
-     * how many threads to start
-     */
-    private static final int THREAD_COUNT = 100;
-    /**
-     * how many seconds to let them run
-     */
-    private static final int DELAY = 15;
-    
-    
-    private MGraph mGraph;
-    private Set<Triple> testTriples = Collections.synchronizedSet(new HashSet<Triple>()); 
-
-    class TestThread extends Thread {
-
-        private final int id;
-        private boolean stopRequested;
-        private int addedTripleCount = 0;
-        private Object exception;
-
-        public TestThread(final int id) {
-            this.id = id;
-            start();
-        }
-
-        public void requestStop() {
-            stopRequested = true;
-        }
-
-        @Override
-        public void run() {
-            while (!stopRequested) {
-                try {
-                    Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
-                    Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
-                    mGraph.add(triple);
-                    addedTripleCount++;
-                    if ((addedTripleCount % 100) == 0) {
-                        testTriples.add(triple);
-                    }
-                } catch (Exception e) {
-                    exception = e;
-                }
-            }
-        }
-
-        public int getAddedTripleCount() {
-            return addedTripleCount;
-        }
-
-    }
-
-    
-    
-    @Before
-    public void setUp() throws IOException, ConfigurationException {
-        File tempFile;
-        UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
-        TcProvider tdbTcProvider;
-        tempFile = File.createTempFile("tdbtest", null);
-        tempFile.delete();
-        tempFile.mkdirs();
-        Dictionary<String, Object> dict = new Hashtable<String, Object>();
-        dict.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
-        tdbTcProvider = new SingleTdbDatasetTcProvider(dict);
-        //tdbTcProvider.activate(null);
-        mGraph = tdbTcProvider.createMGraph(MGRAPHNAME);
-    }
-
-    @Test
-    public void perform() throws InterruptedException {
-        TestThread[] threads =  new TestThread[THREAD_COUNT];
-        for (int i = 0; i < threads.length; i++) {
-            threads[i] = new TestThread(i);
-        }
-        Thread.sleep(DELAY*1000);
-        for (TestThread testThread : threads) {
-            testThread.requestStop();
-        }
-        for (TestThread testThread : threads) {
-            testThread.join();
-        }
-        int addedTriples = 0;
-        for (TestThread testThread : threads) {
-            addedTriples += testThread.getAddedTripleCount();
-        }
-        Assert.assertEquals(addedTriples, mGraph.size());
-        for (Triple testTriple : testTriples) {
-            Assert.assertTrue(mGraph.contains(testTriple));
-        }
-        for (TestThread testThread : threads) {
-            Assert.assertNull(testThread.exception);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
deleted file mode 100644
index cc3741b..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.test.MGraphTest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.osgi.service.cm.ConfigurationException;
-
-public class SingleTdbDatasetMGraphTest extends MGraphTest {
-
-    private static final String MGRAPHNAME_PREFIX = "http://text.example.org/testGraph";
-    private static UriRef UNION_GRAPH_NAME = new UriRef("http://www.example.org/unionGraph");
-    private static int testGraphCounter = 0;
-
-    private static File tempFile;
-    private static Dictionary<String,Object> config;
-    private static SingleTdbDatasetTcProvider provider;
-
-    @BeforeClass
-    public static void setup() throws IOException, ConfigurationException {
-        tempFile = File.createTempFile("tdbdatasettest", null);
-        tempFile.delete();
-        tempFile.mkdirs();
-        config = new Hashtable<String,Object>();
-        config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
-        config.put(SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME, UNION_GRAPH_NAME.getUnicodeString());
-        provider = new SingleTdbDatasetTcProvider(config);
-    }
-    
-    @AfterClass
-    public static void cleanUpDirectory() throws IOException {
-        for(int i = 0; i < testGraphCounter;i++){
-            provider.deleteTripleCollection(new UriRef(MGRAPHNAME_PREFIX+i));
-        }
-        provider.deactivate(null);
-        try {
-            TdbTcProvider.delete(tempFile);
-        } catch (IOException e) {
-            System.err.println("Couldn't remove "+tempFile);
-        }
-    }
-
-    @Override
-    protected MGraph getEmptyMGraph() {
-        MGraph graph = provider.createMGraph(new UriRef(MGRAPHNAME_PREFIX+testGraphCounter));
-        testGraphCounter++;
-        return graph;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
deleted file mode 100644
index b3849dd..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
-import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.core.test.TcProviderTest;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.service.cm.ConfigurationException;
-
-public class SingleTdbDatasetTcProviderTest extends TcProviderTest {
-
-    private static File tempFile;
-    private static Dictionary<String,Object> config;
-    private static SingleTdbDatasetTcProvider provider;
-    private static UriRef UNION_GRAPH_NAME = new UriRef("http://www.example.org/unionGraph");
-    
-    @Before
-    public void setup() throws IOException, ConfigurationException {
-        tempFile = File.createTempFile("tdbdatasettest", null);
-        tempFile.delete();
-        tempFile.mkdirs();
-        config = new Hashtable<String,Object>();
-        config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
-        config.put(SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME, UNION_GRAPH_NAME.getUnicodeString());
-        //config.put(SingleTdbDatasetTcProvider.USE_GRAPH_NAME_SUFFIXES, true);
-    }
-    
-    @Override
-    protected TcProvider getInstance() {
-        //tests want us to deactivate/activate the TcProvider on multiple calls
-        //to getInstance within the same test
-        if(provider !=null){
-            try {
-                provider.deactivate(null);
-                provider = null;
-            } catch (Exception e) {
-                System.err.println("Error cleaning up: "+e.getMessage());
-            }
-        }
-        try {
-            provider = new SingleTdbDatasetTcProvider(config);
-        } catch (Exception e) {
-            throw new RuntimeException("forwarding ...",e);
-        }
-        return provider;
-    }
-
-    @After
-    public void cleanData() throws IOException{
-        //We need to remove all remaining data after a test
-        if(provider != null){
-            try {
-                provider.deactivate(null);
-                TdbTcProvider.delete(tempFile);
-                provider = null;
-            } catch (Exception e) {
-                System.err.println("Error cleaning up: "+e.getMessage());
-            }
-        }
-    }
-    
-    /**
-     * The union graph is read only!
-     */
-    @Test(expected=NoSuchEntityException.class)
-    public void testUnionMgraph(){
-        TcProvider provider = getInstance();
-        provider.getMGraph(UNION_GRAPH_NAME);
-    }
-    
-    /**
-     * Assert union graph on an empty dataset
-     */
-    @Test
-    public void testEmptyUnionGraph(){
-        TcProvider provider = getInstance();
-        Graph graph = provider.getGraph(UNION_GRAPH_NAME);
-        Assert.assertNotNull(graph);
-    }
-    
-    @Test
-    public void testUnionGraph() throws Exception{
-        TcProvider provider = getInstance();
-        UriRef type = new UriRef("http://www.w3.org/2000/01/rdf-schema#type");
-        UriRef name = new UriRef("http://schema.org/name");
-        UriRef personType = new UriRef("http://schema.org/Person");
-        UriRef companyType = new UriRef("http://schema.org/Company");
-        UriRef worksFor = new UriRef("http://schema.org/works-for");
-
-        //create a graph with persons
-        MGraph persons = new SimpleMGraph();
-        UriRef tim = new UriRef("http://people.org/tim.johnson");
-        persons.add(new TripleImpl(tim, type, personType));
-        persons.add(new TripleImpl(tim, name, new PlainLiteralImpl("Tim Johnson")));
-        UriRef john = new UriRef("http://people.org/john.swenson");
-        persons.add(new TripleImpl(john, type, personType));
-        persons.add(new TripleImpl(john, name, new PlainLiteralImpl("John Swenson")));
-        provider.createGraph(new UriRef("urn:persons"), persons.getGraph());
-        
-        //create a MGraph with data about persons
-        MGraph orgdata = provider.createMGraph(new UriRef("urn:orgdata"));
-        UriRef talinor = new UriRef("http://company.org/talinor");
-        orgdata.add(new TripleImpl(talinor, type, companyType));
-        orgdata.add(new TripleImpl(talinor, name, new PlainLiteralImpl("Talinor Inc.")));
-        orgdata.add(new TripleImpl(john, worksFor, talinor));
-        UriRef kondalor = new UriRef("http://company.org/kondalor");
-        orgdata.add(new TripleImpl(kondalor, type, companyType));
-        orgdata.add(new TripleImpl(kondalor, name, new PlainLiteralImpl("Kondalor Ges.m.b.H.")));
-        orgdata.add(new TripleImpl(tim, worksFor, kondalor));
-        
-        //now get the union graph
-        Graph data = provider.getGraph(UNION_GRAPH_NAME);
-        Assert.assertNotNull(data);
-        //CLEREZZA-714: getTriples need to correctly return the UnionGraph
-        data = (Graph)provider.getTriples(UNION_GRAPH_NAME);
-        Assert.assertNotNull(data);
-        //NOTE: Jena TDB does not support getSize for the union graph
-//        int expectedTripleCount = persons.size()+orgdata.size();
-//        Assert.assertEquals("Uniongraph has "+data.size()
-//            +" triples (expected "+expectedTripleCount+")",
-//            expectedTripleCount, data.size());
-        Iterator<Triple> it = data.filter(null, type, companyType);
-        Set<UriRef> expected = new HashSet<UriRef>(Arrays.asList(talinor,kondalor));
-        while(it.hasNext()){
-            NonLiteral subject = it.next().getSubject();
-            Assert.assertTrue("Unexpected "+subject, expected.remove(subject));
-        }
-        Assert.assertTrue("Missing "+expected, expected.isEmpty());
-
-        it = data.filter(null, type, personType);
-        expected = new HashSet<UriRef>(Arrays.asList(john,tim));
-        while(it.hasNext()){
-            NonLiteral subject = it.next().getSubject();
-            Assert.assertTrue("Unexpected "+subject, expected.remove(subject));
-        }
-        Assert.assertTrue("Missing "+expected, expected.isEmpty());
-    }
-    
-    @Test
-    public void testListGraph(){
-    	TcProvider provider = getInstance();
-    	//No union graph in listMGraphs
-    	Set<UriRef> mgl = provider.listMGraphs();
-        Assert.assertFalse("Mgraph list don't contain the read-only union-graph", mgl.contains(UNION_GRAPH_NAME));
-        //Union graph in listGraphs
-        Set<UriRef> gl = provider.listGraphs();
-        Assert.assertTrue("Graph list contain the read-only union-graph", gl.contains(UNION_GRAPH_NAME));
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
deleted file mode 100644
index e09c0e4..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.Iterator;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.LiteralFactory;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.TypedLiteral;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.core.test.MGraphTest;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class TdbMGraphTest extends MGraphTest {
-    private static File tempFile;
-    final private UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
-    static private TdbTcProvider tdbTcProvider;
-
-    @BeforeClass
-    public static void setupDirectory() throws IOException {
-        tempFile = File.createTempFile("tdbtest", null);
-        tempFile.delete();
-        tempFile.mkdirs();
-        tdbTcProvider = new TdbTcProvider(tempFile);
-    }
-
-    @AfterClass
-    public static void cleanUpDirectory() throws IOException {
-        try {
-            TdbTcProvider.delete(tempFile);
-        } catch (IOException e) {
-            System.err.println("failed to delete temp directory: "+tempFile);
-        }
-    }
-
-    @After
-    public void cleanUpGraph() {
-        tdbTcProvider.deleteTripleCollection(MGRAPHNAME);
-    }
-
-    @Override
-    protected MGraph getEmptyMGraph() {
-        return tdbTcProvider.createMGraph(MGRAPHNAME);
-    }
-
-    @Test
-    public void dateStorage() {
-        MGraph graph = getEmptyMGraph();
-        Date date = new Date(0);
-        LiteralFactory literalFactory = LiteralFactory.getInstance();
-        TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
-        Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), dateLiteral);
-        graph.add(triple);
-        Assert.assertTrue(graph.contains(triple));
-    }
-
-    @Test
-    public void dateStorage2() {
-        MGraph graph = getEmptyMGraph();
-        Date date = new Date(0);
-        LiteralFactory literalFactory = LiteralFactory.getInstance();
-        TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
-        System.out.println(dateLiteral);
-        UriRef property = new UriRef("http://example.com/property");
-        Triple triple = new TripleImpl(new BNode(), property, dateLiteral);
-        graph.add(triple);
-
-        Triple tripleFromGraph = null;
-        Iterator<Triple> propertyTriples = graph.filter(null, property, dateLiteral);
-        if (propertyTriples.hasNext()) {
-            tripleFromGraph = propertyTriples.next();
-        } else {
-            Assert.assertTrue(false);
-        }
-        Assert.assertEquals(dateLiteral, tripleFromGraph.getObject());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java
deleted file mode 100644
index 2964385..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-
-
-import org.junit.After;
-import org.junit.Before;
-import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.test.TcProviderTest;
-
-/**
- *
- * @author mir
- */
-public class TdbTcProviderTest extends TcProviderTest {
-
-    private File tempFile;
-    private TdbTcProvider lastInstance;
-
-    @Before
-    public void setupDirectory() throws IOException {
-        tempFile = File.createTempFile("tdbtest", null);
-        tempFile.delete();
-        tempFile.mkdirs();
-    }
-
-    @After
-    public void cleanUp() throws IOException {
-        TdbTcProvider.delete(tempFile);
-    }
-
-
-    @Override
-    protected TcProvider getInstance() {
-        if (lastInstance != null) {
-            lastInstance.deactivate(null);
-        }
-        lastInstance =  new TdbTcProvider(tempFile);
-        lastInstance.activate(null);
-        return lastInstance;
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/pom.xml b/rdf/jena/pom.xml
index cac069e..54b054b 100644
--- a/rdf/jena/pom.xml
+++ b/rdf/jena/pom.xml
@@ -47,8 +47,9 @@
         <module>facade</module>
         <module>parser</module>
         <module>serializer</module>
-        <module>storage</module>
         <module>sparql</module>
+        <module>storage</module>
+        <module>tdb.storage</module>
     </modules>
 
 </project>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/LICENSE
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/LICENSE b/rdf/jena/tdb.storage/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/rdf/jena/tdb.storage/LICENSE
@@ -0,0 +1,201 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/pom.xml b/rdf/jena/tdb.storage/pom.xml
new file mode 100644
index 0000000..9306ee3
--- /dev/null
+++ b/rdf/jena/tdb.storage/pom.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>clerezza</artifactId>
+        <groupId>org.apache.clerezza</groupId>
+        <version>0.5</version>
+        <relativePath>../parent</relativePath>
+    </parent>
+    <groupId>org.apache.clerezza</groupId>
+    <artifactId>rdf.jena.tdb.storage</artifactId>
+    <packaging>bundle</packaging>
+    <version>1.0.0-SNAPSHOT</version>
+    <name>Clerezza - SCB Jena TDB Storage Provider</name>
+    <description>A Jena TDB based storage provider</description>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.core</artifactId>
+            <version>0.14</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.ontologies</artifactId>
+            <version>0.12</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.jena.commons</artifactId>
+            <version>0.7</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.jena.storage</artifactId>
+            <version>0.7</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.jena.sparql</artifactId>
+            <version>0.7</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jena</groupId>
+            <artifactId>jena-tdb</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.sun.jmx</groupId>
+                    <artifactId>jmxri</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.jdmk</groupId>
+                    <artifactId>jmxtools</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>javax.jms</groupId>
+                    <artifactId>jms</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>14.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.core.test</artifactId>
+            <scope>test</scope>
+            <version>0.15</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
new file mode 100644
index 0000000..a3cdd19
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
@@ -0,0 +1,46 @@
+package org.apache.clerezza.rdf.jena.tdb.internals;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.locks.ReadWriteLock;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
+import org.apache.clerezza.rdf.core.event.FilterTriple;
+import org.apache.clerezza.rdf.core.event.GraphListener;
+import org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider;
+
+/**
+ * {@link LockableMGraph} wrapper that uses a single {@link ReadWriteLock} for
+ * the Jena TDB {@link SingleTdbDatasetTcProvider#dataset}
+ * @author Rupert Westenthaler
+ *
+ */
+public class DatasetLockedMGraph extends LockableMGraphWrapper {
+
+
+    /**
+     * Constructs a LocalbleMGraph for an MGraph.
+     *
+     * @param providedMGraph a non-lockable mgraph
+     */
+    public DatasetLockedMGraph(final ReadWriteLock lock, final MGraph providedMGraph) {
+        super(providedMGraph, lock);
+    }
+
+    //Maybe overwriting this prevents unnecessary locking
+    /*
+    @Override
+    public Iterator<Triple> filter(NonLiteral subject, UriRef predicate, Resource object) {
+        //users will need to aquire a readlock while iterating
+        return wrapped.filter(subject, predicate, object);
+    }
+    */
+        
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
new file mode 100644
index 0000000..7b6421f
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
@@ -0,0 +1,149 @@
+package org.apache.clerezza.rdf.jena.tdb.internals;
+
+import java.util.concurrent.locks.ReadWriteLock;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
+import org.apache.clerezza.rdf.core.impl.SimpleGraph;
+import org.apache.clerezza.rdf.core.impl.util.PrivilegedGraphWrapper;
+import org.apache.clerezza.rdf.core.impl.util.PrivilegedMGraphWrapper;
+import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
+import org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.sparql.core.DatasetGraph;
+import com.hp.hpl.jena.sparql.core.Quad;
+import com.hp.hpl.jena.tdb.TDB;
+
+/**
+ * Represents the Jena {@link Model} and the Clerezza {@link Graph} or
+ * {@link MGraph}. It also provide access to the {@link JenaGraphAdaptor}
+ * so that this component can add parsed data to {@link Graph}s created
+ * by calls to {@link SingleTdbDatasetTcProvider#createGraph(UriRef, TripleCollection)}.
+ * @author Rupert Westenthaler
+ *
+ */
+public class ModelGraph {
+    /**
+     * The Jena Model
+     */
+    private final Model model;
+    /**
+     * The JenaGraphAdapter. Note that in case of read-only in anonymous
+     * subclass is used that prevents the creation of an in-memory copy
+     * of the data when calling {@link JenaGraphAdaptor#getGraph()}.
+     */
+    private JenaGraphAdaptor jenaAdapter;
+    /**
+     * The {@link Graph}(in case of read-only) or {@link MGraph} (if read/write)
+     * that can be shared with other components. The instance stored by this
+     * variable will use all the required Wrappers such as such as 
+     * {@link LockableMGraphWrapper lockable} and {@link PrivilegedMGraphWrapper
+     * privileged}.
+     */
+    private TripleCollection graph;
+    /**
+     * keeps the state if this represents an {@link Graph} (read-only) or
+     * {@link MGraph}(read/write) ModelGraph.
+     */
+    private final boolean readWrite;
+    
+    /**
+     * Constructs and initializes the ModelGraph
+     * @param model the Jena Model
+     * @param readWrite if the Clerezza counterpart should be read- and 
+     * write-able or read-only.
+     */
+    public ModelGraph(final ReadWriteLock lock, Model model, boolean readWrite){
+        if(model == null){
+            throw new IllegalArgumentException("The parsed Model MUST NOT be NULL");
+        }
+        this.model = model;
+        this.readWrite = readWrite;
+        if(!readWrite){ //construct an graph
+            jenaAdapter = new JenaGraphAdaptor(model.getGraph()){
+                /**
+                 * Ensure that no in-memory copies are created for read only
+                 * Jena Graphs
+                 * @return
+                 */
+                @Override
+                public Graph getGraph() {
+                    return new SimpleGraph(this,true);
+                }
+            };
+            graph = new PrivilegedGraphWrapper(jenaAdapter.getGraph());
+        } else { //construct an MGraph
+            jenaAdapter = new JenaGraphAdaptor(model.getGraph());
+            this.graph =  new DatasetLockedMGraph(lock,
+                new PrivilegedMGraphWrapper(jenaAdapter));
+        }
+    }
+    /**
+     * The {@link JenaGraphAdaptor}. For internal use only! Do not pass
+     * this instance to other components. Use {@link #getGraph()} and
+     * {@link #getMGraph()} instead!
+     * @return the plain {@link JenaGraphAdaptor}
+     */
+    public JenaGraphAdaptor getJenaAdapter(){
+        return jenaAdapter;
+    }
+
+    public boolean isReadWrite(){
+        return readWrite;
+    }
+    /**
+     * Getter for the {@link MGraph}
+     * @return the {@link MGraph}
+     * @throws IllegalStateException if this {@link ModelGraph} is NOT
+     * {@link #readWrite}
+     */
+    public MGraph getMGraph(){
+        if(!readWrite){
+            throw new IllegalStateException("Unable to return MGraph for read-only models");
+        }
+        return (MGraph)graph;
+    }
+    /**
+     * Getter for the {@link Graph}
+     * @return the {@link Graph}
+     * @throws IllegalStateException if this {@link ModelGraph} is 
+     * {@link #readWrite}
+     */
+    public Graph getGraph() {
+        if(readWrite){
+            throw new IllegalStateException("Unable to return Graph for read/write models.");
+        }
+        return (Graph)graph;
+    }
+    /**
+     * closes this ModelGraph and frees up all Jena TDB related resources.
+     */
+    public void close(){
+        this.graph = null;
+        this.jenaAdapter = null;
+        sync();
+        this.model.close();
+    }
+    /**
+     * Synchronize the Jena Model with the field system by calling
+     * {@link TDB#sync(Model)}
+     */
+    public void sync(){
+        TDB.sync(model);
+    }
+    /**
+     * Removes all triples from the Jena Model and than calls {@link #close()}
+     * to free remaining resources. Note that in Jena TDB a named model is 
+     * deleted if no more triples with the given context are present within
+     * the {@link Quad} store of the Jena TDB {@link DatasetGraph}.
+     */
+    public void delete(){
+        this.model.removeAll();
+        close();
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
new file mode 100644
index 0000000..ccf3003
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
@@ -0,0 +1,22 @@
+package org.apache.clerezza.rdf.jena.tdb.internals;
+
+import org.apache.clerezza.rdf.core.UriRef;
+
+/**
+ * Provides static methods in order to represent classes used to
+ * represent named graphs.
+ * 
+ * @author misl
+ * 
+ */
+public class Symbols {
+
+    public static UriRef Index = new UriRef("http://clerezza.apache.org/storage/Index");
+
+    public static UriRef Default = new UriRef("http://clerezza.apache.org/storage/Default");
+    
+    public static UriRef Graph = new UriRef("http://clerezza.apache.org/storage/Graph");
+
+    public static UriRef MGraph = new UriRef("http://clerezza.apache.org/storage/MGraph");
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
new file mode 100644
index 0000000..fb165d0
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
@@ -0,0 +1,62 @@
+package org.apache.clerezza.rdf.jena.tdb.internals;
+
+import java.util.AbstractSet;
+import java.util.Iterator;
+
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.ontologies.RDF;
+
+/**
+ * Represents a set of uri ref Set<UriRef>
+ * @author Minto van der Sluis
+ */
+public class UriRefSet extends AbstractSet<UriRef> {
+    private ModelGraph graphNameIndex;
+    private UriRef graphType;
+
+    public UriRefSet(ModelGraph index, UriRef object) {
+        graphNameIndex = index;
+        graphType = object;
+    }
+  
+    @Override
+    public int size() {
+        // TODO: How to get the proper size based on graphType
+        return graphNameIndex.getMGraph().size();
+    }
+  
+    @Override
+    public Iterator<UriRef> iterator() {
+        final Iterator<Triple> indexIter = graphNameIndex.getMGraph().filter( null, RDF.type, graphType );
+        return new Iterator<UriRef>() {
+            @Override
+            public boolean hasNext() {
+                return indexIter.hasNext();
+            }
+  
+            @Override
+            public UriRef next() {
+                return UriRef.class.cast(indexIter.next().getSubject());
+            }
+  
+            @Override
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+        };
+    }
+    
+    @Override
+    public boolean add(UriRef o) {
+        throw new UnsupportedOperationException();
+    }
+  
+    @Override
+    public boolean contains(Object o) {
+        if (o instanceof UriRef) {
+            return graphNameIndex.getMGraph().filter(UriRef.class.cast(o), RDF.type, graphType).hasNext();
+        }
+        return false;
+    }
+};    

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
new file mode 100644
index 0000000..c8a7a5f
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
@@ -0,0 +1,110 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.access.QueryableTcProvider;
+import org.apache.clerezza.rdf.core.sparql.query.Query;
+import org.apache.clerezza.rdf.jena.sparql.ResultSetWrapper;
+import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.QueryException;
+import com.hp.hpl.jena.query.QueryExecException;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.update.GraphStore;
+import com.hp.hpl.jena.update.GraphStoreFactory;
+import com.hp.hpl.jena.update.UpdateAction;
+import org.apache.clerezza.rdf.core.UriRef;
+
+abstract class BaseTdbTcProvider implements QueryableTcProvider{
+
+	// ------------------------------------------------------------------------
+	// Object attributes
+	// ------------------------------------------------------------------------
+
+	private Dataset dataset;
+		
+	// ------------------------------------------------------------------------
+	// Implementing QueryableTcProvider
+	// ------------------------------------------------------------------------
+
+    @Override
+    public Object executeSparqlQuery(final String query, UriRef defaultGraph) {
+		// Missing permission (java.lang.RuntimePermission getClassLoader)
+		// when calling QueryFactory.create causes ExceptionInInitializerError
+		// to be thrown.
+		// QueryExecutionFactory.create requires
+		// (java.io.FilePermission [etc/]location-mapping.* read)
+		// Thus, they are placed within doPrivileged
+		QueryExecution qexec = AccessController
+				.doPrivileged(new PrivilegedAction<QueryExecution>() {
+
+					@Override
+					public QueryExecution run() {
+						try {
+							com.hp.hpl.jena.query.Query jenaQuery = QueryFactory
+									.create(query);
+							if (jenaQuery.isUnknownType()) {
+								return null;
+							}
+							return QueryExecutionFactory.create(jenaQuery, getDataset());
+						} catch (QueryException ex) {
+							return null;
+						}							
+					}
+				});
+
+		if (qexec == null) {
+			return executeUpdate(query);
+		}
+
+		try {
+			try {
+				return new ResultSetWrapper(qexec.execSelect());
+			} catch (QueryExecException e) {
+				try {
+					return Boolean.valueOf(qexec.execAsk());
+				} catch (QueryExecException e2) {
+					try {
+						return new JenaGraphAdaptor(qexec.execDescribe()
+								.getGraph()).getGraph();
+					} catch (QueryExecException e3) {
+						return new JenaGraphAdaptor(qexec.execConstruct()
+								.getGraph()).getGraph();
+					}
+				}
+			}
+		} finally {
+			qexec.close();
+		}
+    }
+
+	// ------------------------------------------------------------------------
+	// Getters / Setters
+	// ------------------------------------------------------------------------
+    
+    public Dataset getDataset() {
+    	if (dataset == null) {
+    		throw new RuntimeException("Missing Dataset!");
+    	}
+		return dataset;
+	}
+    
+    public void setDataset(Dataset dataset) {
+		this.dataset = dataset;
+	}
+
+	// ------------------------------------------------------------------------
+	// Private methods
+	// ------------------------------------------------------------------------
+    
+	private Object executeUpdate(String query) {
+        GraphStore graphStore = GraphStoreFactory.create(getDataset()) ;
+        UpdateAction.parseExecute(query, graphStore) ;
+        return true;
+    }
+}


[13/14] clerezza git commit: CLEREZZA-976: ported TDB storage provider and some related fixes, some tests still failing.

Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
deleted file mode 100644
index cc3741b..0000000
--- a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.test.MGraphTest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.osgi.service.cm.ConfigurationException;
-
-public class SingleTdbDatasetMGraphTest extends MGraphTest {
-
-    private static final String MGRAPHNAME_PREFIX = "http://text.example.org/testGraph";
-    private static UriRef UNION_GRAPH_NAME = new UriRef("http://www.example.org/unionGraph");
-    private static int testGraphCounter = 0;
-
-    private static File tempFile;
-    private static Dictionary<String,Object> config;
-    private static SingleTdbDatasetTcProvider provider;
-
-    @BeforeClass
-    public static void setup() throws IOException, ConfigurationException {
-        tempFile = File.createTempFile("tdbdatasettest", null);
-        tempFile.delete();
-        tempFile.mkdirs();
-        config = new Hashtable<String,Object>();
-        config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
-        config.put(SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME, UNION_GRAPH_NAME.getUnicodeString());
-        provider = new SingleTdbDatasetTcProvider(config);
-    }
-    
-    @AfterClass
-    public static void cleanUpDirectory() throws IOException {
-        for(int i = 0; i < testGraphCounter;i++){
-            provider.deleteTripleCollection(new UriRef(MGRAPHNAME_PREFIX+i));
-        }
-        provider.deactivate(null);
-        try {
-            TdbTcProvider.delete(tempFile);
-        } catch (IOException e) {
-            System.err.println("Couldn't remove "+tempFile);
-        }
-    }
-
-    @Override
-    protected MGraph getEmptyMGraph() {
-        MGraph graph = provider.createMGraph(new UriRef(MGRAPHNAME_PREFIX+testGraphCounter));
-        testGraphCounter++;
-        return graph;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
index b3849dd..8dd2048 100644
--- a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
@@ -9,16 +9,16 @@ import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Set;
 
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
 import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
 import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
 import org.apache.clerezza.rdf.core.test.TcProviderTest;
 import org.junit.After;
 import org.junit.Assert;
@@ -31,7 +31,7 @@ public class SingleTdbDatasetTcProviderTest extends TcProviderTest {
     private static File tempFile;
     private static Dictionary<String,Object> config;
     private static SingleTdbDatasetTcProvider provider;
-    private static UriRef UNION_GRAPH_NAME = new UriRef("http://www.example.org/unionGraph");
+    private static Iri UNION_GRAPH_NAME = new Iri("http://www.example.org/unionGraph");
     
     @Before
     public void setup() throws IOException, ConfigurationException {
@@ -84,7 +84,7 @@ public class SingleTdbDatasetTcProviderTest extends TcProviderTest {
     @Test(expected=NoSuchEntityException.class)
     public void testUnionMgraph(){
         TcProvider provider = getInstance();
-        provider.getMGraph(UNION_GRAPH_NAME);
+        provider.getGraph(UNION_GRAPH_NAME);
     }
     
     /**
@@ -93,45 +93,45 @@ public class SingleTdbDatasetTcProviderTest extends TcProviderTest {
     @Test
     public void testEmptyUnionGraph(){
         TcProvider provider = getInstance();
-        Graph graph = provider.getGraph(UNION_GRAPH_NAME);
+        ImmutableGraph graph = provider.getImmutableGraph(UNION_GRAPH_NAME);
         Assert.assertNotNull(graph);
     }
     
     @Test
     public void testUnionGraph() throws Exception{
         TcProvider provider = getInstance();
-        UriRef type = new UriRef("http://www.w3.org/2000/01/rdf-schema#type");
-        UriRef name = new UriRef("http://schema.org/name");
-        UriRef personType = new UriRef("http://schema.org/Person");
-        UriRef companyType = new UriRef("http://schema.org/Company");
-        UriRef worksFor = new UriRef("http://schema.org/works-for");
+        Iri type = new Iri("http://www.w3.org/2000/01/rdf-schema#type");
+        Iri name = new Iri("http://schema.org/name");
+        Iri personType = new Iri("http://schema.org/Person");
+        Iri companyType = new Iri("http://schema.org/Company");
+        Iri worksFor = new Iri("http://schema.org/works-for");
 
         //create a graph with persons
-        MGraph persons = new SimpleMGraph();
-        UriRef tim = new UriRef("http://people.org/tim.johnson");
+        Graph persons = new SimpleGraph();
+        Iri tim = new Iri("http://people.org/tim.johnson");
         persons.add(new TripleImpl(tim, type, personType));
         persons.add(new TripleImpl(tim, name, new PlainLiteralImpl("Tim Johnson")));
-        UriRef john = new UriRef("http://people.org/john.swenson");
+        Iri john = new Iri("http://people.org/john.swenson");
         persons.add(new TripleImpl(john, type, personType));
         persons.add(new TripleImpl(john, name, new PlainLiteralImpl("John Swenson")));
-        provider.createGraph(new UriRef("urn:persons"), persons.getGraph());
+        provider.createImmutableGraph(new Iri("urn:persons"), persons);
         
-        //create a MGraph with data about persons
-        MGraph orgdata = provider.createMGraph(new UriRef("urn:orgdata"));
-        UriRef talinor = new UriRef("http://company.org/talinor");
+        //create a Graph with data about persons
+        Graph orgdata = provider.createGraph(new Iri("urn:orgdata"));
+        Iri talinor = new Iri("http://company.org/talinor");
         orgdata.add(new TripleImpl(talinor, type, companyType));
         orgdata.add(new TripleImpl(talinor, name, new PlainLiteralImpl("Talinor Inc.")));
         orgdata.add(new TripleImpl(john, worksFor, talinor));
-        UriRef kondalor = new UriRef("http://company.org/kondalor");
+        Iri kondalor = new Iri("http://company.org/kondalor");
         orgdata.add(new TripleImpl(kondalor, type, companyType));
         orgdata.add(new TripleImpl(kondalor, name, new PlainLiteralImpl("Kondalor Ges.m.b.H.")));
         orgdata.add(new TripleImpl(tim, worksFor, kondalor));
         
         //now get the union graph
-        Graph data = provider.getGraph(UNION_GRAPH_NAME);
+        ImmutableGraph data = provider.getImmutableGraph(UNION_GRAPH_NAME);
         Assert.assertNotNull(data);
         //CLEREZZA-714: getTriples need to correctly return the UnionGraph
-        data = (Graph)provider.getTriples(UNION_GRAPH_NAME);
+        data = (ImmutableGraph)provider.getGraph(UNION_GRAPH_NAME);
         Assert.assertNotNull(data);
         //NOTE: Jena TDB does not support getSize for the union graph
 //        int expectedTripleCount = persons.size()+orgdata.size();
@@ -139,17 +139,17 @@ public class SingleTdbDatasetTcProviderTest extends TcProviderTest {
 //            +" triples (expected "+expectedTripleCount+")",
 //            expectedTripleCount, data.size());
         Iterator<Triple> it = data.filter(null, type, companyType);
-        Set<UriRef> expected = new HashSet<UriRef>(Arrays.asList(talinor,kondalor));
+        Set<Iri> expected = new HashSet<Iri>(Arrays.asList(talinor,kondalor));
         while(it.hasNext()){
-            NonLiteral subject = it.next().getSubject();
+            BlankNodeOrIri subject = it.next().getSubject();
             Assert.assertTrue("Unexpected "+subject, expected.remove(subject));
         }
         Assert.assertTrue("Missing "+expected, expected.isEmpty());
 
         it = data.filter(null, type, personType);
-        expected = new HashSet<UriRef>(Arrays.asList(john,tim));
+        expected = new HashSet<Iri>(Arrays.asList(john,tim));
         while(it.hasNext()){
-            NonLiteral subject = it.next().getSubject();
+            BlankNodeOrIri subject = it.next().getSubject();
             Assert.assertTrue("Unexpected "+subject, expected.remove(subject));
         }
         Assert.assertTrue("Missing "+expected, expected.isEmpty());
@@ -158,11 +158,11 @@ public class SingleTdbDatasetTcProviderTest extends TcProviderTest {
     @Test
     public void testListGraph(){
     	TcProvider provider = getInstance();
-    	//No union graph in listMGraphs
-    	Set<UriRef> mgl = provider.listMGraphs();
-        Assert.assertFalse("Mgraph list don't contain the read-only union-graph", mgl.contains(UNION_GRAPH_NAME));
+    	//No union graph in listGraphs
+    	Set<Iri> mgl = provider.listMGraphs();
+        Assert.assertFalse("Mgraph contains the read-only union-graph", mgl.contains(UNION_GRAPH_NAME));
         //Union graph in listGraphs
-        Set<UriRef> gl = provider.listGraphs();
-        Assert.assertTrue("Graph list contain the read-only union-graph", gl.contains(UNION_GRAPH_NAME));
+        Set<Iri> gl = provider.listGraphs();
+        Assert.assertTrue("ImmutableGraph does not contain the read-only union-graph", gl.contains(UNION_GRAPH_NAME));
     }
 }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbGraphTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbGraphTest.java
new file mode 100644
index 0000000..72a9f57
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbGraphTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Iterator;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.commons.rdf.BlankNode;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.core.test.GraphTest;
+import org.apache.commons.rdf.Literal;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class TdbGraphTest extends GraphTest {
+    private static File tempFile;
+    final private Iri MGRAPHNAME = new Iri("http://text.example.org/");
+    static private TdbTcProvider tdbTcProvider;
+
+    @BeforeClass
+    public static void setupDirectory() throws IOException {
+        tempFile = File.createTempFile("tdbtest", null);
+        tempFile.delete();
+        tempFile.mkdirs();
+        tdbTcProvider = new TdbTcProvider(tempFile);
+    }
+
+    @AfterClass
+    public static void cleanUpDirectory() throws IOException {
+        try {
+            TdbTcProvider.delete(tempFile);
+        } catch (IOException e) {
+            System.err.println("failed to delete temp directory: "+tempFile);
+        }
+    }
+
+    @After
+    public void cleanUpGraph() {
+        tdbTcProvider.deleteGraph(MGRAPHNAME);
+    }
+
+    @Override
+    protected Graph getEmptyGraph() {
+        return tdbTcProvider.createGraph(MGRAPHNAME);
+    }
+
+    @Test
+    public void dateStorage() {
+        Graph graph = getEmptyGraph();
+        Date date = new Date(0);
+        LiteralFactory literalFactory = LiteralFactory.getInstance();
+        Literal dateLiteral = literalFactory.createTypedLiteral(date);
+        Triple triple = new TripleImpl(new BlankNode(), new Iri("http://example.com/property"), dateLiteral);
+        graph.add(triple);
+        Assert.assertTrue(graph.contains(triple));
+    }
+
+    @Test
+    public void dateStorage2() {
+        Graph graph = getEmptyGraph();
+        Date date = new Date(0);
+        LiteralFactory literalFactory = LiteralFactory.getInstance();
+        Literal dateLiteral = literalFactory.createTypedLiteral(date);
+        System.out.println(dateLiteral);
+        Iri property = new Iri("http://example.com/property");
+        Triple triple = new TripleImpl(new BlankNode(), property, dateLiteral);
+        graph.add(triple);
+
+        Triple tripleFromGraph = null;
+        Iterator<Triple> propertyTriples = graph.filter(null, property, dateLiteral);
+        if (propertyTriples.hasNext()) {
+            tripleFromGraph = propertyTriples.next();
+        } else {
+            Assert.assertTrue(false);
+        }
+        Assert.assertEquals(dateLiteral, tripleFromGraph.getObject());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
deleted file mode 100644
index e09c0e4..0000000
--- a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.Iterator;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.LiteralFactory;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.TypedLiteral;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.core.test.MGraphTest;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class TdbMGraphTest extends MGraphTest {
-    private static File tempFile;
-    final private UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
-    static private TdbTcProvider tdbTcProvider;
-
-    @BeforeClass
-    public static void setupDirectory() throws IOException {
-        tempFile = File.createTempFile("tdbtest", null);
-        tempFile.delete();
-        tempFile.mkdirs();
-        tdbTcProvider = new TdbTcProvider(tempFile);
-    }
-
-    @AfterClass
-    public static void cleanUpDirectory() throws IOException {
-        try {
-            TdbTcProvider.delete(tempFile);
-        } catch (IOException e) {
-            System.err.println("failed to delete temp directory: "+tempFile);
-        }
-    }
-
-    @After
-    public void cleanUpGraph() {
-        tdbTcProvider.deleteTripleCollection(MGRAPHNAME);
-    }
-
-    @Override
-    protected MGraph getEmptyMGraph() {
-        return tdbTcProvider.createMGraph(MGRAPHNAME);
-    }
-
-    @Test
-    public void dateStorage() {
-        MGraph graph = getEmptyMGraph();
-        Date date = new Date(0);
-        LiteralFactory literalFactory = LiteralFactory.getInstance();
-        TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
-        Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), dateLiteral);
-        graph.add(triple);
-        Assert.assertTrue(graph.contains(triple));
-    }
-
-    @Test
-    public void dateStorage2() {
-        MGraph graph = getEmptyMGraph();
-        Date date = new Date(0);
-        LiteralFactory literalFactory = LiteralFactory.getInstance();
-        TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
-        System.out.println(dateLiteral);
-        UriRef property = new UriRef("http://example.com/property");
-        Triple triple = new TripleImpl(new BNode(), property, dateLiteral);
-        graph.add(triple);
-
-        Triple tripleFromGraph = null;
-        Iterator<Triple> propertyTriples = graph.filter(null, property, dateLiteral);
-        if (propertyTriples.hasNext()) {
-            tripleFromGraph = propertyTriples.next();
-        } else {
-            Assert.assertTrue(false);
-        }
-        Assert.assertEquals(dateLiteral, tripleFromGraph.getObject());
-    }
-
-}


[02/14] clerezza git commit: CLEREZZA-966: moved rdf.utils into the hierarchy

Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
new file mode 100644
index 0000000..fad1d6b
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils.smushing;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A utility to equate duplicate nodes in an Mgarph, currently only nodes with 
+ * a shared ifp are equated.
+ *
+ * @author reto
+ */
+public class IfpSmusher extends BaseSmusher {
+    
+    static final Logger log = LoggerFactory.getLogger(IfpSmusher.class);
+
+    /**
+     * smush mGaph given the ontological facts. Currently it does only
+     * one step ifp smushin, i.e. only ifps are taken in account and only
+     * nodes that have the same node as ifp object in the orignal graph are
+     * equates. (calling the method a second time might lead to additional
+     * smushings.)
+     *
+     * @param mGraph
+     * @param tBox
+     */
+    public void smush(Graph mGraph, Graph tBox) {
+        final Set<Iri> ifps = getIfps(tBox);
+        final Map<PredicateObject, Set<BlankNodeOrIri>> ifp2nodesMap = new HashMap<PredicateObject, Set<BlankNodeOrIri>>();
+        for (Iterator<Triple> it = mGraph.iterator(); it.hasNext();) {
+            final Triple triple = it.next();
+            final Iri predicate = triple.getPredicate();
+            if (!ifps.contains(predicate)) {
+                continue;
+            }
+            final PredicateObject po = new PredicateObject(predicate, triple.getObject());
+            Set<BlankNodeOrIri> equivalentNodes = ifp2nodesMap.get(po);
+            if (equivalentNodes == null) {
+                equivalentNodes = new HashSet<BlankNodeOrIri>();
+                ifp2nodesMap.put(po, equivalentNodes);
+            }
+            equivalentNodes.add(triple.getSubject());
+        }
+        Set<Set<BlankNodeOrIri>> unitedEquivalenceSets = uniteSetsWithCommonElement(ifp2nodesMap.values());
+        smush(mGraph, unitedEquivalenceSets, true);
+    }
+    
+
+    private Set<Iri> getIfps(Graph tBox) {
+        final Iterator<Triple> ifpDefinitions = tBox.filter(null, RDF.type,
+                OWL.InverseFunctionalProperty);
+        final Set<Iri> ifps = new HashSet<Iri>();
+        while (ifpDefinitions.hasNext()) {
+            final Triple triple = ifpDefinitions.next();
+            ifps.add((Iri) triple.getSubject());
+        }
+        return ifps;
+    }
+
+    private <T> Set<Set<T>> uniteSetsWithCommonElement(
+            Collection<Set<T>> originalSets) {
+        Set<Set<T>> result = new HashSet<Set<T>>();
+        Iterator<Set<T>> iter = originalSets.iterator();
+        while (iter.hasNext()) {
+            Set<T> originalSet = iter.next();
+            //TODO this could be done more efficiently with a map
+            Set<T> matchingSet = getMatchinSet(originalSet, result);
+            if (matchingSet != null) {
+                matchingSet.addAll(originalSet);
+            } else {
+                result.add(new HashSet<T>(originalSet));
+            }
+        }
+        if (result.size() < originalSets.size()) {
+            return uniteSetsWithCommonElement(result);
+        } else {
+            return result;
+        }
+    }
+
+    private <T> Set<T> getMatchinSet(Set<T> set, Set<Set<T>> setOfSet) {
+        for (Set<T> current : setOfSet) {
+            if (shareElements(set,current)) {
+                return current;
+            }
+        }
+        return null;
+    }
+
+    private <T> boolean shareElements(Set<T> set1, Set<T> set2) {
+        for (T elem : set2) {
+            if (set1.contains(elem)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+
+    class PredicateObject {
+
+        final Iri predicate;
+        final RdfTerm object;
+
+        public PredicateObject(Iri predicate, RdfTerm object) {
+            this.predicate = predicate;
+            this.object = object;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            final PredicateObject other = (PredicateObject) obj;
+            if (this.predicate != other.predicate && !this.predicate.equals(other.predicate)) {
+                return false;
+            }
+            if (this.object != other.object && !this.object.equals(other.object)) {
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            int hash = 3;
+            hash = 29 * hash + this.predicate.hashCode();
+            hash = 13 * hash + this.object.hashCode();
+            return hash;
+        }
+
+        @Override
+        public String toString() {
+            return "("+predicate+", "+object+")";
+        }
+
+
+    };
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
new file mode 100644
index 0000000..e656a42
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils.smushing;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A utility to equate duplicate nodes in an Mgraph. This unifies owl:sameAs
+ * resources.
+ *
+ * @author reto
+ */
+public class SameAsSmusher extends BaseSmusher {
+    
+    static final Logger log = LoggerFactory.getLogger(SameAsSmusher.class);
+    
+    /**
+     * This will ensure that all properties of sameAs resources are associated
+     * to the preferedIri as returned by {@code getPreferedIri}
+     * @param mGraph
+     * @param owlSameStatements 
+     * @param addCanonicalSameAsStatements if true owl:sameAsStatements with the preferedIri as object will be added
+     */
+    public void smush(Graph mGraph, 
+            Graph owlSameStatements,
+            boolean addCanonicalSameAsStatements) {
+    	
+    	log.info("Starting smushing");
+        
+    	// This hashmap contains a uri (key) and the set of equivalent uris (value)
+    	final Map<BlankNodeOrIri, Set<BlankNodeOrIri>> node2EquivalenceSet = new HashMap<BlankNodeOrIri, Set<BlankNodeOrIri>>();
+    	
+    	log.info("Creating the sets of equivalent uris of each subject or object in the owl:sameAs statements");
+    	// Determines for each subject and object in all the owl:sameAs statements the set of ewquivalent uris 
+    	for (Iterator<Triple> it = owlSameStatements.iterator(); it.hasNext();) {            
+    		final Triple triple = it.next();
+            final Iri predicate = triple.getPredicate();
+            if (!predicate.equals(OWL.sameAs)) {
+                throw new RuntimeException("Statements must use only <http://www.w3.org/2002/07/owl#sameAs> predicate.");
+            }
+            final BlankNodeOrIri subject = triple.getSubject();
+            //literals not yet supported
+            final BlankNodeOrIri object = (BlankNodeOrIri)triple.getObject();
+            
+            Set<BlankNodeOrIri> equivalentNodes = node2EquivalenceSet.get(subject);
+            
+            // if there is not a set of equivalent uris then create a new set
+            if (equivalentNodes == null) {
+            	equivalentNodes = node2EquivalenceSet.get(object);
+            	if (equivalentNodes == null) {
+                    equivalentNodes = new HashSet<BlankNodeOrIri>();
+                }
+            } else {
+                Set<BlankNodeOrIri> objectSet = node2EquivalenceSet.get(object);
+                if ((objectSet != null) && (objectSet != equivalentNodes)) {
+                    //merge two sets
+                    for (BlankNodeOrIri res : objectSet) {
+                        node2EquivalenceSet.remove(res);
+                    }
+                    for (BlankNodeOrIri res : objectSet) {
+                        node2EquivalenceSet.put(res,equivalentNodes);
+                    }
+                    equivalentNodes.addAll(objectSet);
+                }
+            }
+            
+            // add both subject and object of the owl:sameAs statement to the set of equivalent uris
+            equivalentNodes.add(subject);
+            equivalentNodes.add(object);
+            
+            // use both uris in the owl:sameAs statement as keys for the set of equivalent uris
+            node2EquivalenceSet.put(subject, equivalentNodes);
+            node2EquivalenceSet.put(object, equivalentNodes);
+            
+            log.info("Sets of equivalent uris created.");
+        
+    	}
+    	
+    	// This set contains the sets of equivalent uris
+    	Set<Set<BlankNodeOrIri>> unitedEquivalenceSets = new HashSet<Set<BlankNodeOrIri>>(node2EquivalenceSet.values());
+        smush(mGraph, unitedEquivalenceSets, addCanonicalSameAsStatements);
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java
new file mode 100644
index 0000000..fa14977
--- /dev/null
+++ b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.rdf.utils;
+
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.utils.GraphUtils.NoSuchSubGraphException;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class GraphUtilsTest {
+
+    final Iri u1 = new Iri("http://ex.org/1");
+    final Iri u2 = new Iri("http://ex.org/2");
+    final Iri u3 = new Iri("http://ex.org/3");
+
+    @Test
+    public void removeSubGraph() throws NoSuchSubGraphException {
+        Graph baseGraph = createBaseGraph();
+
+        Graph subGraph = new SimpleGraph();
+        {
+            BlankNode bNode1 = new BlankNode();
+            BlankNode bNode2 = new BlankNode();
+            subGraph.add(new TripleImpl(u1, u2, bNode2));
+            subGraph.add(new TripleImpl(bNode2, u2, bNode2));
+            subGraph.add(new TripleImpl(bNode2, u2, bNode1));
+        }
+        GraphUtils.removeSubGraph(baseGraph, subGraph);
+        Assert.assertEquals(1, baseGraph.size());
+    }
+
+    private Graph createBaseGraph() {
+        Graph baseGraph = new SimpleGraph();
+        {
+            BlankNode bNode1 = new BlankNode();
+            BlankNode bNode2 = new BlankNode();
+            baseGraph.add(new TripleImpl(u1, u2, bNode2));
+            baseGraph.add(new TripleImpl(bNode2, u2, bNode2));
+            baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
+            baseGraph.add(new TripleImpl(u3, u2, u1));
+        }
+        return baseGraph;
+    }
+    
+    /** It is required that the subgraph comprises the whole context of the Bnodes it ioncludes
+     * 
+     * @throws org.apache.clerezza.rdf.utils.GraphUtils.NoSuchSubGraphException
+     */
+    @Test(expected=NoSuchSubGraphException.class)
+    public void removeIncompleteSubGraph() throws NoSuchSubGraphException {
+        Graph baseGraph = createBaseGraph();
+
+        Graph subGraph = new SimpleGraph();
+        {
+            BlankNode bNode1 = new BlankNode();
+            BlankNode bNode2 = new BlankNode();
+            subGraph.add(new TripleImpl(u1, u2, bNode2));
+            subGraph.add(new TripleImpl(bNode2, u2, bNode2));
+        }
+        GraphUtils.removeSubGraph(baseGraph, subGraph);
+    }
+
+    @Test(expected=NoSuchSubGraphException.class)
+    public void removeInvalidSubGraph() throws NoSuchSubGraphException {
+        Graph baseGraph = createBaseGraph();
+
+        Graph subGraph = new SimpleGraph();
+        {
+            BlankNode bNode1 = new BlankNode();
+            BlankNode bNode2 = new BlankNode();
+            subGraph.add(new TripleImpl(u1, u2, bNode2));
+            subGraph.add(new TripleImpl(bNode2, u2, bNode2));
+            baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
+            baseGraph.add(new TripleImpl(bNode2, u2, new BlankNode()));
+        }
+        GraphUtils.removeSubGraph(baseGraph, subGraph);
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
new file mode 100644
index 0000000..d7a2b81
--- /dev/null
+++ b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.FOAF;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.ontologies.RDFS;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class IfpSmushTest {
+
+    private Graph ontology = new SimpleGraph();
+    {
+        ontology.add(new TripleImpl(FOAF.mbox, RDF.type, OWL.InverseFunctionalProperty));
+    }
+
+    @Test
+    public void simpleBlankNode()  {
+        Graph mGraph = new SimpleGraph();
+        Iri mbox1 = new Iri("mailto:foo@example.org");
+        final BlankNode bNode1 = new BlankNode();
+        mGraph.add(new TripleImpl(bNode1, FOAF.mbox, mbox1));
+        mGraph.add(new TripleImpl(bNode1, RDFS.comment, 
+                new PlainLiteralImpl("a comment")));
+        final BlankNode bNode2 = new BlankNode();
+        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
+        mGraph.add(new TripleImpl(bNode2, RDFS.comment, 
+                new PlainLiteralImpl("another comment")));
+        Smusher.smush(mGraph, ontology);
+        Assert.assertEquals(3, mGraph.size());
+    }
+
+    @Test
+    public void overlappingEquivalenceClasses()  {
+        Graph mGraph = new SimpleGraph();
+        Iri mbox1 = new Iri("mailto:foo@example.org");
+        final BlankNode bNode1 = new BlankNode();
+        mGraph.add(new TripleImpl(bNode1, FOAF.mbox, mbox1));
+        mGraph.add(new TripleImpl(bNode1, RDFS.comment,
+                new PlainLiteralImpl("a comment")));
+        final BlankNode bNode2 = new BlankNode();
+        Iri mbox2 = new Iri("mailto:bar@example.org");
+        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
+        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox2));
+        mGraph.add(new TripleImpl(bNode2, RDFS.comment,
+                new PlainLiteralImpl("another comment")));
+        final BlankNode bNode3 = new BlankNode();
+        mGraph.add(new TripleImpl(bNode3, FOAF.mbox, mbox2));
+        mGraph.add(new TripleImpl(bNode3, RDFS.comment,
+                new PlainLiteralImpl("yet another comment")));
+        Smusher.smush(mGraph, ontology);
+        Assert.assertEquals(5, mGraph.size());
+    }
+
+    @Test
+    public void oneIri()  {
+        Graph mGraph = new SimpleGraph();
+        Iri mbox1 = new Iri("mailto:foo@example.org");
+        final Iri resource = new Iri("http://example.org/");
+        mGraph.add(new TripleImpl(resource, FOAF.mbox, mbox1));
+        mGraph.add(new TripleImpl(resource, RDFS.comment,
+                new PlainLiteralImpl("a comment")));
+        final BlankNode bNode2 = new BlankNode();
+        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
+        mGraph.add(new TripleImpl(bNode2, RDFS.comment,
+                new PlainLiteralImpl("another comment")));
+        Smusher.smush(mGraph, ontology);
+        Assert.assertEquals(3, mGraph.size());
+    }
+
+    @Test
+    public void twoIris()  {
+        Graph mGraph = new SimpleGraph();
+        Iri mbox1 = new Iri("mailto:foo@example.org");
+        final Iri resource1 = new Iri("http://example.org/");
+        mGraph.add(new TripleImpl(resource1, FOAF.mbox, mbox1));
+        mGraph.add(new TripleImpl(resource1, RDFS.comment,
+                new PlainLiteralImpl("a comment")));
+        final Iri resource2 = new Iri("http://2.example.org/");
+        mGraph.add(new TripleImpl(resource2, FOAF.mbox, mbox1));
+        mGraph.add(new TripleImpl(resource2, RDFS.comment,
+                new PlainLiteralImpl("another comment")));
+        Smusher.smush(mGraph, ontology);
+        Assert.assertEquals(4, mGraph.size());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
new file mode 100644
index 0000000..cd4045d
--- /dev/null
+++ b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author rbn
+ */
+public class RdfListTest {
+
+    @Test
+    public void listCreationAndAccess() {
+        Graph tc = new SimpleGraph();
+        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
+        assertEquals(0, list.size());
+        list.add(new PlainLiteralImpl("hello"));
+        list.add(new PlainLiteralImpl("world"));
+        assertEquals(new PlainLiteralImpl("hello"), list.get(0));
+        assertEquals(new PlainLiteralImpl("world"), list.get(1));
+        assertEquals(2, list.size());
+        list.add(new PlainLiteralImpl("welcome"));
+        assertEquals(3, list.size());
+        assertEquals(new PlainLiteralImpl("welcome"), list.get(2));
+        list.add(1, new PlainLiteralImpl("interesting"));
+        assertEquals(4, list.size());
+        assertEquals(new PlainLiteralImpl("interesting"), list.get(1));
+        assertEquals(new PlainLiteralImpl("world"), list.get(2));
+        assertEquals(new PlainLiteralImpl("welcome"), list.get(3));
+        list.add(0, new PlainLiteralImpl("start"));
+        assertEquals(5, list.size());
+        assertEquals(new PlainLiteralImpl("hello"), list.get(1));
+        assertEquals(new PlainLiteralImpl("interesting"), list.get(2));
+        List<RdfTerm> list2 = new RdfList(new Iri("http://example.org/mytest"), tc);
+        assertEquals(5, list2.size());
+        assertEquals(new PlainLiteralImpl("hello"), list2.get(1));
+        assertEquals(new PlainLiteralImpl("interesting"), list2.get(2));
+        list2.remove(2);
+        assertEquals(4, list2.size());
+        assertEquals(new PlainLiteralImpl("hello"), list2.get(1));
+        assertEquals(new PlainLiteralImpl("world"), list2.get(2));
+        while (list2.size() > 0) {
+            list2.remove(0);
+        }
+        assertEquals(1, tc.size()); //list = rdf:nil statement
+        list2.add(0, new PlainLiteralImpl("restart"));
+        list2.add(1, new PlainLiteralImpl("over"));
+        assertEquals(2, list2.size());
+        list2.add(new PlainLiteralImpl("2"));
+        list2.add(new PlainLiteralImpl("3"));
+        assertEquals(4, list2.size());
+        list2.add(new PlainLiteralImpl("4"));
+        list2.add(new PlainLiteralImpl("5"));
+        assertEquals(new PlainLiteralImpl("3"), list2.get(3));
+    }
+
+    @Test
+    public void listCreationAndAccess2() {
+        Graph tc = new SimpleGraph();
+        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
+        assertEquals(0, list.size());
+        list.add(0,new PlainLiteralImpl("world"));
+        list = new RdfList(new Iri("http://example.org/mytest"), tc);
+        list.add(0,new PlainLiteralImpl("beautifuly"));
+        list = new RdfList(new Iri("http://example.org/mytest"), tc);
+        list.add(0,new PlainLiteralImpl("hello"));
+        assertEquals(new PlainLiteralImpl("hello"), list.get(0));
+        assertEquals(new PlainLiteralImpl("beautifuly"), list.get(1));
+        assertEquals(new PlainLiteralImpl("world"), list.get(2));
+    }
+
+    @Test
+    public void listCreationAndAccess3() {
+        Graph tc = new SimpleGraph();
+        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
+        assertEquals(0, list.size());
+        BlankNode node0 = new BlankNode() {};
+        BlankNode node1 = new BlankNode() {};
+        BlankNode node2 = new BlankNode() {};
+        list.add(0,node2);
+        list.add(0,node1);
+        list.add(0,node0);
+        assertEquals(node0, list.get(0));
+        assertEquals(node1, list.get(1));
+        assertEquals(node2, list.get(2));
+    }
+
+    @Test
+    public void secondButLastElementAccessTest() {
+        Graph tc = new SimpleGraph();
+        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest2"), tc);
+        list.add(new PlainLiteralImpl("hello"));
+        list.add(new PlainLiteralImpl("world"));
+        list.remove(1);
+        assertEquals(1, list.size());
+    }
+
+    @Test
+    public void cleanGraphAfterRemoval() {
+        Graph tc = new SimpleGraph();
+        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
+        list.add(new PlainLiteralImpl("hello"));
+        list.add(new PlainLiteralImpl("world"));
+        list.remove(1);
+        Assert.assertEquals(2, tc.size());
+
+    }
+
+    @Test
+    public void findContainingListNodesAndfindContainingListsTest() {
+        Graph tc = new SimpleGraph();
+        GraphNode listA = new GraphNode(new Iri("http:///listA"), tc);
+        GraphNode listB = new GraphNode(new Iri("http:///listB"), tc);
+        BlankNode element1 = new BlankNode();
+        BlankNode element2 = new BlankNode();
+        BlankNode element3 = new BlankNode();
+        BlankNode element4 = new BlankNode();
+        BlankNode element5 = new BlankNode();
+
+        RdfList rdfListA = new RdfList(listA);
+        rdfListA.add(element1);
+        rdfListA.add(element2);
+        rdfListA.add(element3);
+        rdfListA.add(element4);
+
+        RdfList rdfListB = new RdfList(listB);
+        rdfListB.add(element2);
+        rdfListB.add(element4);
+        rdfListB.add(element5);
+
+        Set<GraphNode> containingListNodes = RdfList.findContainingListNodes(
+                new GraphNode(element3, tc));
+        Assert.assertEquals(1, containingListNodes.size());
+        Assert.assertTrue(containingListNodes.contains(listA));
+
+        Set<RdfList> containingLists = RdfList.findContainingLists(
+                new GraphNode(element3, tc));
+        Assert.assertEquals(1, containingLists.size());
+        Assert.assertTrue(containingLists.contains(rdfListA));
+
+        containingListNodes = RdfList.findContainingListNodes(
+                new GraphNode(element4, tc));
+        Assert.assertEquals(2, containingListNodes.size());
+        Assert.assertTrue(containingListNodes.contains(listA));
+        Assert.assertTrue(containingListNodes.contains(listB));
+
+        containingLists = RdfList.findContainingLists(
+                new GraphNode(element4, tc));
+        Assert.assertEquals(2, containingLists.size());
+        Assert.assertTrue(containingLists.contains(rdfListA));
+        Assert.assertTrue(containingLists.contains(rdfListB));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
new file mode 100644
index 0000000..66c4005
--- /dev/null
+++ b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import java.util.Iterator;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.FOAF;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.ontologies.RDFS;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class SameAsSmushTest {
+    
+    private final Iri uriA = new Iri("http://example.org/A");
+    private final Iri uriB = new Iri("http://example.org/B");
+    private final Literal lit = new PlainLiteralImpl("That's me (and you)");
+
+    private Graph sameAsStatements = new SimpleGraph();
+    {
+        sameAsStatements.add(new TripleImpl(uriA, OWL.sameAs, uriB));
+    }
+    
+    private Graph  dataGraph = new SimpleGraph();
+    {
+        dataGraph.add(new TripleImpl(uriA, FOAF.knows, uriB));
+        dataGraph.add(new TripleImpl(uriB, RDFS.label, lit));
+        dataGraph.add(new TripleImpl(uriA, RDFS.label, lit));
+    }
+
+    @Test
+    public void simple()  {
+        Assert.assertEquals(3, dataGraph.size());
+        Smusher.sameAsSmush(dataGraph, sameAsStatements);
+        Assert.assertEquals(3, dataGraph.size());
+        Assert.assertTrue(dataGraph.filter(null, OWL.sameAs, null).hasNext());
+        //exactly one statement with literal 
+        Iterator<Triple> litStmts = dataGraph.filter(null, null, lit);
+        Assert.assertTrue(litStmts.hasNext());
+        Triple litStmt = litStmts.next();
+        Assert.assertFalse(litStmts.hasNext());
+        Iterator<Triple> knowsStmts = dataGraph.filter(null, FOAF.knows, null);
+        Assert.assertTrue(knowsStmts.hasNext());
+        Triple knowStmt = knowsStmts.next();
+        Assert.assertEquals(knowStmt.getSubject(), knowStmt.getObject());
+        Assert.assertEquals(litStmt.getSubject(), knowStmt.getObject());
+        Assert.assertEquals(litStmt.getSubject(), dataGraph.filter(null, OWL.sameAs, null).next().getObject());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
new file mode 100644
index 0000000..af8434a
--- /dev/null
+++ b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
@@ -0,0 +1,271 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import junit.framework.Assert;
+import org.junit.Test;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.core.test.RandomGraph;
+
+/**
+ *
+ * @author reto, mir
+ */
+public class TestGraphNode {
+
+    @Test
+    public void nodeContext() {
+        Graph g = new SimpleGraph();
+        BlankNode bNode1 = new BlankNode() {};
+        BlankNode bNode2 = new BlankNode() {};
+        Iri property1 = new Iri("http://example.org/property1");
+        Iri property2 = new Iri("http://example.org/property2");
+        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("literal")));
+        g.add(new TripleImpl(bNode1, property2, property1));
+        g.add(new TripleImpl(bNode2, property2, bNode1));
+        g.add(new TripleImpl(property1, property1, bNode2));
+        g.add(new TripleImpl(property1, property1, new PlainLiteralImpl("bla bla")));
+        GraphNode n = new GraphNode(bNode1, g);
+        Assert.assertEquals(4, n.getNodeContext().size());
+        n.deleteNodeContext();
+        Assert.assertEquals(1, g.size());
+        Assert.assertFalse(n.getObjects(property2).hasNext());
+    }
+
+    @Test
+    public void addNode() {
+        Graph g = new SimpleGraph();
+        BlankNode bNode1 = new BlankNode() {};
+        BlankNode bNode2 = new BlankNode() {};
+        Iri property1 = new Iri("http://example.org/property1");
+        GraphNode n = new GraphNode(bNode1, g);
+        n.addProperty(property1, bNode2);
+        Assert.assertEquals(1, g.size());
+    }
+
+    @Test
+    public void testGetSubjectAndObjectNodes() {
+        RandomGraph graph = new RandomGraph(500, 20, new SimpleGraph());
+        for (int j = 0; j < 200; j++) {
+            Triple randomTriple = graph.getRandomTriple();
+            GraphNode node = new GraphNode(randomTriple.getSubject(), graph);
+            Iterator<Iri> properties = node.getProperties();
+            while (properties.hasNext()) {
+                Iri property = properties.next();
+                Set<RdfTerm> objects = createSet(node.getObjects(property));
+                Iterator<GraphNode> objectNodes = node.getObjectNodes(property);
+                while (objectNodes.hasNext()) {
+                    GraphNode graphNode = objectNodes.next();
+                    Assert.assertTrue(objects.contains(graphNode.getNode()));
+                }
+            }
+        }
+
+        for (int j = 0; j < 200; j++) {
+            Triple randomTriple = graph.getRandomTriple();
+            GraphNode node = new GraphNode(randomTriple.getObject(), graph);
+            Iterator<Iri> properties = node.getProperties();
+            while (properties.hasNext()) {
+                Iri property = properties.next();
+                Set<RdfTerm> subjects = createSet(node.getSubjects(property));
+                Iterator<GraphNode> subjectNodes = node.getSubjectNodes(property);
+                while (subjectNodes.hasNext()) {
+                    GraphNode graphNode = subjectNodes.next();
+                    Assert.assertTrue(subjects.contains(graphNode.getNode()));
+                }
+            }
+        }
+    }
+
+    @Test
+    public void getAvailableProperties(){
+        Graph g = new SimpleGraph();
+        BlankNode bNode1 = new BlankNode() {};
+        BlankNode bNode2 = new BlankNode() {};
+        Iri property1 = new Iri("http://example.org/property1");
+        Iri property2 = new Iri("http://example.org/property2");
+        Iri property3 = new Iri("http://example.org/property3");
+        Iri property4 = new Iri("http://example.org/property4");
+        ArrayList<Iri> props = new ArrayList<Iri>();
+        props.add(property1);
+        props.add(property2);
+        props.add(property3);
+        props.add(property4);
+        GraphNode n = new GraphNode(bNode1, g);
+        n.addProperty(property1, bNode2);
+        n.addProperty(property2, bNode2);
+        n.addProperty(property3, bNode2);
+        n.addProperty(property4, bNode2);
+        Iterator<Iri> properties = n.getProperties();
+        int i = 0;
+        while(properties.hasNext()){
+            i++;
+            Iri prop = properties.next();
+            Assert.assertTrue(props.contains(prop));
+            props.remove(prop);
+        }
+        Assert.assertEquals(i, 4);
+        Assert.assertEquals(props.size(), 0);
+
+    }
+
+    @Test
+    public void deleteAll() {
+        Graph g = new SimpleGraph();
+        BlankNode bNode1 = new BlankNode() {};
+        BlankNode bNode2 = new BlankNode() {};
+        Iri property1 = new Iri("http://example.org/property1");
+        Iri property2 = new Iri("http://example.org/property2");
+        //the two properties two be deleted
+        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("literal")));
+        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("bla bla")));
+        //this 3 properties should stay
+        g.add(new TripleImpl(bNode1, property2, property1));
+        g.add(new TripleImpl(property1, property1, new PlainLiteralImpl("bla bla")));
+        g.add(new TripleImpl(bNode2, property1, new PlainLiteralImpl("bla bla")));
+        GraphNode n = new GraphNode(bNode1, g);
+        n.deleteProperties(property1);
+        Assert.assertEquals(3, g.size());
+    }
+
+    @Test
+    public void deleteSingleProperty() {
+        Graph g = new SimpleGraph();
+        BlankNode bNode1 = new BlankNode() {};
+        BlankNode bNode2 = new BlankNode() {};
+        Iri property1 = new Iri("http://example.org/property1");
+        Iri property2 = new Iri("http://example.org/property2");
+        //the properties two be deleted
+        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("literal")));
+        //this 4 properties should stay
+        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("bla bla")));
+        g.add(new TripleImpl(bNode1, property2, property1));
+        g.add(new TripleImpl(property1, property1, new PlainLiteralImpl("bla bla")));
+        g.add(new TripleImpl(bNode2, property1, new PlainLiteralImpl("bla bla")));
+        GraphNode n = new GraphNode(bNode1, g);
+        n.deleteProperty(property1, new PlainLiteralImpl("literal"));
+        Assert.assertEquals(4, g.size());
+    }
+
+    @Test
+    public void replaceWith() {
+        Graph initialGraph = new SimpleGraph();
+        BlankNode bNode1 = new BlankNode();
+        BlankNode bNode2 = new BlankNode();
+        BlankNode newBnode = new BlankNode();
+        Iri property1 = new Iri("http://example.org/property1");
+        Iri property2 = new Iri("http://example.org/property2");
+        Iri newIri = new Iri("http://example.org/newName");
+        Literal literal1 = new PlainLiteralImpl("literal");
+        Literal literal2 = new PlainLiteralImpl("bla bla");
+
+        Triple triple1 = new TripleImpl(bNode1, property1, literal1);
+        Triple triple2 = new TripleImpl(bNode1, property2, property1);
+        Triple triple3 = new TripleImpl(bNode2, property2, bNode1);
+        Triple triple4 = new TripleImpl(property1, property1, bNode2);
+        Triple triple5 = new TripleImpl(property1, property1, literal2);
+        initialGraph.add(triple1);
+        initialGraph.add(triple2);
+        initialGraph.add(triple3);
+        initialGraph.add(triple4);
+        initialGraph.add(triple5);
+        GraphNode node = new GraphNode(property1,
+                new SimpleGraph(initialGraph.iterator()));
+
+        node.replaceWith(newIri, true);
+        Assert.assertEquals(5, node.getGraph().size());
+        Triple expectedTriple1 = new TripleImpl(bNode1, newIri, literal1);
+        Triple expectedTriple2 = new TripleImpl(bNode1, property2, newIri);
+        Triple expectedTriple3 = new TripleImpl(newIri, newIri, bNode2);
+        Triple expectedTriple4 = new TripleImpl(newIri, newIri, literal2);
+
+        Assert.assertTrue(node.getGraph().contains(expectedTriple1));
+        Assert.assertTrue(node.getGraph().contains(expectedTriple2));
+        Assert.assertTrue(node.getGraph().contains(expectedTriple3));
+        Assert.assertTrue(node.getGraph().contains(expectedTriple4));
+
+        Assert.assertFalse(node.getGraph().contains(triple1));
+        Assert.assertFalse(node.getGraph().contains(triple2));
+        Assert.assertFalse(node.getGraph().contains(triple4));
+        Assert.assertFalse(node.getGraph().contains(triple5));
+
+        node = new GraphNode(property1, new SimpleGraph(initialGraph.iterator()));
+        node.replaceWith(newBnode);
+        Triple expectedTriple5 = new TripleImpl(bNode1, property2, newBnode);
+        Triple expectedTriple6 = new TripleImpl(newBnode, property1, bNode2);
+        Triple expectedTriple7 = new TripleImpl(newBnode, property1, literal2);
+
+        Assert.assertTrue(node.getGraph().contains(triple1));
+        Assert.assertTrue(node.getGraph().contains(expectedTriple5));
+        Assert.assertTrue(node.getGraph().contains(expectedTriple6));
+        Assert.assertTrue(node.getGraph().contains(expectedTriple7));
+
+        node = new GraphNode(literal1, new SimpleGraph(initialGraph.iterator()));
+        node.replaceWith(newBnode);
+        Triple expectedTriple8 = new TripleImpl(bNode1, property1, newBnode);
+        Assert.assertTrue(node.getGraph().contains(expectedTriple8));
+
+        node = new GraphNode(property1, new SimpleGraph(initialGraph.iterator()));
+        node.replaceWith(newIri);
+        Triple expectedTriple9 = new TripleImpl(bNode1, property2, newIri);
+        Triple expectedTriple10 = new TripleImpl(newIri, property1, bNode2);
+        Triple expectedTriple11 = new TripleImpl(newIri, property1, literal2);
+        Assert.assertTrue(node.getGraph().contains(triple1));
+        Assert.assertTrue(node.getGraph().contains(expectedTriple9));
+        Assert.assertTrue(node.getGraph().contains(expectedTriple10));
+        Assert.assertTrue(node.getGraph().contains(expectedTriple11));
+    }
+
+    @Test
+    public void equality() {
+        Graph g = new SimpleGraph();
+        BlankNode bNode1 = new BlankNode() {};
+        BlankNode bNode2 = new BlankNode() {};
+        Iri property1 = new Iri("http://example.org/property1");
+        GraphNode n = new GraphNode(bNode1, g);
+        n.addProperty(property1, bNode2);
+        Assert.assertTrue(n.equals(new GraphNode(bNode1, g)));
+        Assert.assertFalse(n.equals(new GraphNode(bNode2, g)));
+        GraphNode n2 = null;
+        Assert.assertFalse(n.equals(n2));
+    }
+
+    private Set<RdfTerm> createSet(Iterator<? extends RdfTerm> resources) {
+        Set<RdfTerm> set = new HashSet<RdfTerm>();
+        while (resources.hasNext()) {
+            RdfTerm resource = resources.next();
+            set.add(resource);
+        }
+        return set;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java
new file mode 100644
index 0000000..2881eb4
--- /dev/null
+++ b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import java.util.Iterator;
+import org.junit.Test;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.junit.Assert;
+
+/**
+ *
+ * @author hasan
+ */
+public class UnionGraphTest {
+
+    private final Iri uriRef1 =
+            new Iri("http://example.org/ontology#res1");
+    private final Iri uriRef2 =
+            new Iri("http://example.org/ontology#res2");
+    private final Iri uriRef3 =
+            new Iri("http://example.org/ontology#res3");
+    private final Iri uriRef4 =
+            new Iri("http://example.org/ontology#res4");
+
+    @Test
+    public void readAccess() {
+        Graph graph = new SimpleGraph();
+        Graph graph2 = new SimpleGraph();
+        BlankNode bnode = new BlankNode() {
+        };
+        graph.add(new TripleImpl(uriRef1, uriRef2, uriRef1));
+        graph2.add(new TripleImpl(bnode, uriRef1, uriRef3));
+        Graph unionGraph = new UnionGraph(graph, graph2);
+        Iterator<Triple> unionTriples = unionGraph.iterator();
+        Assert.assertTrue(unionTriples.hasNext());
+        unionTriples.next();
+        Assert.assertTrue(unionTriples.hasNext());
+        unionTriples.next();
+        Assert.assertFalse(unionTriples.hasNext());
+        Assert.assertEquals(2, unionGraph.size());
+    }
+    
+    @Test
+    public void writeAccess() {
+        Graph graph = new SimpleGraph();
+        Graph graph2 = new SimpleGraph();
+        BlankNode bnode = new BlankNode() {
+        };
+        graph2.add(new TripleImpl(bnode, uriRef1, uriRef3));
+        Graph unionGraph = new UnionGraph(graph, graph2);
+        Assert.assertEquals(1, unionGraph.size());
+        unionGraph.add(new TripleImpl(uriRef4, uriRef1, uriRef3));
+        Assert.assertEquals(1, graph.size());
+        Assert.assertEquals(2, unionGraph.size());
+        Assert.assertEquals(1, graph2.size());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
new file mode 100644
index 0000000..bab58e9
--- /dev/null
+++ b/rdf/utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils.smushing;
+
+import java.util.Iterator;
+import java.util.Set;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.FOAF;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.ontologies.RDFS;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class SameAsSmushTest {
+    
+    private final Iri uriA = new Iri("http://example.org/A");
+    private final Iri uriB = new Iri("http://example.org/B");
+    private final Iri uriC = new Iri("http://example.org/C");
+    
+    private final Literal lit = new PlainLiteralImpl("That's me (and you)");
+
+    private Graph sameAsStatements = new SimpleGraph();
+    {
+        sameAsStatements.add(new TripleImpl(uriA, OWL.sameAs, uriB));
+    }
+    
+    private Graph  dataGraph = new SimpleGraph();
+    {
+        dataGraph.add(new TripleImpl(uriA, FOAF.knows, uriB));
+        dataGraph.add(new TripleImpl(uriB, RDFS.label, lit));
+        dataGraph.add(new TripleImpl(uriA, RDFS.label, lit));
+    }
+
+    @Test
+    public void simple()  {
+        SameAsSmusher smusher = new SameAsSmusher() {
+
+            @Override
+            protected Iri getPreferedIri(Set<Iri> uriRefs) {
+                if (!uriRefs.contains(uriA)) throw new RuntimeException("not the set we excpect");
+                if (!uriRefs.contains(uriB)) throw new RuntimeException("not the set we excpect");
+                return uriC;
+            }
+            
+        };
+        Assert.assertEquals(3, dataGraph.size());
+        smusher.smush(dataGraph, sameAsStatements, true);
+        Assert.assertEquals(4, dataGraph.size());
+        Assert.assertTrue(dataGraph.filter(null, OWL.sameAs, null).hasNext());
+        //exactly one statement with literal 
+        Iterator<Triple> litStmts = dataGraph.filter(null, null, lit);
+        Assert.assertTrue(litStmts.hasNext());
+        Triple litStmt = litStmts.next();
+        Assert.assertFalse(litStmts.hasNext());
+        Iterator<Triple> knowsStmts = dataGraph.filter(null, FOAF.knows, null);
+        Assert.assertTrue(knowsStmts.hasNext());
+        Triple knowStmt = knowsStmts.next();
+        Assert.assertEquals(knowStmt.getSubject(), knowStmt.getObject());
+        Assert.assertEquals(litStmt.getSubject(), knowStmt.getObject());
+        Assert.assertEquals(litStmt.getSubject(), dataGraph.filter(null, OWL.sameAs, null).next().getObject());
+        Assert.assertEquals(knowStmt.getSubject(), uriC);
+    }
+
+}


[07/14] clerezza git commit: removed unused import

Posted by re...@apache.org.
removed unused import

Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/0a84a39d
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/0a84a39d
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/0a84a39d

Branch: refs/heads/rdf-commons
Commit: 0a84a39db1d51eeb48095a920a168438ec65091e
Parents: 4777a9b
Author: Reto Gmuer <re...@apache.org>
Authored: Sun Mar 22 17:57:59 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Sun Mar 22 17:57:59 2015 +0000

----------------------------------------------------------------------
 .../src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java     | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/0a84a39d/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
index 8a1365f..a95608d 100644
--- a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
@@ -18,8 +18,6 @@
  */
 package org.apache.clerezza.rdf.utils;
 
-import org.apache.commons.rdf.impl.*;
-import org.apache.commons.rdf.impl.utils.*;
 import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
 import org.apache.commons.rdf.impl.utils.TripleImpl;
 


[06/14] clerezza git commit: CLEREZZA-966: changed names to reflect hierarchy

Posted by re...@apache.org.
CLEREZZA-966: changed names to reflect hierarchy

Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/4777a9b9
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/4777a9b9
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/4777a9b9

Branch: refs/heads/rdf-commons
Commit: 4777a9b9e2068f844d25165eab67cca8437cdbb1
Parents: 74f5fdb
Author: Reto Gmuer <re...@apache.org>
Authored: Sun Mar 22 17:43:17 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Sun Mar 22 17:43:17 2015 +0000

----------------------------------------------------------------------
 provisioning/launchers/full-launcher/pom.xml          | 2 +-
 provisioning/launchers/linked-data-launcher/pom.xml   | 2 +-
 provisioning/launchers/pom.xml                        | 2 +-
 provisioning/launchers/shell-launcher/pom.xml         | 2 +-
 provisioning/launchers/typerendering-launcher/pom.xml | 2 +-
 provisioning/pom.xml                                  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/4777a9b9/provisioning/launchers/full-launcher/pom.xml
----------------------------------------------------------------------
diff --git a/provisioning/launchers/full-launcher/pom.xml b/provisioning/launchers/full-launcher/pom.xml
index 4898a69..4ed6f1a 100644
--- a/provisioning/launchers/full-launcher/pom.xml
+++ b/provisioning/launchers/full-launcher/pom.xml
@@ -27,7 +27,7 @@
     <version>1.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
-    <name>Clerezza - Launcher: Full (sling based)</name>
+    <name>Clerezza - Provisioning - Launchers - Full (sling based)</name>
     <description>Runnable jar using all the clerezza partial bundlelists.
     Note that this is not (yet) as complete as the clerezza platform tdb launcher.</description>
 

http://git-wip-us.apache.org/repos/asf/clerezza/blob/4777a9b9/provisioning/launchers/linked-data-launcher/pom.xml
----------------------------------------------------------------------
diff --git a/provisioning/launchers/linked-data-launcher/pom.xml b/provisioning/launchers/linked-data-launcher/pom.xml
index 21753ad..5e0acb0 100644
--- a/provisioning/launchers/linked-data-launcher/pom.xml
+++ b/provisioning/launchers/linked-data-launcher/pom.xml
@@ -27,7 +27,7 @@
     <version>1.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
-    <name>Clerezza - Launcher: Core Linked Data</name>
+    <name>Clerezza - Provisioning - Launchers - Linked Data Launcher (Core)</name>
     <description>Runnable jar using the clerezza partial bundlelists for Web
         access to the RDF Data.</description>
 

http://git-wip-us.apache.org/repos/asf/clerezza/blob/4777a9b9/provisioning/launchers/pom.xml
----------------------------------------------------------------------
diff --git a/provisioning/launchers/pom.xml b/provisioning/launchers/pom.xml
index d4a2fa0..9d4c120 100644
--- a/provisioning/launchers/pom.xml
+++ b/provisioning/launchers/pom.xml
@@ -40,7 +40,7 @@
     <artifactId>launchers-reactor</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>pom</packaging>
-    <name>Clerezza - Provisioning - Launchers - Reactor</name>
+    <name>Clerezza - Provisioning - Launchers</name>
 
     <modules>
         <module>typerendering-launcher</module>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/4777a9b9/provisioning/launchers/shell-launcher/pom.xml
----------------------------------------------------------------------
diff --git a/provisioning/launchers/shell-launcher/pom.xml b/provisioning/launchers/shell-launcher/pom.xml
index 892f7ca..338983a 100644
--- a/provisioning/launchers/shell-launcher/pom.xml
+++ b/provisioning/launchers/shell-launcher/pom.xml
@@ -27,7 +27,7 @@
     <version>1.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
-    <name>Clerezza - Launcher: Shell only</name>
+    <name>Clerezza - Provisioning - Launchers - Shell only</name>
     <description>Runnable jar using the clerezza partial bundlelists.</description>
     <!-- note that the sling launchpad unnecessarily adds a webserser to it, 
     see: http://mail-archives.apache.org/mod_mbox/sling-users/201403.mbox/%3CCAKkCf4p3gOBwG8ALTNXXb-QYT3Eb6zwSWdVTF8xs8DgkY_fD1A%40mail.gmail.com%3E -->

http://git-wip-us.apache.org/repos/asf/clerezza/blob/4777a9b9/provisioning/launchers/typerendering-launcher/pom.xml
----------------------------------------------------------------------
diff --git a/provisioning/launchers/typerendering-launcher/pom.xml b/provisioning/launchers/typerendering-launcher/pom.xml
index b1798e8..6e3b2a3 100644
--- a/provisioning/launchers/typerendering-launcher/pom.xml
+++ b/provisioning/launchers/typerendering-launcher/pom.xml
@@ -27,7 +27,7 @@
     <version>1.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
-    <name>Clerezza - Launcher: TypeRendering</name>
+    <name>Clerezza - Provisioning - Launchers - TypeRendering</name>
     <description>Runnable jar using the clerezza partial bundlelists needed for
         typerendering.</description>
 

http://git-wip-us.apache.org/repos/asf/clerezza/blob/4777a9b9/provisioning/pom.xml
----------------------------------------------------------------------
diff --git a/provisioning/pom.xml b/provisioning/pom.xml
index 1a0979f..9d67a89 100644
--- a/provisioning/pom.xml
+++ b/provisioning/pom.xml
@@ -40,7 +40,7 @@
     <artifactId>reactor</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <packaging>pom</packaging>
-    <name>Clerezza - Provisioning - Reactor</name>
+    <name>Clerezza - Provisioning</name>
 
     <modules>
         <module>felixosgi</module>


[14/14] clerezza git commit: CLEREZZA-976: ported TDB storage provider and some related fixes, some tests still failing.

Posted by re...@apache.org.
CLEREZZA-976: ported TDB storage provider and some related fixes, some tests still failing.

Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/8a337849
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/8a337849
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/8a337849

Branch: refs/heads/rdf-commons
Commit: 8a337849cfa59c30b740954b93eaa7cec8464167
Parents: be0f378
Author: Reto Gmuer <re...@apache.org>
Authored: Sun Mar 22 22:04:32 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Sun Mar 22 22:04:32 2015 +0000

----------------------------------------------------------------------
 rdf/core.test/pom.xml                           |   4 +-
 rdf/jena/commons/pom.xml                        |  12 +-
 .../rdf/jena/commons/Jena2TriaUtil.java         |  22 +--
 rdf/jena/dependencymanagement/pom.xml           |  57 +++++++
 rdf/jena/facade/pom.xml                         |  21 ++-
 .../clerezza/rdf/jena/facade/JenaGraph.java     |   2 +-
 rdf/jena/parser/pom.xml                         |  12 +-
 rdf/jena/pom.xml                                |   1 +
 rdf/jena/serializer/pom.xml                     |  11 ++
 rdf/jena/sparql/pom.xml                         |  12 +-
 rdf/jena/storage/pom.xml                        |  11 ++
 .../rdf/jena/storage/JenaGraphAdaptor.java      |   6 +
 rdf/jena/tdb.storage/pom.xml                    |  27 +++-
 .../jena/tdb/internals/DatasetLockedMGraph.java |  46 ------
 .../clerezza/rdf/jena/tdb/internals/IriSet.java |  62 ++++++++
 .../rdf/jena/tdb/internals/ModelGraph.java      |  67 ++++----
 .../rdf/jena/tdb/internals/Symbols.java         |  10 +-
 .../rdf/jena/tdb/internals/UriRefSet.java       |  62 --------
 .../rdf/jena/tdb/storage/BaseTdbTcProvider.java |  10 +-
 .../tdb/storage/SingleTdbDatasetTcProvider.java | 154 +++++++++----------
 .../rdf/jena/tdb/storage/TdbTcProvider.java     |  97 ++++++------
 .../MultiThreadedSingleTdbDatasetTest.java      |  35 ++---
 .../rdf/jena/tdb/storage/MultiThreadedTest.java |  24 +--
 .../tdb/storage/MultiThreadedTestSingleTdb.java |  24 +--
 .../tdb/storage/SingleTdbDatasetGraphTest.java  |  56 +++++++
 .../tdb/storage/SingleTdbDatasetMGraphTest.java |  56 -------
 .../storage/SingleTdbDatasetTcProviderTest.java |  70 ++++-----
 .../rdf/jena/tdb/storage/TdbGraphTest.java      | 107 +++++++++++++
 .../rdf/jena/tdb/storage/TdbMGraphTest.java     | 107 -------------
 29 files changed, 638 insertions(+), 547 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/core.test/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/core.test/pom.xml b/rdf/core.test/pom.xml
index 5cd0e48..41e53d0 100644
--- a/rdf/core.test/pom.xml
+++ b/rdf/core.test/pom.xml
@@ -24,8 +24,8 @@
     <parent>
         <artifactId>clerezza</artifactId>
         <groupId>org.apache.clerezza</groupId>
-        <version>1.0.0-SNAPSHOT</version>
-        <relativePath>../parent</relativePath>
+        <version>7-SNAPSHOT</version>
+        <relativePath />
     </parent>
     <groupId>org.apache.clerezza</groupId>
     <artifactId>rdf.core.test</artifactId>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/commons/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/commons/pom.xml b/rdf/jena/commons/pom.xml
index 61b0c99..8cb7a84 100644
--- a/rdf/jena/commons/pom.xml
+++ b/rdf/jena/commons/pom.xml
@@ -33,6 +33,17 @@
     <version>1.0.0-SNAPSHOT</version>
     <name>Clerezza - RDF - Jena - Commons</name>
     <description>Common classes needed by Jena adaptors</description>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.clerezza</groupId>
+                <artifactId>rdf.jena.dependencymanagement</artifactId>
+                <type>pom</type>
+                <version>1.0.0-SNAPSHOT</version>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
     <dependencies>
         <dependency>
             <groupId>org.apache.clerezza.commons-rdf</groupId>
@@ -47,7 +58,6 @@
         <dependency>
             <groupId>org.apache.jena</groupId>
             <artifactId>jena-core</artifactId>
-            <version>2.13.0</version>
             <exclusions>
                 <exclusion>
                     <artifactId>slf4j-log4j12</artifactId>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/commons/src/main/java/org/apache/clerezza/rdf/jena/commons/Jena2TriaUtil.java
----------------------------------------------------------------------
diff --git a/rdf/jena/commons/src/main/java/org/apache/clerezza/rdf/jena/commons/Jena2TriaUtil.java b/rdf/jena/commons/src/main/java/org/apache/clerezza/rdf/jena/commons/Jena2TriaUtil.java
index 32919a4..842c118 100644
--- a/rdf/jena/commons/src/main/java/org/apache/clerezza/rdf/jena/commons/Jena2TriaUtil.java
+++ b/rdf/jena/commons/src/main/java/org/apache/clerezza/rdf/jena/commons/Jena2TriaUtil.java
@@ -27,9 +27,8 @@ import org.apache.commons.rdf.Language;
 import org.apache.commons.rdf.Literal;
 import org.apache.commons.rdf.RdfTerm;
 import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.LiteralImpl;
 import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.apache.commons.rdf.impl.utils.TypedLiteralImpl;
 
 /**
  *
@@ -59,18 +58,19 @@ public class Jena2TriaUtil {
      */
     private Literal convertJenaLiteral2Literal(Node node) {
         final String lexicalForm = node.getLiteralLexicalForm();
-        String datatypeString = node.getLiteralDatatypeURI();
+        final String datatypeString = node.getLiteralDatatypeURI();
+        final String languageTag = node.getLiteralLanguage();
+        Language language = null;
+        if ((languageTag != null) && !languageTag.equals("")) {
+             language = new Language(languageTag);
+        }
+        Iri dataType = null;
         if (datatypeString != null) {
-            Iri dtUriRef = new Iri(datatypeString);
-            return new TypedLiteralImpl(lexicalForm, dtUriRef);
+            dataType = new Iri(datatypeString);
         } else {
-            String language = node.getLiteralLanguage();
-            if ((language != null) && !language.equals("")) {
-                return new PlainLiteralImpl(lexicalForm, new Language(language));
-            } else {
-                return new PlainLiteralImpl(lexicalForm);
-            }
+            dataType = new Iri("http://www.w3.org/2001/XMLSchema#string");
         }
+        return new LiteralImpl(lexicalForm, dataType, language);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/dependencymanagement/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/dependencymanagement/pom.xml b/rdf/jena/dependencymanagement/pom.xml
new file mode 100644
index 0000000..78b9771
--- /dev/null
+++ b/rdf/jena/dependencymanagement/pom.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>clerezza</artifactId>
+        <groupId>org.apache.clerezza</groupId>
+        <version>7-SNAPSHOT</version>
+        <relativePath />
+    </parent>
+    <groupId>org.apache.clerezza</groupId>
+    <artifactId>rdf.jena.dependencymanagement</artifactId>
+    <packaging>pom</packaging>
+    <version>1.0.0-SNAPSHOT</version>
+    <name>Clerezza - RDF - Jena - Dependency Management</name>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.jena</groupId>
+                <artifactId>jena-tdb</artifactId>
+                <version>1.0.1</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.jena</groupId>
+                <artifactId>jena-iri</artifactId>
+                <version>1.0.1</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.jena</groupId>
+                <artifactId>jena-arq</artifactId>
+                <version>2.11.1</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.jena</groupId>
+                <artifactId>jena-core</artifactId>
+                <version>2.11.1</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/facade/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/facade/pom.xml b/rdf/jena/facade/pom.xml
index d9db3ca..4c138b9 100644
--- a/rdf/jena/facade/pom.xml
+++ b/rdf/jena/facade/pom.xml
@@ -18,7 +18,7 @@
  specific language governing permissions and limitations
  under the License.
 
--->
+    -->
 
     <modelVersion>4.0.0</modelVersion>
     <parent>
@@ -33,7 +33,18 @@
     <version>1.0.0-SNAPSHOT</version>
     <name>Clerezza - RDF - Jena - Facade: Jena API on SCB</name>
     <description>An implementation of the Jena API on top of Clerezza RDF Commons, allows to
-    run code written against the Jena API on a source exposing the Clerezza Commons API .</description>
+        run code written against the Jena API on a source exposing the Clerezza Commons API .</description>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.clerezza</groupId>
+                <artifactId>rdf.jena.dependencymanagement</artifactId>
+                <type>pom</type>
+                <version>1.0.0-SNAPSHOT</version>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
     <dependencies>
         <dependency>
             <groupId>org.apache.clerezza.commons-rdf</groupId>
@@ -53,7 +64,11 @@
         <dependency>
             <groupId>org.wymiwyg</groupId>
             <artifactId>wymiwyg-commons-core</artifactId>
-        </dependency>        
+        </dependency>   
+        <dependency>
+            <groupId>org.apache.jena</groupId>
+            <artifactId>jena-core</artifactId>
+        </dependency>     
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/facade/src/main/java/org/apache/clerezza/rdf/jena/facade/JenaGraph.java
----------------------------------------------------------------------
diff --git a/rdf/jena/facade/src/main/java/org/apache/clerezza/rdf/jena/facade/JenaGraph.java b/rdf/jena/facade/src/main/java/org/apache/clerezza/rdf/jena/facade/JenaGraph.java
index 420d6e3..2a7c8a6 100644
--- a/rdf/jena/facade/src/main/java/org/apache/clerezza/rdf/jena/facade/JenaGraph.java
+++ b/rdf/jena/facade/src/main/java/org/apache/clerezza/rdf/jena/facade/JenaGraph.java
@@ -154,7 +154,7 @@ public class JenaGraph extends GraphBase implements com.hp.hpl.jena.graph.Graph
         return new TrackingTripleIterator(convert(filter(m)));
     }
 
-    @Override
+    //not yet @Override
     protected ExtendedIterator<com.hp.hpl.jena.graph.Triple> graphBaseFind(com.hp.hpl.jena.graph.Triple triple) {
         return new TrackingTripleIterator(convert(filter(triple)));
     }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/parser/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/parser/pom.xml b/rdf/jena/parser/pom.xml
index 19fd86c..90572ad 100644
--- a/rdf/jena/parser/pom.xml
+++ b/rdf/jena/parser/pom.xml
@@ -33,6 +33,17 @@
     <version>1.0.0-SNAPSHOT</version>
     <name>Clerezza - RDF - Jena - Parser</name>
     <description>A ParserProvider based on jena</description>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.clerezza</groupId>
+                <artifactId>rdf.jena.dependencymanagement</artifactId>
+                <type>pom</type>
+                <version>1.0.0-SNAPSHOT</version>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
     <dependencies>
         <dependency>
             <groupId>junit</groupId>
@@ -51,7 +62,6 @@
         <dependency>
             <groupId>org.apache.jena</groupId>
             <artifactId>jena-core</artifactId>
-            <version>2.13.0</version>
         </dependency>
         <dependency>
             <groupId>org.apache.clerezza</groupId>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/pom.xml b/rdf/jena/pom.xml
index 54b054b..b41ad1e 100644
--- a/rdf/jena/pom.xml
+++ b/rdf/jena/pom.xml
@@ -43,6 +43,7 @@
     <name>Clerezza - RDF - Jena</name>
     <description>The clerezza RDF Implementation using Jena</description>
     <modules>
+        <module>dependencymanagement</module>
         <module>commons</module>
         <module>facade</module>
         <module>parser</module>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/serializer/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/serializer/pom.xml b/rdf/jena/serializer/pom.xml
index c9cca45..9555624 100644
--- a/rdf/jena/serializer/pom.xml
+++ b/rdf/jena/serializer/pom.xml
@@ -33,6 +33,17 @@
     <version>1.0.0-SNAPSHOT</version>
     <name>Clerezza - RDF - Jena - Serializer</name>
     <description>A SerializingProvider based on jena</description>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.clerezza</groupId>
+                <artifactId>rdf.jena.dependencymanagement</artifactId>
+                <type>pom</type>
+                <version>1.0.0-SNAPSHOT</version>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
     <dependencies>
         <dependency>
             <groupId>org.apache.clerezza</groupId>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/sparql/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/sparql/pom.xml b/rdf/jena/sparql/pom.xml
index 7af8e15..2e8dfb0 100644
--- a/rdf/jena/sparql/pom.xml
+++ b/rdf/jena/sparql/pom.xml
@@ -33,6 +33,17 @@
     <version>1.0.0-SNAPSHOT</version>
     <name>Clerezza - RDF - Jena - SPARQL</name>
     <description>Allows executing SPARQL queries on SCB using the jena sparql engine.</description>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.clerezza</groupId>
+                <artifactId>rdf.jena.dependencymanagement</artifactId>
+                <type>pom</type>
+                <version>1.0.0-SNAPSHOT</version>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
     <dependencies>
         <dependency>
             <groupId>org.apache.clerezza</groupId>
@@ -52,7 +63,6 @@
         <dependency>
             <groupId>org.apache.jena</groupId>
             <artifactId>jena-arq</artifactId>
-            <version>2.11.1</version>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/storage/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/storage/pom.xml b/rdf/jena/storage/pom.xml
index c352ee5..654d13c 100644
--- a/rdf/jena/storage/pom.xml
+++ b/rdf/jena/storage/pom.xml
@@ -33,6 +33,17 @@
     <version>1.0.0-SNAPSHOT</version>
     <name>Clerezza - RDF - Jena - Storage</name>
     <description>Allows converting Jena graphs to SCB graphs. (Currently no TcProvider comprised)</description>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.clerezza</groupId>
+                <artifactId>rdf.jena.dependencymanagement</artifactId>
+                <type>pom</type>
+                <version>1.0.0-SNAPSHOT</version>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
     <dependencies>
         <dependency>
             <groupId>org.apache.clerezza</groupId>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/storage/src/main/java/org/apache/clerezza/rdf/jena/storage/JenaGraphAdaptor.java
----------------------------------------------------------------------
diff --git a/rdf/jena/storage/src/main/java/org/apache/clerezza/rdf/jena/storage/JenaGraphAdaptor.java b/rdf/jena/storage/src/main/java/org/apache/clerezza/rdf/jena/storage/JenaGraphAdaptor.java
index 0fb594e..87df8b1 100644
--- a/rdf/jena/storage/src/main/java/org/apache/clerezza/rdf/jena/storage/JenaGraphAdaptor.java
+++ b/rdf/jena/storage/src/main/java/org/apache/clerezza/rdf/jena/storage/JenaGraphAdaptor.java
@@ -24,6 +24,7 @@ import com.hp.hpl.jena.util.iterator.ExtendedIterator;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.concurrent.locks.ReadWriteLock;
 import org.apache.commons.rdf.BlankNode;
 import org.apache.commons.rdf.BlankNodeOrIri;
 import org.apache.commons.rdf.RdfTerm;
@@ -56,6 +57,11 @@ public class JenaGraphAdaptor extends AbstractGraph {
     public JenaGraphAdaptor(com.hp.hpl.jena.graph.Graph jenaGraph) {
         this.jenaGraph = jenaGraph;
     }
+    
+    public JenaGraphAdaptor(com.hp.hpl.jena.graph.Graph jenaGraph, ReadWriteLock lock) {
+        super(lock);
+        this.jenaGraph = jenaGraph;
+    }
 
     @Override
     public void clear() {

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/pom.xml b/rdf/jena/tdb.storage/pom.xml
index 9306ee3..11d054d 100644
--- a/rdf/jena/tdb.storage/pom.xml
+++ b/rdf/jena/tdb.storage/pom.xml
@@ -22,20 +22,31 @@
     <parent>
         <artifactId>clerezza</artifactId>
         <groupId>org.apache.clerezza</groupId>
-        <version>0.5</version>
+        <version>7-SNAPSHOT</version>
         <relativePath>../parent</relativePath>
     </parent>
     <groupId>org.apache.clerezza</groupId>
     <artifactId>rdf.jena.tdb.storage</artifactId>
     <packaging>bundle</packaging>
     <version>1.0.0-SNAPSHOT</version>
-    <name>Clerezza - SCB Jena TDB Storage Provider</name>
+    <name>Clerezza - RDF - Jena - TDB Storage Provider</name>
     <description>A Jena TDB based storage provider</description>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.clerezza</groupId>
+                <artifactId>rdf.jena.dependencymanagement</artifactId>
+                <type>pom</type>
+                <version>1.0.0-SNAPSHOT</version>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
     <dependencies>
         <dependency>
             <groupId>org.apache.clerezza</groupId>
             <artifactId>rdf.core</artifactId>
-            <version>0.14</version>
+            <version>1.0.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>junit</groupId>
@@ -45,22 +56,22 @@
         <dependency>
             <groupId>org.apache.clerezza</groupId>
             <artifactId>rdf.ontologies</artifactId>
-            <version>0.12</version>
+            <version>1.0.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.clerezza</groupId>
             <artifactId>rdf.jena.commons</artifactId>
-            <version>0.7</version>
+            <version>1.0.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.clerezza</groupId>
             <artifactId>rdf.jena.storage</artifactId>
-            <version>0.7</version>
+            <version>1.0.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.clerezza</groupId>
             <artifactId>rdf.jena.sparql</artifactId>
-            <version>0.7</version>
+            <version>1.0.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
@@ -101,7 +112,7 @@
             <groupId>org.apache.clerezza</groupId>
             <artifactId>rdf.core.test</artifactId>
             <scope>test</scope>
-            <version>0.15</version>
+            <version>1.0.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
deleted file mode 100644
index a3cdd19..0000000
--- a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.internals;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.concurrent.locks.ReadWriteLock;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
-import org.apache.clerezza.rdf.core.event.FilterTriple;
-import org.apache.clerezza.rdf.core.event.GraphListener;
-import org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider;
-
-/**
- * {@link LockableMGraph} wrapper that uses a single {@link ReadWriteLock} for
- * the Jena TDB {@link SingleTdbDatasetTcProvider#dataset}
- * @author Rupert Westenthaler
- *
- */
-public class DatasetLockedMGraph extends LockableMGraphWrapper {
-
-
-    /**
-     * Constructs a LocalbleMGraph for an MGraph.
-     *
-     * @param providedMGraph a non-lockable mgraph
-     */
-    public DatasetLockedMGraph(final ReadWriteLock lock, final MGraph providedMGraph) {
-        super(providedMGraph, lock);
-    }
-
-    //Maybe overwriting this prevents unnecessary locking
-    /*
-    @Override
-    public Iterator<Triple> filter(NonLiteral subject, UriRef predicate, Resource object) {
-        //users will need to aquire a readlock while iterating
-        return wrapped.filter(subject, predicate, object);
-    }
-    */
-        
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/IriSet.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/IriSet.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/IriSet.java
new file mode 100644
index 0000000..1eb5d55
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/IriSet.java
@@ -0,0 +1,62 @@
+package org.apache.clerezza.rdf.jena.tdb.internals;
+
+import java.util.AbstractSet;
+import java.util.Iterator;
+
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.clerezza.rdf.ontologies.RDF;
+
+/**
+ * Represents a set of uri ref Set<Iri>
+ * @author Minto van der Sluis
+ */
+public class IriSet extends AbstractSet<Iri> {
+    private ModelGraph graphNameIndex;
+    private Iri graphType;
+
+    public IriSet(ModelGraph index, Iri object) {
+        graphNameIndex = index;
+        graphType = object;
+    }
+  
+    @Override
+    public int size() {
+        // TODO: How to get the proper size based on graphType
+        return graphNameIndex.getGraph().size();
+    }
+  
+    @Override
+    public Iterator<Iri> iterator() {
+        final Iterator<Triple> indexIter = graphNameIndex.getGraph().filter( null, RDF.type, graphType );
+        return new Iterator<Iri>() {
+            @Override
+            public boolean hasNext() {
+                return indexIter.hasNext();
+            }
+  
+            @Override
+            public Iri next() {
+                return Iri.class.cast(indexIter.next().getSubject());
+            }
+  
+            @Override
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+        };
+    }
+    
+    @Override
+    public boolean add(Iri o) {
+        throw new UnsupportedOperationException();
+    }
+  
+    @Override
+    public boolean contains(Object o) {
+        if (o instanceof Iri) {
+            return graphNameIndex.getGraph().filter(Iri.class.cast(o), RDF.type, graphType).hasNext();
+        }
+        return false;
+    }
+};    

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
index 7b6421f..6465d86 100644
--- a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
@@ -2,14 +2,13 @@ package org.apache.clerezza.rdf.jena.tdb.internals;
 
 import java.util.concurrent.locks.ReadWriteLock;
 
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
-import org.apache.clerezza.rdf.core.impl.SimpleGraph;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Graph;
+
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.clerezza.rdf.core.impl.util.PrivilegedGraphWrapper;
 import org.apache.clerezza.rdf.core.impl.util.PrivilegedGraphWrapper;
-import org.apache.clerezza.rdf.core.impl.util.PrivilegedMGraphWrapper;
 import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
 import org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider;
 
@@ -17,12 +16,13 @@ import com.hp.hpl.jena.rdf.model.Model;
 import com.hp.hpl.jena.sparql.core.DatasetGraph;
 import com.hp.hpl.jena.sparql.core.Quad;
 import com.hp.hpl.jena.tdb.TDB;
+import org.apache.commons.rdf.impl.utils.simple.SimpleImmutableGraph;
 
 /**
- * Represents the Jena {@link Model} and the Clerezza {@link Graph} or
- * {@link MGraph}. It also provide access to the {@link JenaGraphAdaptor}
- * so that this component can add parsed data to {@link Graph}s created
- * by calls to {@link SingleTdbDatasetTcProvider#createGraph(UriRef, TripleCollection)}.
+ * Represents the Jena {@link Model} and the Clerezza {@link ImmutableGraph} or
+ * {@link Graph}. It also provide access to the {@link JenaGraphAdaptor}
+ * so that this component can add parsed data to {@link ImmutableGraph}s created
+ * by calls to {@link SingleTdbDatasetTcProvider#createGraph(Iri, TripleCollection)}.
  * @author Rupert Westenthaler
  *
  */
@@ -38,16 +38,16 @@ public class ModelGraph {
      */
     private JenaGraphAdaptor jenaAdapter;
     /**
-     * The {@link Graph}(in case of read-only) or {@link MGraph} (if read/write)
+     * The {@link ImmutableGraph}(in case of read-only) or {@link Graph} (if read/write)
      * that can be shared with other components. The instance stored by this
      * variable will use all the required Wrappers such as such as 
-     * {@link LockableMGraphWrapper lockable} and {@link PrivilegedMGraphWrapper
+     * {@link LockableGraphWrapper lockable} and {@link PrivilegedGraphWrapper
      * privileged}.
      */
-    private TripleCollection graph;
+    private Graph graph;
     /**
-     * keeps the state if this represents an {@link Graph} (read-only) or
-     * {@link MGraph}(read/write) ModelGraph.
+     * keeps the state if this represents an {@link ImmutableGraph} (read-only) or
+     * {@link Graph}(read/write) ModelGraph.
      */
     private final boolean readWrite;
     
@@ -71,21 +71,20 @@ public class ModelGraph {
                  * @return
                  */
                 @Override
-                public Graph getGraph() {
-                    return new SimpleGraph(this,true);
+                public ImmutableGraph getImmutableGraph() {
+                    return new SimpleImmutableGraph(this,true);
                 }
             };
-            graph = new PrivilegedGraphWrapper(jenaAdapter.getGraph());
-        } else { //construct an MGraph
-            jenaAdapter = new JenaGraphAdaptor(model.getGraph());
-            this.graph =  new DatasetLockedMGraph(lock,
-                new PrivilegedMGraphWrapper(jenaAdapter));
+            graph = new PrivilegedGraphWrapper(jenaAdapter).getImmutableGraph();
+        } else { //construct an Graph
+            jenaAdapter = new JenaGraphAdaptor(model.getGraph(), lock);
+            this.graph =  new PrivilegedGraphWrapper(jenaAdapter);
         }
     }
     /**
      * The {@link JenaGraphAdaptor}. For internal use only! Do not pass
      * this instance to other components. Use {@link #getGraph()} and
-     * {@link #getMGraph()} instead!
+     * {@link #getGraph()} instead!
      * @return the plain {@link JenaGraphAdaptor}
      */
     public JenaGraphAdaptor getJenaAdapter(){
@@ -96,28 +95,28 @@ public class ModelGraph {
         return readWrite;
     }
     /**
-     * Getter for the {@link MGraph}
-     * @return the {@link MGraph}
+     * Getter for the {@link Graph}
+     * @return the {@link Graph}
      * @throws IllegalStateException if this {@link ModelGraph} is NOT
      * {@link #readWrite}
      */
-    public MGraph getMGraph(){
+    public Graph getGraph(){
         if(!readWrite){
-            throw new IllegalStateException("Unable to return MGraph for read-only models");
+            throw new IllegalStateException("Unable to return Graph for read-only models");
         }
-        return (MGraph)graph;
+        return (Graph)graph;
     }
     /**
-     * Getter for the {@link Graph}
-     * @return the {@link Graph}
+     * Getter for the {@link ImmutableGraph}
+     * @return the {@link ImmutableGraph}
      * @throws IllegalStateException if this {@link ModelGraph} is 
      * {@link #readWrite}
      */
-    public Graph getGraph() {
+    public ImmutableGraph getImmutableGraph() {
         if(readWrite){
-            throw new IllegalStateException("Unable to return Graph for read/write models.");
+            throw new IllegalStateException("Unable to return ImmutableGraph for read/write models.");
         }
-        return (Graph)graph;
+        return (ImmutableGraph)graph;
     }
     /**
      * closes this ModelGraph and frees up all Jena TDB related resources.

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
index ccf3003..39ec2fd 100644
--- a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
@@ -1,6 +1,6 @@
 package org.apache.clerezza.rdf.jena.tdb.internals;
 
-import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.commons.rdf.Iri;
 
 /**
  * Provides static methods in order to represent classes used to
@@ -11,12 +11,12 @@ import org.apache.clerezza.rdf.core.UriRef;
  */
 public class Symbols {
 
-    public static UriRef Index = new UriRef("http://clerezza.apache.org/storage/Index");
+    public static Iri Index = new Iri("http://clerezza.apache.org/storage/Index");
 
-    public static UriRef Default = new UriRef("http://clerezza.apache.org/storage/Default");
+    public static Iri Default = new Iri("http://clerezza.apache.org/storage/Default");
     
-    public static UriRef Graph = new UriRef("http://clerezza.apache.org/storage/Graph");
+    public static Iri ImmutableGraph = new Iri("http://clerezza.apache.org/storage/ImmutableGraph");
 
-    public static UriRef MGraph = new UriRef("http://clerezza.apache.org/storage/MGraph");
+    public static Iri Graph = new Iri("http://clerezza.apache.org/storage/Graph");
 
 }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
deleted file mode 100644
index fb165d0..0000000
--- a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.internals;
-
-import java.util.AbstractSet;
-import java.util.Iterator;
-
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.ontologies.RDF;
-
-/**
- * Represents a set of uri ref Set<UriRef>
- * @author Minto van der Sluis
- */
-public class UriRefSet extends AbstractSet<UriRef> {
-    private ModelGraph graphNameIndex;
-    private UriRef graphType;
-
-    public UriRefSet(ModelGraph index, UriRef object) {
-        graphNameIndex = index;
-        graphType = object;
-    }
-  
-    @Override
-    public int size() {
-        // TODO: How to get the proper size based on graphType
-        return graphNameIndex.getMGraph().size();
-    }
-  
-    @Override
-    public Iterator<UriRef> iterator() {
-        final Iterator<Triple> indexIter = graphNameIndex.getMGraph().filter( null, RDF.type, graphType );
-        return new Iterator<UriRef>() {
-            @Override
-            public boolean hasNext() {
-                return indexIter.hasNext();
-            }
-  
-            @Override
-            public UriRef next() {
-                return UriRef.class.cast(indexIter.next().getSubject());
-            }
-  
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException();
-            }
-        };
-    }
-    
-    @Override
-    public boolean add(UriRef o) {
-        throw new UnsupportedOperationException();
-    }
-  
-    @Override
-    public boolean contains(Object o) {
-        if (o instanceof UriRef) {
-            return graphNameIndex.getMGraph().filter(UriRef.class.cast(o), RDF.type, graphType).hasNext();
-        }
-        return false;
-    }
-};    

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
index c8a7a5f..feb5dcc 100644
--- a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
@@ -3,7 +3,7 @@ package org.apache.clerezza.rdf.jena.tdb.storage;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
-import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.commons.rdf.Graph;
 import org.apache.clerezza.rdf.core.access.QueryableTcProvider;
 import org.apache.clerezza.rdf.core.sparql.query.Query;
 import org.apache.clerezza.rdf.jena.sparql.ResultSetWrapper;
@@ -18,7 +18,7 @@ import com.hp.hpl.jena.query.QueryFactory;
 import com.hp.hpl.jena.update.GraphStore;
 import com.hp.hpl.jena.update.GraphStoreFactory;
 import com.hp.hpl.jena.update.UpdateAction;
-import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.commons.rdf.Iri;
 
 abstract class BaseTdbTcProvider implements QueryableTcProvider{
 
@@ -33,7 +33,7 @@ abstract class BaseTdbTcProvider implements QueryableTcProvider{
 	// ------------------------------------------------------------------------
 
     @Override
-    public Object executeSparqlQuery(final String query, UriRef defaultGraph) {
+    public Object executeSparqlQuery(final String query, Iri defaultGraph) {
 		// Missing permission (java.lang.RuntimePermission getClassLoader)
 		// when calling QueryFactory.create causes ExceptionInInitializerError
 		// to be thrown.
@@ -71,10 +71,10 @@ abstract class BaseTdbTcProvider implements QueryableTcProvider{
 				} catch (QueryExecException e2) {
 					try {
 						return new JenaGraphAdaptor(qexec.execDescribe()
-								.getGraph()).getGraph();
+								.getGraph()).getImmutableGraph();
 					} catch (QueryExecException e3) {
 						return new JenaGraphAdaptor(qexec.execConstruct()
-								.getGraph()).getGraph();
+								.getGraph()).getImmutableGraph();
 					}
 				}
 			}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
index b8df417..8a9d1aa 100644
--- a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
@@ -13,21 +13,21 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
 import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
 import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
 import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
 import org.apache.clerezza.rdf.core.access.QueryableTcProvider;
 import org.apache.clerezza.rdf.core.access.TcProvider;
 import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
 import org.apache.clerezza.rdf.jena.tdb.internals.ModelGraph;
 import org.apache.clerezza.rdf.jena.tdb.internals.Symbols;
-import org.apache.clerezza.rdf.jena.tdb.internals.UriRefSet;
+import org.apache.clerezza.rdf.jena.tdb.internals.IriSet;
 import org.apache.clerezza.rdf.ontologies.RDF;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
@@ -54,15 +54,15 @@ import org.apache.clerezza.rdf.core.access.TcManager;
 /**
  * {@link WeightedTcProvider} implementation for Jena TDB that uses a single
  * {@link TDBFactory#createDataset(String) Dataset} to store all created
- * {@link Graph} and {@link MGraph} instances.<p>
+ * {@link ImmutableGraph} and {@link Graph} instances.<p>
  * The {@link #TDB_DIR} is uses to configure the directory on the disc. It
  * supports property substitution <code>'${property}'</code> based on properties defined
  * in the {@link BundleContext#getProperty(String)} and 
  * {@link System#getProperty(String)}. This is to easily allow configurations
  * such as <code>"${myHome}/myRdfStore"</code><p>
  * The {@link #DEFAULT_GRAPH_NAME} property can be used to define the
- * name of the Graph that exposes the {@link Dataset#getDefaultModel()} as
- * both {@link TcProvider#getGraph(UriRef)} and {@link TcProvider#getMGraph(UriRef)}.
+ * name of the ImmutableGraph that exposes the {@link Dataset#getDefaultModel()} as
+ * both {@link TcProvider#getGraph(Iri)} and {@link TcProvider#getGraph(Iri)}.
  * This easily allows to access the union graph of the Jena TDB dataset.<p>
  * This {@link TcProvider} {@link ConfigurationPolicy#REQUIRE requires} an
  * configuration and uses the {@link Component#configurationFactory() 
@@ -109,10 +109,10 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
     private SyncThread syncThread;
 
     private final ReadWriteLock datasetLock = new ReentrantReadWriteLock();;
-    private UriRef defaultGraphName;
+    private Iri defaultGraphName;
 
     // Ensure that models not yet garbage collected get properly synced.
-    private final ConcurrentMap<UriRef, ModelGraph> syncModels = new MapMaker().weakValues().makeMap();
+    private final ConcurrentMap<Iri, ModelGraph> syncModels = new MapMaker().weakValues().makeMap();
     
     /**
      * This background thread ensures that changes to {@link Model}s are
@@ -167,8 +167,8 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
      * <li> {@link #TDB_DIR} (required): The directory used by Jena TDB. Property
      * substitution "${property-name}" with {@link System#getProperties()} is
      * supported.
-     * <li> {@link #DEFAULT_GRAPH_NAME}: The name ({@link UriRef}) of the
-     * {@link Graph} that exports the union graph. This graph allows to query
+     * <li> {@link #DEFAULT_GRAPH_NAME}: The name ({@link Iri}) of the
+     * {@link ImmutableGraph} that exports the union graph. This graph allows to query
      * triples in any named model managed by this {@link TcProvider}.
      * <li> {@link #SYNC_INTERVAL}: The sync interval that
      * is used to write changes in the graph to the file system. If missing
@@ -257,7 +257,7 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
         if(value != null && !value.toString().isEmpty()){
             try {
                 new URI(value.toString());
-                defaultGraphName = new UriRef(value.toString());
+                defaultGraphName = new Iri(value.toString());
             } catch (URISyntaxException e) {
                 throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The parsed name '"
                         + value + "'for the default graph (union over all "
@@ -291,10 +291,10 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
         if (defaultGraphName != null) {
           if (isExistingGraphName(defaultGraphName)) {
             throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The configured default graph name '"
-                +defaultGraphName+"' is already used as a Graph or MGraph name!");
+                +defaultGraphName+"' is already used as a ImmutableGraph or Graph name!");
           } else {
             addToIndex( defaultGraphName, Symbols.Default );
-            addToIndex( defaultGraphName, Symbols.Graph );
+            addToIndex( defaultGraphName, Symbols.ImmutableGraph );
           }
         }
 
@@ -357,18 +357,18 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
     /**
      * Internal method used to retrieve an existing Jena {@link ModelGraph} 
      * instance from {@link #syncModels} or initializes a new Jena TDB {@link Model}
-     * and Clerezza {@link Graph}s/{@link MGraph}s.
-     * @param name the name of the Graph to initialize/create
-     * @param readWrite if <code>true</code> a {@link MGraph} is initialized.
-     * Otherwise a {@link Graph} is created.
+     * and Clerezza {@link ImmutableGraph}s/{@link Graph}s.
+     * @param name the name of the ImmutableGraph to initialize/create
+     * @param readWrite if <code>true</code> a {@link Graph} is initialized.
+     * Otherwise a {@link ImmutableGraph} is created.
      * @param create if this method is allowed to create an new {@link Model} or
      * if an already existing model is initialized.
-     * @return the initialized {@link Model} and @link Graph} or {@link MGraph}.
+     * @return the initialized {@link Model} and @link ImmutableGraph} or {@link Graph}.
      * The returned instance will be also cached in {@link #syncModels}. 
      * @throws NoSuchEntityException If <code>create == false</code> and no
      * {@link Model} for the parsed <code>name</code> exists.
      */
-    private ModelGraph getModelGraph(UriRef name, boolean readWrite,boolean create) throws NoSuchEntityException {
+    private ModelGraph getModelGraph(Iri name, boolean readWrite,boolean create) throws NoSuchEntityException {
         ModelGraph modelGraph = null;
         datasetLock.readLock().lock();
         try {
@@ -396,17 +396,17 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
     
     /*
      * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#getGraph(org.apache.clerezza.rdf.core.UriRef)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#getGraph(org.apache.commons.rdf.Iri)
      */
     @Override
-    public Graph getGraph(UriRef name) throws NoSuchEntityException {
+    public ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException {
         if(name == null){
-            throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
+            throw new IllegalArgumentException("The parsed ImmutableGraph Iri MUST NOT be NULL!");
         }
         datasetLock.readLock().lock();
         try {
-            if (isExistingGraphName(name, Symbols.Graph) || name.equals(defaultGraphName)){
-                return getModelGraph(name,false,false).getGraph();
+            if (isExistingGraphName(name, Symbols.ImmutableGraph) || name.equals(defaultGraphName)){
+                return getModelGraph(name,false,false).getImmutableGraph();
             } else {
                 throw new NoSuchEntityException(name);
             }
@@ -417,17 +417,17 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
     
     /*
      * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#getMGraph(org.apache.clerezza.rdf.core.UriRef)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#getGraph(org.apache.commons.rdf.Iri)
      */
     @Override
-    public MGraph getMGraph(UriRef name) throws NoSuchEntityException {
+    public Graph getMGraph(Iri name) throws NoSuchEntityException {
         if(name == null){
-            throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
+            throw new IllegalArgumentException("The parsed ImmutableGraph Iri MUST NOT be NULL!");
         }
         datasetLock.readLock().lock();
         try {
-            if(isExistingGraphName(name, Symbols.MGraph)){
-                return getModelGraph(name,true,false).getMGraph();
+            if(isExistingGraphName(name, Symbols.Graph)){
+                return getModelGraph(name,true,false).getGraph();
             } else {
                 throw new NoSuchEntityException(name);
             }
@@ -438,19 +438,19 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
     
     /*
      * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#getTriples(org.apache.clerezza.rdf.core.UriRef)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#getTriples(org.apache.commons.rdf.Iri)
      */
     @Override
-    public TripleCollection getTriples(UriRef name) throws NoSuchEntityException {
+    public Graph getGraph(Iri name) throws NoSuchEntityException {
         if(name == null){
-            throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
+            throw new IllegalArgumentException("The parsed ImmutableGraph Iri MUST NOT be NULL!");
         }
         datasetLock.readLock().lock();
         try {
-            if(isExistingGraphName(name, Symbols.Graph) || name.equals(defaultGraphName)){
-                return getGraph(name);
-            } else if(isExistingGraphName(name, Symbols.MGraph)){
+            if(isExistingGraphName(name, Symbols.ImmutableGraph) || name.equals(defaultGraphName)){
                 return getMGraph(name);
+            } else if(isExistingGraphName(name, Symbols.Graph)){
+                return getImmutableGraph(name);
             } else {
                 throw new NoSuchEntityException(name);
             }
@@ -464,10 +464,10 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
      * @see org.apache.clerezza.rdf.core.access.TcProvider#listGraphs()
      */
     @Override
-    public Set<UriRef> listGraphs() {
+    public Set<Iri> listImmutableGraphs() {
         datasetLock.readLock().lock();
         try {
-            return new HashSet(new UriRefSet( graphNameIndex, Symbols.Graph ));
+            return new HashSet(new IriSet( graphNameIndex, Symbols.ImmutableGraph ));
         } finally {
             datasetLock.readLock().unlock();
         }
@@ -475,13 +475,13 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
 
     /*
      * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#listMGraphs()
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#listGraphs()
      */
     @Override
-    public Set<UriRef> listMGraphs() {
+    public Set<Iri> listMGraphs() {
         datasetLock.readLock().lock();
         try {
-            return  new HashSet(new UriRefSet( graphNameIndex, Symbols.MGraph ));
+            return  new HashSet(new IriSet( graphNameIndex, Symbols.Graph ));
         } finally {
             datasetLock.readLock().unlock();
         }
@@ -489,13 +489,13 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
 
     /*
      * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#listTripleCollections()
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#listGraphs()
      */
     @Override
-    public Set<UriRef> listTripleCollections() {
+    public Set<Iri> listGraphs() {
         datasetLock.readLock().lock();
         try {
-            return  new HashSet(new UriRefSet( graphNameIndex, null ));
+            return  new HashSet(new IriSet( graphNameIndex, null ));
         } finally {
             datasetLock.readLock().unlock();
         }
@@ -503,10 +503,10 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
 
     /*
      * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#createMGraph(org.apache.clerezza.rdf.core.UriRef)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#createGraph(org.apache.commons.rdf.Iri)
      */
     @Override
-    public MGraph createMGraph(UriRef name) throws UnsupportedOperationException,
+    public Graph createGraph(Iri name) throws UnsupportedOperationException,
                                            EntityAlreadyExistsException {
         if(name == null){
             throw new IllegalArgumentException("The parsed MGrpah name MUST NOT be NULL!");
@@ -516,8 +516,8 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
             if(isExistingGraphName(name)){
                 throw new EntityAlreadyExistsException(name);
             }
-            MGraph graph = getModelGraph(name,true,true).getMGraph();
-            addToIndex( name, Symbols.MGraph);
+            Graph graph = getModelGraph(name,true,true).getGraph();
+            addToIndex( name, Symbols.Graph);
             return graph;
         } finally {
             datasetLock.writeLock().unlock();
@@ -526,10 +526,10 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
     
     /*
      * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#createGraph(org.apache.clerezza.rdf.core.UriRef, org.apache.clerezza.rdf.core.TripleCollection)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#createGraph(org.apache.commons.rdf.Iri, org.apache.commons.rdf.Graph)
      */
     @Override
-    public Graph createGraph(UriRef name, TripleCollection triples) throws UnsupportedOperationException,
+    public ImmutableGraph createImmutableGraph(Iri name, Graph triples) throws UnsupportedOperationException,
                                                                    EntityAlreadyExistsException {
         if(name == null){
             throw new IllegalArgumentException("The parsed Grpah name MUST NOT be NULL!");
@@ -541,7 +541,7 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
                 throw new EntityAlreadyExistsException(name);
             }
             mg = getModelGraph(name,false,true);
-            addToIndex( name, Symbols.Graph);
+            addToIndex( name, Symbols.ImmutableGraph);
             
             //add the parsed data!
             if(triples != null) { //load the initial and final set of triples
@@ -551,15 +551,15 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
         } finally {
             datasetLock.writeLock().unlock();
         }
-        return mg.getGraph();
+        return mg.getImmutableGraph();
     }
     
     /*
      * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#deleteTripleCollection(org.apache.clerezza.rdf.core.UriRef)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#deleteGraph(org.apache.commons.rdf.Iri)
      */
     @Override
-    public void deleteTripleCollection(UriRef name) throws UnsupportedOperationException,
+    public void deleteGraph(Iri name) throws UnsupportedOperationException,
                                                    NoSuchEntityException,
                                                    EntityUndeletableException {
         if(name == null){
@@ -567,14 +567,14 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
         }
         datasetLock.writeLock().lock();
         try {
-            if(isExistingGraphName(name,Symbols.MGraph)){
+            if(isExistingGraphName(name,Symbols.Graph)){
                 ModelGraph mg = getModelGraph(name, true, false);
                 mg.delete();
-                removeFromIndex( name, Symbols.MGraph );
-            } else if(isExistingGraphName(name,Symbols.Graph)){
+                removeFromIndex( name, Symbols.Graph );
+            } else if(isExistingGraphName(name,Symbols.ImmutableGraph)){
                 ModelGraph mg = getModelGraph(name, false, false);
                 mg.delete();
-                removeFromIndex( name, Symbols.Graph );
+                removeFromIndex( name, Symbols.ImmutableGraph );
             } else if (name.equals(defaultGraphName)){
                 throw new EntityUndeletableException(defaultGraphName);
             }
@@ -587,17 +587,17 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
     
     /*
      * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#getNames(org.apache.clerezza.rdf.core.Graph)
+     * @see org.apache.clerezza.rdf.core.access.TcProvider#getNames(org.apache.commons.rdf.ImmutableGraph)
      */
     @Override
-    public Set<UriRef> getNames(Graph graph) {
+    public Set<Iri> getNames(ImmutableGraph graph) {
         //TODO: this method would require to compare the triples within the graph
-        //      because an equals check will not work with BNodes. 
-        Set<UriRef> graphNames = new HashSet<UriRef>();
-        for( Iterator<Triple> iterator = graphNameIndex.getMGraph().iterator(); iterator.hasNext(); ) {
+        //      because an equals check will not work with BlankNodes. 
+        Set<Iri> graphNames = new HashSet<Iri>();
+        for( Iterator<Triple> iterator = graphNameIndex.getGraph().iterator(); iterator.hasNext(); ) {
             Triple triple = iterator.next();
-            UriRef graphName = new UriRef(triple.getSubject().toString());
-            Graph currentGraph = getModelGraph(graphName, false, false).getGraph();
+            Iri graphName = new Iri(triple.getSubject().toString());
+            ImmutableGraph currentGraph = getModelGraph(graphName, false, false).getImmutableGraph();
             if(graph.equals(currentGraph)){
                 graphNames.add(graphName);
             }
@@ -666,8 +666,8 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
      * @param graphType the resource type
      * @return true if a resource with the given name and type already exists, false otherwise.
      */
-    private boolean isExistingGraphName(UriRef graphName, UriRef graphType) {
-        return graphNameIndex.getMGraph().filter(graphName, RDF.type, graphType).hasNext();
+    private boolean isExistingGraphName(Iri graphName, Iri graphType) {
+        return graphNameIndex.getGraph().filter(graphName, RDF.type, graphType).hasNext();
     }
 
     /**
@@ -675,7 +675,7 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
      * @param graphName the graph name
      * @return true if a graph or mgraph with the given name already exists, false otherwise.
      */
-    private boolean isExistingGraphName(UriRef graphName) {
+    private boolean isExistingGraphName(Iri graphName) {
         return isExistingGraphName(graphName, null);
     }
     
@@ -684,8 +684,8 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
      * @param graphName name of the graph
      * @param graphType resourcetype for the graph to add.
      */
-    private void addToIndex(UriRef graphName, UriRef graphType) {
-        graphNameIndex.getMGraph().add(new TripleImpl(graphName, RDF.type, graphType));
+    private void addToIndex(Iri graphName, Iri graphType) {
+        graphNameIndex.getGraph().add(new TripleImpl(graphName, RDF.type, graphType));
         graphNameIndex.sync();
     }
     
@@ -694,8 +694,8 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
      * @param graphName name of the graph to remove
      * @param graphType resource type of the graph to remove.
      */
-    private void removeFromIndex(UriRef graphName, UriRef graphType) {
-        MGraph index = graphNameIndex.getMGraph();
+    private void removeFromIndex(Iri graphName, Iri graphType) {
+        Graph index = graphNameIndex.getGraph();
         Iterator<Triple> triplesToRemove = index.filter(graphName, RDF.type, graphType);
         for( ; triplesToRemove.hasNext(); ) {
             triplesToRemove.next();
@@ -705,12 +705,12 @@ public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements Wei
     }
     
     private void removeDefaultGraphFromIndex() {
-      MGraph index = graphNameIndex.getMGraph();
+      Graph index = graphNameIndex.getGraph();
       Iterator<Triple> triplesToRemove = index.filter(null, RDF.type, Symbols.Default);
       for( ; triplesToRemove.hasNext(); ) {
           Triple triple = triplesToRemove.next();
           triplesToRemove.remove();
-          removeFromIndex( UriRef.class.cast(triple.getSubject()), Symbols.Graph );
+          removeFromIndex( Iri.class.cast(triple.getSubject()), Symbols.ImmutableGraph );
       }
       graphNameIndex.sync();
     }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
index f8924fc..d50ef64 100644
--- a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
@@ -38,19 +38,16 @@ import java.util.logging.Level;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
 import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
 import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
 import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
 import org.apache.clerezza.rdf.core.access.TcManager;
 import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.util.PrivilegedMGraphWrapper;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.clerezza.rdf.core.impl.util.PrivilegedGraphWrapper;
 import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Properties;
@@ -89,8 +86,8 @@ public class TdbTcProvider implements WeightedTcProvider {
      */
     private static final String DATA_PATH_NAME = "tdb-data/";
     private String dataPathString = DATA_PATH_NAME;
-    private Map<UriRef, LockableMGraph> mGraphMap = new HashMap<UriRef, LockableMGraph>();
-    private Map<UriRef, Graph> graphMap = new HashMap<UriRef, Graph>();
+    private Map<Iri, Graph> mGraphMap = new HashMap<Iri, Graph>();
+    private Map<Iri, ImmutableGraph> graphMap = new HashMap<Iri, ImmutableGraph>();
     private Map<File, com.hp.hpl.jena.graph.Graph> dir2JenaGraphMap = new HashMap<File, com.hp.hpl.jena.graph.Graph>();
     private Map<File, Lock> dir2Lock = new HashMap<File, Lock>();
     private final Map<File, Dataset> dir2Dataset = new HashMap<File, Dataset>();
@@ -126,8 +123,8 @@ public class TdbTcProvider implements WeightedTcProvider {
 
     TdbTcProvider(File directory) {
         dataPathString = directory.getAbsolutePath();
-        loadMGraphs();
         loadGraphs();
+        loadImmutableGraphs();
     }
 
     public void activate(ComponentContext cCtx) {
@@ -138,8 +135,8 @@ public class TdbTcProvider implements WeightedTcProvider {
                     getDataFile(DATA_PATH_NAME).getAbsolutePath();
             syncInterval = Integer.parseInt(cCtx.getProperties().get(SYNC_INTERVAL).toString());
         }
-        loadMGraphs();
         loadGraphs();
+        loadImmutableGraphs();
         syncThread = new SyncThread();
         syncThread.start();
     }
@@ -163,7 +160,7 @@ public class TdbTcProvider implements WeightedTcProvider {
     }
 
     @Override
-    public Graph getGraph(UriRef name) throws NoSuchEntityException {
+    public ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException {
         if (!graphMap.containsKey(name)) {
             throw new NoSuchEntityException(name);
         }
@@ -171,7 +168,7 @@ public class TdbTcProvider implements WeightedTcProvider {
     }
 
     @Override
-    public synchronized MGraph getMGraph(UriRef name) throws NoSuchEntityException {
+    public synchronized Graph getMGraph(Iri name) throws NoSuchEntityException {
         if (!mGraphMap.containsKey(name)) {
             throw new NoSuchEntityException(name);
         }
@@ -179,18 +176,18 @@ public class TdbTcProvider implements WeightedTcProvider {
     }
 
     @Override
-    public TripleCollection getTriples(UriRef name) throws NoSuchEntityException {
+    public Graph getGraph(Iri name) throws NoSuchEntityException {
         try {
             return getMGraph(name);
         } catch (NoSuchEntityException e) {
-            return getGraph(name);
+            return getImmutableGraph(name);
         }
     }
 
     @Override
-    public synchronized MGraph createMGraph(UriRef name)
+    public synchronized Graph createGraph(Iri name)
             throws UnsupportedOperationException, EntityAlreadyExistsException {
-        File tcDir = getMGraphDir(name);
+        File tcDir = getGraphDir(name);
         if (tcDir.exists()) {
             throw new EntityAlreadyExistsException(name);
         }
@@ -201,22 +198,22 @@ public class TdbTcProvider implements WeightedTcProvider {
         } catch (IOException ex) {
             throw new RuntimeException(ex);
         }
-        LockableMGraph result = new LockableMGraphWrapper(getMGraph(tcDir));
+        Graph result = getGraph(tcDir);
         dir2Lock.put(tcDir, result.getLock().writeLock());
         mGraphMap.put(name, result);
         return result;
     }
 
     @Override
-    public Graph createGraph(UriRef name, TripleCollection triples)
+    public ImmutableGraph createImmutableGraph(Iri name, Graph triples)
             throws UnsupportedOperationException, EntityAlreadyExistsException {
-        File tcDir = getGraphDir(name);
+        File tcDir = getImmutableGraphDir(name);
         if (tcDir.exists()) {
             throw new EntityAlreadyExistsException(name);
         }
 
         if (triples == null) {
-            triples = new SimpleMGraph();
+            triples = new SimpleGraph();
         }
         tcDir.mkdirs();
         File otimizationIndicator = new File(tcDir, "fixed.opt");
@@ -225,24 +222,24 @@ public class TdbTcProvider implements WeightedTcProvider {
         } catch (IOException ex) {
             throw new RuntimeException(ex);
         }
-        MGraph mGraph = getMGraph(tcDir);
+        Graph mGraph = getGraph(tcDir);
         mGraph.addAll(triples);
-        Graph result = mGraph.getGraph();
+        ImmutableGraph result = mGraph.getImmutableGraph();
         TDB.sync(dir2Dataset.get(tcDir));
         graphMap.put(name, result);
         return result;
     }
 
     @Override
-    public void deleteTripleCollection(UriRef name)
+    public void deleteGraph(Iri name)
             throws UnsupportedOperationException, NoSuchEntityException,
             EntityUndeletableException {
         syncWithFileSystem();
-        if (deleteTcDir(getGraphDir(name))) {
+        if (deleteTcDir(getImmutableGraphDir(name))) {
             graphMap.remove(name);
             return;
         }
-        if (deleteTcDir(getMGraphDir(name))) {
+        if (deleteTcDir(getGraphDir(name))) {
             mGraphMap.remove(name);
             return;
         }
@@ -312,11 +309,11 @@ public class TdbTcProvider implements WeightedTcProvider {
     }
 
     @Override
-    public Set<UriRef> getNames(Graph graph) {
+    public Set<Iri> getNames(ImmutableGraph graph) {
         //this could be done more efficiently with an index, could be done with
         //a MultiBidiMap (BidiMap allowing multiple keys for the same value)
-        Set<UriRef> result = new HashSet<UriRef>();
-        for (UriRef name : listGraphs()) {
+        Set<Iri> result = new HashSet<Iri>();
+        for (Iri name : listGraphs()) {
             if (getGraph(name).equals(graph)) {
                 result.add(name);
             }
@@ -325,33 +322,33 @@ public class TdbTcProvider implements WeightedTcProvider {
     }
 
     @Override
-    public Set<UriRef> listTripleCollections() {
-        Set<UriRef> result = new HashSet<UriRef>();
+    public Set<Iri> listGraphs() {
+        Set<Iri> result = new HashSet<Iri>();
+        result.addAll(listGraphs());
         result.addAll(listGraphs());
-        result.addAll(listMGraphs());
         return result;
     }
 
     @Override
-    public Set<UriRef> listGraphs() {
+    public Set<Iri> listMGraphs() {
         return graphMap.keySet();
     }
 
     @Override
-    public Set<UriRef> listMGraphs() {
+    public Set<Iri> listImmutableGraphs() {
         return mGraphMap.keySet();
     }
 
-    private Graph getGraph(File tcDir) {
-        return getMGraph(tcDir).getGraph();
+    private ImmutableGraph getImmutableGraph(File tcDir) {
+        return getGraph(tcDir).getImmutableGraph();
     }
 
-    private File getGraphDir(UriRef name) {
+    private File getImmutableGraphDir(Iri name) {
         File base = new File(dataPathString);
         return getTcDir(new File(base, "graph"), name);
     }
 
-    private MGraph getMGraph(File tcDir) {
+    private Graph getGraph(File tcDir) {
         Dataset dataset = TDBFactory.createDataset(tcDir.getAbsolutePath());
         Model model = dataset.getDefaultModel();
         //Model model = TDBFactory.createModel(tcDir.getAbsolutePath());
@@ -361,15 +358,15 @@ public class TdbTcProvider implements WeightedTcProvider {
         synchronized (dir2Dataset) {
             dir2Dataset.put(tcDir, dataset);
         }
-        return new PrivilegedMGraphWrapper(new JenaGraphAdaptor(jenaGraph));
+        return new PrivilegedGraphWrapper(new JenaGraphAdaptor(jenaGraph));
     }
 
-    private File getMGraphDir(UriRef name) {
+    private File getGraphDir(Iri name) {
         File base = new File(dataPathString);
         return getTcDir(new File(base, "mgraph"), name);
     }
 
-    private File getTcDir(File directory, UriRef name) {
+    private File getTcDir(File directory, Iri name) {
         try {
             String subDirName = URLEncoder.encode(name.getUnicodeString(), "utf-8");
             return new File(directory, subDirName);
@@ -378,14 +375,14 @@ public class TdbTcProvider implements WeightedTcProvider {
         }
     }
 
-    private void loadGraphs() {
+    private void loadImmutableGraphs() {
         File graphsDir = new File(new File(dataPathString), "graph");
         if (graphsDir.exists()) {
             for (String graphDirName : graphsDir.list()) {
                 try {
-                    UriRef uri = new UriRef(URLDecoder.decode(graphDirName, "utf-8"));
+                    Iri uri = new Iri(URLDecoder.decode(graphDirName, "utf-8"));
                     log.info("loading: " + graphDirName);
-                    graphMap.put(uri, getGraph(new File(graphsDir, graphDirName)));
+                    graphMap.put(uri, getImmutableGraph(new File(graphsDir, graphDirName)));
                 } catch (UnsupportedEncodingException ex) {
                     throw new RuntimeException("utf-8 not supported", ex);
                 } catch (Exception e) {
@@ -395,17 +392,17 @@ public class TdbTcProvider implements WeightedTcProvider {
         }
     }
 
-    private void loadMGraphs() {
+    private void loadGraphs() {
         File mGraphsDir = new File(new File(dataPathString), "mgraph");
         if (mGraphsDir.exists()) {
             for (String mGraphDirName : mGraphsDir.list()) {
                 try {
-                    UriRef uri = new UriRef(URLDecoder.decode(mGraphDirName, "utf-8"));
+                    Iri uri = new Iri(URLDecoder.decode(mGraphDirName, "utf-8"));
                     log.info("loading: " + mGraphDirName);
                     final File tcDir = new File(mGraphsDir, mGraphDirName);
-                    final LockableMGraphWrapper lockableMGraph = new LockableMGraphWrapper(getMGraph(tcDir));
-                    mGraphMap.put(uri, lockableMGraph);
-                    dir2Lock.put(tcDir, lockableMGraph.getLock().writeLock());
+                    final Graph lockableGraph = getGraph(tcDir);
+                    mGraphMap.put(uri, lockableGraph);
+                    dir2Lock.put(tcDir, lockableGraph.getLock().writeLock());
                 } catch (UnsupportedEncodingException ex) {
                     throw new RuntimeException("utf-8 not supported", ex);
                 } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
index ac0dc89..d08ce42 100644
--- a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
@@ -33,14 +33,13 @@ import java.util.Random;
 import java.util.Set;
 
 
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
@@ -69,7 +68,7 @@ public class MultiThreadedSingleTdbDatasetTest {
     private static final int DELAY = 15;
     
     
-    protected final List<MGraph> mGraphs = new ArrayList<MGraph>();
+    protected final List<Graph> mGraphs = new ArrayList<Graph>();
     protected final List<Set<Triple>> testTriplesList = new ArrayList<Set<Triple>>();
     private Random random = new Random();
 
@@ -94,7 +93,7 @@ public class MultiThreadedSingleTdbDatasetTest {
                 synchronized (random) {
                     r = random.nextFloat();
                 }
-                MGraph graph;
+                Graph graph;
                 Set<Triple> testTriples;
                 if(r > 0.995){
                     int num;
@@ -102,7 +101,7 @@ public class MultiThreadedSingleTdbDatasetTest {
                         num = graphNum[0];
                         graphNum[0]++;
                     }
-                    graph = provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+num));
+                    graph = provider.createGraph(new Iri(TEST_GRAPH_URI_PREFIX+num));
                     log.info(" ... creating the {}. Grpah", num+1);
                     testTriples = new HashSet<Triple>();
                     synchronized (mGraphs) {
@@ -117,7 +116,7 @@ public class MultiThreadedSingleTdbDatasetTest {
                     }
                 }
                 Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
-                Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
+                Triple triple = new TripleImpl(new BlankNode(), new Iri("http://example.com/property"), randomLiteral);
                 graph.add(triple);
                 addedTripleCount++;
                 if ((addedTripleCount % 100) == 0) {
@@ -132,7 +131,7 @@ public class MultiThreadedSingleTdbDatasetTest {
 
     }
     /**
-     * Iterates over max. the first 10 triples of a Graph
+     * Iterates over max. the first 10 triples of a ImmutableGraph
      * while acquiring a read lock on the graph.
      * @author westei
      *
@@ -158,9 +157,9 @@ public class MultiThreadedSingleTdbDatasetTest {
                     r = random.nextFloat();
                 }
                 int num = Math.round(r*(float)(mGraphs.size()-1));
-                LockableMGraph graph;
+                Graph graph;
                 synchronized (mGraphs) {
-                    graph = (LockableMGraph)mGraphs.get(num);
+                    graph = mGraphs.get(num);
                 }
                 int elem = 0;
                 graph.getLock().readLock().lock();
@@ -202,10 +201,10 @@ public class MultiThreadedSingleTdbDatasetTest {
     }
     @Before
     public void createGraphs(){
-        mGraphs.add(provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+graphNum[0])));
+        mGraphs.add(provider.createGraph(new Iri(TEST_GRAPH_URI_PREFIX+graphNum[0])));
         testTriplesList.add(new HashSet<Triple>());
         graphNum[0]++;
-        mGraphs.add(provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+graphNum[0])));
+        mGraphs.add(provider.createGraph(new Iri(TEST_GRAPH_URI_PREFIX+graphNum[0])));
         testTriplesList.add(new HashSet<Triple>());
         graphNum[0]++;
     }
@@ -239,7 +238,7 @@ public class MultiThreadedSingleTdbDatasetTest {
         int graphTriples = 0;
         log.info("Test created {} graphs with {} triples", mGraphs.size(), addedTriples);
         for(int i = 0;i < mGraphs.size(); i++){
-            MGraph graph = mGraphs.get(i);
+            Graph graph = mGraphs.get(i);
             graphTriples += graph.size();
             log.info("  > Grpah {}: {} triples",i,graph.size());
             for (Triple testTriple : testTriplesList.get(i)) {

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
index 91791c3..88a6cec 100644
--- a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
@@ -28,14 +28,14 @@ import java.util.HashSet;
 import java.util.Set;
 
 
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
 import org.apache.felix.scr.annotations.Activate;
 import org.junit.Assert;
 import org.junit.Before;
@@ -57,7 +57,7 @@ public class MultiThreadedTest {
     private static final int DELAY = 15;
     
     
-    private MGraph mGraph;
+    private Graph mGraph;
     private Set<Triple> testTriples = Collections.synchronizedSet(new HashSet<Triple>()); 
 
     class TestThread extends Thread {
@@ -81,7 +81,7 @@ public class MultiThreadedTest {
             while (!stopRequested) {
                 try {
                     Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
-                    Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
+                    Triple triple = new TripleImpl(new BlankNode(), new Iri("http://example.com/property"), randomLiteral);
                     mGraph.add(triple);
                     addedTripleCount++;
                     if ((addedTripleCount % 100) == 0) {
@@ -104,14 +104,14 @@ public class MultiThreadedTest {
     @Before
     public void setUp() throws IOException {
         File tempFile;
-        UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
+        Iri MGRAPHNAME = new Iri("http://text.example.org/");
         TdbTcProvider tdbTcProvider;
         tempFile = File.createTempFile("tdbtest", null);
         tempFile.delete();
         tempFile.mkdirs();
         tdbTcProvider = new TdbTcProvider(tempFile);
         tdbTcProvider.activate(null);
-        mGraph = tdbTcProvider.createMGraph(MGRAPHNAME);
+        mGraph = tdbTcProvider.createGraph(MGRAPHNAME);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
index 76505b3..2554225 100644
--- a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
@@ -31,15 +31,15 @@ import java.util.Hashtable;
 import java.util.Set;
 
 
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
 import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
 import org.apache.felix.scr.annotations.Activate;
 import org.junit.Assert;
 import org.junit.Before;
@@ -62,7 +62,7 @@ public class MultiThreadedTestSingleTdb {
     private static final int DELAY = 15;
     
     
-    private MGraph mGraph;
+    private Graph mGraph;
     private Set<Triple> testTriples = Collections.synchronizedSet(new HashSet<Triple>()); 
 
     class TestThread extends Thread {
@@ -86,7 +86,7 @@ public class MultiThreadedTestSingleTdb {
             while (!stopRequested) {
                 try {
                     Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
-                    Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
+                    Triple triple = new TripleImpl(new BlankNode(), new Iri("http://example.com/property"), randomLiteral);
                     mGraph.add(triple);
                     addedTripleCount++;
                     if ((addedTripleCount % 100) == 0) {
@@ -109,7 +109,7 @@ public class MultiThreadedTestSingleTdb {
     @Before
     public void setUp() throws IOException, ConfigurationException {
         File tempFile;
-        UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
+        Iri MGRAPHNAME = new Iri("http://text.example.org/");
         TcProvider tdbTcProvider;
         tempFile = File.createTempFile("tdbtest", null);
         tempFile.delete();
@@ -118,7 +118,7 @@ public class MultiThreadedTestSingleTdb {
         dict.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
         tdbTcProvider = new SingleTdbDatasetTcProvider(dict);
         //tdbTcProvider.activate(null);
-        mGraph = tdbTcProvider.createMGraph(MGRAPHNAME);
+        mGraph = tdbTcProvider.createGraph(MGRAPHNAME);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8a337849/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetGraphTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetGraphTest.java
new file mode 100644
index 0000000..30451f3
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetGraphTest.java
@@ -0,0 +1,56 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.clerezza.rdf.core.test.GraphTest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.osgi.service.cm.ConfigurationException;
+
+public class SingleTdbDatasetGraphTest extends GraphTest {
+
+    private static final String MGRAPHNAME_PREFIX = "http://text.example.org/testGraph";
+    private static Iri UNION_GRAPH_NAME = new Iri("http://www.example.org/unionGraph");
+    private static int testGraphCounter = 0;
+
+    private static File tempFile;
+    private static Dictionary<String,Object> config;
+    private static SingleTdbDatasetTcProvider provider;
+
+    @BeforeClass
+    public static void setup() throws IOException, ConfigurationException {
+        tempFile = File.createTempFile("tdbdatasettest", null);
+        tempFile.delete();
+        tempFile.mkdirs();
+        config = new Hashtable<String,Object>();
+        config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
+        config.put(SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME, UNION_GRAPH_NAME.getUnicodeString());
+        provider = new SingleTdbDatasetTcProvider(config);
+    }
+    
+    @AfterClass
+    public static void cleanUpDirectory() throws IOException {
+        for(int i = 0; i < testGraphCounter;i++){
+            provider.deleteGraph(new Iri(MGRAPHNAME_PREFIX+i));
+        }
+        provider.deactivate(null);
+        try {
+            TdbTcProvider.delete(tempFile);
+        } catch (IOException e) {
+            System.err.println("Couldn't remove "+tempFile);
+        }
+    }
+
+    @Override
+    protected Graph getEmptyGraph() {
+        Graph graph = provider.createGraph(new Iri(MGRAPHNAME_PREFIX+testGraphCounter));
+        testGraphCounter++;
+        return graph;
+    }
+
+}


[05/14] clerezza git commit: CLEREZZA-966: moved rdf.utils into the hierarchy

Posted by re...@apache.org.
CLEREZZA-966: moved rdf.utils into the hierarchy

Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/74f5fdb3
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/74f5fdb3
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/74f5fdb3

Branch: refs/heads/rdf-commons
Commit: 74f5fdb34ab823b7fe0f6f733499b766e60bf68e
Parents: ed16bac
Author: Reto Gmuer <re...@apache.org>
Authored: Sun Mar 22 17:38:06 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Sun Mar 22 17:38:06 2015 +0000

----------------------------------------------------------------------
 rdf.utils/LICENSE                               | 201 ------
 rdf.utils/pom.xml                               |  69 --
 .../apache/clerezza/rdf/utils/GraphNode.java    | 722 -------------------
 .../apache/clerezza/rdf/utils/GraphUtils.java   | 163 -----
 .../org/apache/clerezza/rdf/utils/IriUtil.java  |  63 --
 .../org/apache/clerezza/rdf/utils/RdfList.java  | 358 ---------
 .../clerezza/rdf/utils/SeeAlsoExpander.java     | 113 ---
 .../org/apache/clerezza/rdf/utils/Smusher.java  |  61 --
 .../apache/clerezza/rdf/utils/UnionGraph.java   | 286 --------
 .../clerezza/rdf/utils/UnionWatchableGraph.java |  54 --
 .../clerezza/rdf/utils/UriMutatingGraph.java    | 223 ------
 .../graphnodeprovider/GraphNodeProvider.java    |  51 --
 .../rdf/utils/smushing/BaseSmusher.java         | 135 ----
 .../clerezza/rdf/utils/smushing/IfpSmusher.java | 174 -----
 .../rdf/utils/smushing/SameAsSmusher.java       | 113 ---
 .../clerezza/rdf/utils/GraphUtilsTest.java      | 104 ---
 .../apache/clerezza/rdf/utils/IfpSmushTest.java | 115 ---
 .../apache/clerezza/rdf/utils/RdfListTest.java  | 183 -----
 .../clerezza/rdf/utils/SameAsSmushTest.java     |  78 --
 .../clerezza/rdf/utils/TestGraphNode.java       | 271 -------
 .../clerezza/rdf/utils/UnionGraphTest.java      |  78 --
 .../rdf/utils/smushing/SameAsSmushTest.java     |  92 ---
 rdf/pom.xml                                     |   7 +-
 rdf/utils/LICENSE                               | 201 ++++++
 rdf/utils/pom.xml                               |  69 ++
 .../apache/clerezza/rdf/utils/GraphNode.java    | 722 +++++++++++++++++++
 .../apache/clerezza/rdf/utils/GraphUtils.java   | 163 +++++
 .../org/apache/clerezza/rdf/utils/IriUtil.java  |  63 ++
 .../org/apache/clerezza/rdf/utils/RdfList.java  | 358 +++++++++
 .../clerezza/rdf/utils/SeeAlsoExpander.java     | 113 +++
 .../org/apache/clerezza/rdf/utils/Smusher.java  |  61 ++
 .../apache/clerezza/rdf/utils/UnionGraph.java   | 286 ++++++++
 .../clerezza/rdf/utils/UnionWatchableGraph.java |  54 ++
 .../clerezza/rdf/utils/UriMutatingGraph.java    | 223 ++++++
 .../graphnodeprovider/GraphNodeProvider.java    |  51 ++
 .../rdf/utils/smushing/BaseSmusher.java         | 135 ++++
 .../clerezza/rdf/utils/smushing/IfpSmusher.java | 174 +++++
 .../rdf/utils/smushing/SameAsSmusher.java       | 113 +++
 .../clerezza/rdf/utils/GraphUtilsTest.java      | 104 +++
 .../apache/clerezza/rdf/utils/IfpSmushTest.java | 115 +++
 .../apache/clerezza/rdf/utils/RdfListTest.java  | 183 +++++
 .../clerezza/rdf/utils/SameAsSmushTest.java     |  78 ++
 .../clerezza/rdf/utils/TestGraphNode.java       | 271 +++++++
 .../clerezza/rdf/utils/UnionGraphTest.java      |  78 ++
 .../rdf/utils/smushing/SameAsSmushTest.java     |  92 +++
 45 files changed, 3711 insertions(+), 3710 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/LICENSE
----------------------------------------------------------------------
diff --git a/rdf.utils/LICENSE b/rdf.utils/LICENSE
deleted file mode 100644
index 261eeb9..0000000
--- a/rdf.utils/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
-   APPENDIX: How to apply the Apache License to your work.
-
-      To apply the Apache License to your work, attach the following
-      boilerplate notice, with the fields enclosed by brackets "[]"
-      replaced with your own identifying information. (Don't include
-      the brackets!)  The text should be enclosed in the appropriate
-      comment syntax for the file format. We also recommend that a
-      file or class name and description of purpose be included on the
-      same "printed page" as the copyright notice for easier
-      identification within third-party archives.
-
-   Copyright [yyyy] [name of copyright owner]
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.utils/pom.xml b/rdf.utils/pom.xml
deleted file mode 100644
index 0f6b648..0000000
--- a/rdf.utils/pom.xml
+++ /dev/null
@@ -1,69 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements.  See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership.  The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License.  You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied.  See the License for the
- specific language governing permissions and limitations
- under the License.
-
--->
-
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <artifactId>clerezza</artifactId>
-        <groupId>org.apache.clerezza</groupId>
-        <version>7-SNAPSHOT</version>
-        <relativePath>../parent</relativePath>
-    </parent>
-    <groupId>org.apache.clerezza</groupId>
-    <artifactId>rdf.utils</artifactId>
-    <packaging>bundle</packaging>
-    <version>1.0.0-SNAPSHOT</version>
-    <name>Clerezza - RDF - Utilities</name>
-    <description>Utility classed to deal with Clerezza Models</description>
-    <dependencies>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza</groupId>
-            <artifactId>rdf.core</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza.commons-rdf</groupId>
-            <artifactId>commons-rdf-api</artifactId>
-            <version>0.1-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza.commons-rdf</groupId>
-            <artifactId>commons-rdf-impl-utils</artifactId>
-            <version>0.1-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza</groupId>
-            <artifactId>rdf.ontologies</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza</groupId>
-            <artifactId>rdf.core.test</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
deleted file mode 100644
index 8a1365f..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
+++ /dev/null
@@ -1,722 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import org.apache.commons.rdf.impl.*;
-import org.apache.commons.rdf.impl.utils.*;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-
-import java.util.*;
-import java.util.concurrent.locks.Lock;
-import org.apache.clerezza.rdf.core.LiteralFactory;
-import org.apache.commons.rdf.*;
-
-/**
- * This class represents a node in the context of a graph. It provides
- * utility methods to explore and modify its neighbourhood. The method
- * modifying the graph will throw an {@link UnsupportedOperationException}
- * it the underlying Graph in immutable (i.e. is a {@link ImmutableGraph}.
- *
- * @since 0.2
- * @author reto, mir
- */
-public class GraphNode {
-
-    private final RdfTerm resource;
-    private final Graph graph;
-
-    /**
-     * Create a GraphNode representing resource within graph.
-     *
-     * @param resource the resource this GraphNode represents
-     * @param graph the Graph that describes the resource
-     */
-    public GraphNode(RdfTerm resource, Graph graph) {
-        if (resource == null) {
-            throw new IllegalArgumentException("resource may not be null");
-        }
-        if (graph == null) {
-            throw new IllegalArgumentException("graph may not be null");
-        }
-        this.resource = resource;
-        this.graph = graph;
-    }
-
-    /**
-     * Gets the graph the node represented by this instance is in
-     *
-     * @return the graph of this GraphNode
-     */
-    public Graph getGraph() {
-        return graph;
-    }
-
-    /**
-     * Gets the unwrapped node
-     *
-     * @return the node represented by this GraphNode
-     */
-    public RdfTerm getNode() {
-        return resource;
-    }
-
-    /**
-     * Deletes the context of a node
-     * @see getNodeContext()
-     */
-    public void deleteNodeContext() {
-        for (Triple triple : getNodeContext()) {
-            graph.remove(triple);
-        }
-    }
-
-    /**
-     * The context of a node are the triples containing a node
-     * as subject or object and recursively the context of the b-nodes in any
-     * of these statements.
-     *
-     * The triples in the ImmutableGraph returned by this method contain the same bnode
-     * instances as in the original graph.
-     *
-     * @return the context of the node represented by the instance
-     */
-    public ImmutableGraph getNodeContext() {
-        Lock l = readLock();
-        l.lock();
-        try {
-            final HashSet<RdfTerm> dontExpand = new HashSet<RdfTerm>();
-            dontExpand.add(resource);
-            if (resource instanceof Iri) {
-                return getContextOf((Iri) resource, dontExpand).getImmutableGraph();
-            }
-            return getContextOf(resource, dontExpand).getImmutableGraph();
-        } finally {
-            l.unlock();
-        }
-
-    }
-
-    private Graph getContextOf(Iri node, final Set<RdfTerm> dontExpand) {
-        final String uriPrefix = node.getUnicodeString()+'#';
-        return getContextOf(node, dontExpand, new Acceptor() {
-
-            @Override
-            public boolean expand(RdfTerm resource) {
-                if (resource instanceof BlankNode) {
-                    return true;
-                }
-                if (resource instanceof Iri) {
-                    return ((Iri)resource).getUnicodeString().startsWith(uriPrefix);
-                }
-                return false;
-            }
-        });
-    }
-
-    /**
-     * Returns the context of a <code>BlankNodeOrIri</code>
-     *
-     * @param node
-     * @param dontExpand a list of bnodes at which to stop expansion, if node
-     * is a BlankNode it should be contained (potentially faster)
-     * @return the context of a node
-     */
-    private Graph getContextOf(RdfTerm node, final Set<RdfTerm> dontExpand) {
-        return getContextOf(node, dontExpand, new Acceptor() {
-
-            @Override
-            public boolean expand(RdfTerm resource) {
-                if (resource instanceof BlankNode) {
-                    return true;
-                }
-                return false;
-            }
-        });
-    }
-
-    private interface Acceptor {
-        boolean expand(RdfTerm resource);
-    }
-    private Graph getContextOf(RdfTerm node, final Set<RdfTerm> dontExpand, Acceptor acceptor) {
-        Graph result = new SimpleGraph();
-        if (node instanceof BlankNodeOrIri) {
-            Iterator<Triple> forwardProperties = graph.filter((BlankNodeOrIri) node, null, null);
-            while (forwardProperties.hasNext()) {
-                Triple triple = forwardProperties.next();
-                result.add(triple);
-                RdfTerm object = triple.getObject();
-                if (acceptor.expand(object) && !dontExpand.contains(object)) {
-                    dontExpand.add(object);
-                    result.addAll(getContextOf(object, dontExpand, acceptor));
-                }
-            }
-        }
-        Iterator<Triple> backwardProperties = graph.filter(null, null, node);
-        while (backwardProperties.hasNext()) {
-            Triple triple = backwardProperties.next();
-            result.add(triple);
-            BlankNodeOrIri subject = triple.getSubject();
-            if (acceptor.expand(subject) && !dontExpand.contains(subject)) {
-                dontExpand.add(subject);
-                result.addAll(getContextOf(subject, dontExpand, acceptor));
-            }
-        }
-        return result;
-    }
-
-    private <T> Iterator<T> getTypeSelectedObjects(Iri property, final Class<T> type) {
-        final Iterator<RdfTerm> objects = getObjects(property);
-        return new Iterator<T>() {
-
-            T next = prepareNext();
-
-            @Override
-            public boolean hasNext() {
-                return next != null;
-            }
-
-            @Override
-            public T next() {
-                T result = next;
-                next = prepareNext();
-                return result;
-            }
-
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException("Not supported yet.");
-            }
-
-            private T prepareNext() {
-                while (objects.hasNext()) {
-                    RdfTerm nextObject = objects.next();
-                    if (type.isAssignableFrom(nextObject.getClass())) {
-                        return (T) nextObject;
-                    }
-                }
-                return null;
-            }
-        };
-    }
-
-    public Iterator<Literal> getLiterals(Iri property) {
-        final Iterator<RdfTerm> objects = getObjects(property);
-        return new Iterator<Literal>() {
-
-            Literal next = prepareNext();
-
-            @Override
-            public boolean hasNext() {
-                return next != null;
-            }
-
-            @Override
-            public Literal next() {
-                Literal result = next;
-                next = prepareNext();
-                return result;
-            }
-
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException("Not supported yet.");
-            }
-
-            private Literal prepareNext() {
-                while (objects.hasNext()) {
-                    RdfTerm nextObject = objects.next();
-                    if (nextObject instanceof Literal) {
-                        return (Literal) nextObject;
-                    }
-                }
-                return null;
-            }
-        };
-    }
-
-    /**
-     * Count the number of triples in the underlying triple-collection
-     * with this node as subject and a specified property as predicate.
-     *
-     * @param property the property to be examined
-     * @return the number of triples in the underlying triple-collection
-     *        which meet the specified condition
-     */
-    public int countObjects(Iri property) {
-        return countTriples(graph.filter((BlankNodeOrIri) resource, property, null));
-    }
-
-    private int countTriples(final Iterator<Triple> triples) {
-        int count = 0;
-        while (triples.hasNext()) {
-            triples.next();
-            count++;
-        }
-        return count;
-    }
-
-    /**
-     * Get the objects of statements with this node as subject and a specified
-     * property as predicate.
-     *
-     * @param property the property
-     * @return
-     */
-    public Iterator<RdfTerm> getObjects(Iri property) {
-        if (resource instanceof BlankNodeOrIri) {
-            final Iterator<Triple> triples = graph.filter((BlankNodeOrIri) resource, property, null);
-            return new Iterator<RdfTerm>() {
-
-                @Override
-                public boolean hasNext() {
-                    return triples.hasNext();
-                }
-
-                @Override
-                public RdfTerm next() {
-                    final Triple triple = triples.next();
-                    if (triple != null) {
-                        return triple.getObject();
-                    } else {
-                        return null;
-                    }
-                }
-
-                @Override
-                public void remove() {
-                    throw new UnsupportedOperationException("Not supported yet.");
-                }
-            };
-        } else {
-            return new Iterator<RdfTerm>() {
-
-                @Override
-                public boolean hasNext() {
-                    return false;
-                }
-
-                @Override
-                public RdfTerm next() {
-                    return null;
-                }
-
-                @Override
-                public void remove() {
-                    throw new UnsupportedOperationException("Not supported yet.");
-                }
-            };
-        }
-    }
-
-    /**
-     * Checks wether this node has the given property with the given value.
-     * If the given value is null, then it is checked if this node has the
-     * specified property regardless of its value.
-     *
-     * @param property
-     * @param object
-     * @return true if the node represented by this object is the subject of a
-     *         statement with the given prediate and object, false otherwise
-     */
-    public boolean hasProperty(Iri property, RdfTerm object) {
-        Lock l = readLock();
-        l.lock();
-        try {
-            Iterator<RdfTerm> objects = getObjects(property);
-            if (object == null) {
-                return objects.hasNext();
-            }
-            while (objects.hasNext()) {
-                if (objects.next().equals(object)) {
-                    return true;
-                }
-            }
-            return false;
-        } finally {
-            l.unlock();
-        }
-    }
-
-    /**
-     * Count the number of triples in the underlying triple-collection
-     * with this node as object and a specified property as predicate.
-     *
-     * @param property the property to be examined
-     * @return the number of triples in the underlying triple-collection
-     *        which meet the specified condition
-     */
-    public int countSubjects(Iri property) {
-        Lock l = readLock();
-        l.lock();
-        try {
-            return countTriples(graph.filter(null, property, resource));
-        } finally {
-            l.unlock();
-        }
-    }
-
-    /**
-     * Get the subjects of statements with this node as object and a specified
-     * property as predicate.
-     *
-     * @param property the property
-     * @return
-     */
-    public Iterator<BlankNodeOrIri> getSubjects(Iri property) {
-        final Iterator<Triple> triples = graph.filter(null, property, resource);
-        return new Iterator<BlankNodeOrIri>() {
-
-            @Override
-            public boolean hasNext() {
-                return triples.hasNext();
-            }
-
-            @Override
-            public BlankNodeOrIri next() {
-                return triples.next().getSubject();
-            }
-
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException("Not supported yet.");
-            }
-        };
-    }
-
-    public Iterator<Iri> getIriObjects(Iri property) {
-        return getTypeSelectedObjects(property, Iri.class);
-
-    }
-
-    /**
-     * Get all available properties as an {@link Iterator}<{@link Iri}>.
-     * You can use <code>getObjects(Iri property)</code> to get the values of
-     * each property
-     *
-     * @return an iterator over properties of this node
-     */
-    public Iterator<Iri> getProperties() {
-        if (resource instanceof BlankNodeOrIri) {
-            final Iterator<Triple> triples = graph.filter((BlankNodeOrIri) resource, null, null);
-            return getUniquePredicates(triples);
-        } else {
-            return new Iterator<Iri>() {
-
-                @Override
-                public boolean hasNext() {
-                    return false;
-                }
-
-                @Override
-                public Iri next() {
-                    return null;
-                }
-
-                @Override
-                public void remove() {
-                    throw new UnsupportedOperationException("Not supported yet.");
-                }
-            };
-        }
-    }
-
-    /**
-     * Get all inverse properties as an {@link Iterator}<{@link Iri}>.
-     * You can use <code>getSubject(Iri property)</code> to get the values of
-     * each inverse property
-     *
-     * @return an iterator over properties pointing to this node
-     */
-    public Iterator<Iri> getInverseProperties() {
-        final Iterator<Triple> triples = graph.filter(null, null, resource);
-        return getUniquePredicates(triples);
-    }
-
-    /**
-     *
-     * @param triples
-     * @returnan {@link Iterator}<{@link Iri}> containing the predicates from
-     * an {@link Iterator}<{@link Triple}>
-     */
-    private Iterator<Iri> getUniquePredicates(final Iterator<Triple> triples) {
-        final Set<Iri> resultSet = new HashSet<Iri>();
-        while (triples.hasNext()) {
-            resultSet.add(triples.next().getPredicate());
-        }
-        return resultSet.iterator();
-    }
-
-    /**
-     * Adds a property to the node with the specified predicate and object
-     *
-     * @param predicate
-     * @param object
-     */
-    public void addProperty(Iri predicate, RdfTerm object) {
-        if (resource instanceof BlankNodeOrIri) {
-            graph.add(new TripleImpl((BlankNodeOrIri) resource, predicate, object));
-        } else {
-            throw new RuntimeException("Literals cannot be the subject of a statement");
-        }
-    }
-
-
-    /**
-     * Coverts the value into a typed literals and sets it as object of the
-     * specified property
-     *
-     * @param property the predicate of the triple to be created
-     * @param value the value of the typed literal object
-     */
-    public void addPropertyValue(Iri property, Object value) {
-        addProperty(property,
-                LiteralFactory.getInstance().createTypedLiteral(value));
-    }
-
-    /**
-     * Adds a property to the node with the inverse of the specified predicate and object
-     * In other words <code>subject</code> will be related via the property <code>relation</code> to this node.
-     *
-     * @param predicate
-     * @param subject
-     */
-    public void addInverseProperty(Iri predicate, RdfTerm subject) {
-        if (subject instanceof BlankNodeOrIri) {
-            graph.add(new TripleImpl((BlankNodeOrIri) subject, predicate, resource));
-        } else {
-            throw new RuntimeException("Literals cannot be the subject of a statement");
-        }
-    }
-
-
-    /**
-     * creates and returns an <code>RdfList</code> for the node and
-     * Graph represented by this object.
-     *
-     * @return a List to easy access the rdf:List represented by this node
-     */
-    public List<RdfTerm> asList() {
-        if (resource instanceof BlankNodeOrIri) {
-            return new RdfList((BlankNodeOrIri) resource, graph);
-        } else {
-            throw new RuntimeException("Literals cannot be the subject of a List");
-        }
-    }
-
-    /**
-     * Deletes all statement with the current node as subject and the specified
-     * predicate
-     *
-     * @param predicate
-     */
-    public void deleteProperties(Iri predicate) {
-        if (resource instanceof BlankNodeOrIri) {
-            Iterator<Triple> tripleIter = graph.filter((BlankNodeOrIri) resource, predicate, null);
-            Collection<Triple> toDelete = new ArrayList<Triple>();
-            while (tripleIter.hasNext()) {
-                Triple triple = tripleIter.next();
-                toDelete.add(triple);
-            }
-            for (Triple triple : toDelete) {
-                graph.remove(triple);
-            }
-        }
-    }
-
-    /**
-     * Delete property to the node with the specified predicate and object
-     *
-     * @param predicate
-     * @param object
-     */
-    public void deleteProperty(Iri predicate, RdfTerm object) {
-        if (resource instanceof BlankNodeOrIri) {
-            graph.remove(new TripleImpl((BlankNodeOrIri) resource, predicate, object));
-        }
-    }
-
-    @Override
-    public String toString() {
-        return resource.toString();
-    }
-
-    /**
-     * Replaces the graph node resouce with the specified <code>BlankNodeOrIri</code>.
-     * The resource is only replaced where it is either subject or object.
-     * @param replacement
-     * @return a GraphNode representing the replecement node
-     */
-    public GraphNode replaceWith(BlankNodeOrIri replacement) {
-        return replaceWith(replacement, false);
-    }
-
-    /**
-     * Replaces the graph node resouce with the specified <code>BlankNodeOrIri</code>.
-     * Over the boolean <code>checkPredicate</code> it can be specified if the
-     * resource should also be replaced where it is used as predicate.
-     * @param replacement
-     * @param checkPredicates
-     * @return a GraphNode representing the replecement node
-     */
-    public GraphNode replaceWith(BlankNodeOrIri replacement, boolean checkPredicates) {
-        Graph newTriples = new SimpleGraph();
-        if (!(resource instanceof Literal)) {
-            Iterator<Triple> subjectTriples = graph.filter((BlankNodeOrIri) resource, null,
-                    null);
-            while (subjectTriples.hasNext()) {
-                Triple triple = subjectTriples.next();
-                Triple newTriple = new TripleImpl(replacement, triple.getPredicate(),
-                        triple.getObject());
-                subjectTriples.remove();
-                newTriples.add(newTriple);
-            }
-            graph.addAll(newTriples);
-            newTriples.clear();
-        }
-
-        Iterator<Triple> objectTriples = graph.filter(null, null, resource);
-        while (objectTriples.hasNext()) {
-            Triple triple = objectTriples.next();
-            Triple newTriple = new TripleImpl(triple.getSubject(),
-                    triple.getPredicate(), replacement);
-            objectTriples.remove();
-            newTriples.add(newTriple);
-        }
-        graph.addAll(newTriples);
-        newTriples.clear();
-
-        if (checkPredicates && replacement instanceof Iri
-                && resource instanceof Iri) {
-            Iterator<Triple> predicateTriples = graph.filter(null,
-                    (Iri) resource, null);
-            while (predicateTriples.hasNext()) {
-                Triple triple = predicateTriples.next();
-                Triple newTriple = new TripleImpl(triple.getSubject(),
-                        (Iri) replacement, triple.getObject());
-                predicateTriples.remove();
-                newTriples.add(newTriple);
-            }
-            graph.addAll(newTriples);
-        }
-        return new GraphNode(replacement, graph);
-    }
-
-    /**
-     * Returns a iterator containing all objects of the triples where this
-     * graph node is the subject and has the specified property. The objects
-     * are returned as <code>GraphNode</code>s.
-     *
-     * @param property
-     * @return
-     */
-    public Iterator<GraphNode> getObjectNodes(Iri property) {
-        final Iterator<RdfTerm> objects = this.getObjects(property);
-        return new Iterator<GraphNode>() {
-
-            @Override
-            public boolean hasNext() {
-                return objects.hasNext();
-            }
-
-            @Override
-            public GraphNode next() {
-                RdfTerm object = objects.next();
-                return new GraphNode(object, graph);
-
-            }
-
-            @Override
-            public void remove() {
-                objects.remove();
-            }
-        };
-    }
-
-    /**
-     * Returns a iterator containing all subjects of the triples where this
-     * graph node is the object and has the specified property. The subjects
-     * are returned as <code>GraphNode</code>s.
-     *
-     * @param property
-     * @return
-     */
-    public Iterator<GraphNode> getSubjectNodes(Iri property) {
-        final Iterator<BlankNodeOrIri> subjects = this.getSubjects(property);
-        return new Iterator<GraphNode>() {
-
-            @Override
-            public boolean hasNext() {
-                return subjects.hasNext();
-            }
-
-            @Override
-            public GraphNode next() {
-                RdfTerm object = subjects.next();
-                return new GraphNode(object, graph);
-
-            }
-
-            @Override
-            public void remove() {
-                subjects.remove();
-            }
-        };
-    }
-
-    /**
-     *
-     * @param obj
-     * @return true if obj is an instance of the same class represening the same
-     * node in the same graph, subclasses may have different identity criteria.
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == null || !(obj.getClass().equals(getClass()))) {
-            return false;
-        }
-        GraphNode other = (GraphNode) obj;
-        return getNode().equals(other.getNode())
-                && getGraph().equals(other.getGraph());
-    }
-
-    @Override
-    public int hashCode() {
-        return 13 * getNode().hashCode() + getGraph().hashCode();
-    }
-
-    /**
-     * @return a ReadLock if the underlying ImmutableGraph is a LockableGraph it returns its lock, otherwise null
-     */
-    public Lock readLock() {
-
-            return getGraph().getLock().readLock();
-
-    }
-
-    /**
-     *
-     * @return
-     */
-    public Lock writeLock() {
-
-            return (getGraph()).getLock().writeLock();
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java
deleted file mode 100644
index dc3943b..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.clerezza.rdf.utils;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.ImmutableGraph;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-
-/**
- * Utility methods to manipulate <code>Graph</code>s
- *
- * @author reto
- */
-public class GraphUtils {
-
-    /**
-     * Removes a subGraph from an Graph. The subGraph must match a subgraph of
-     * Graph so that for every node in <code>subGraph</code>
-     * each triple it appears in is also present in <code>mGraph</code>. Two
-     * bnodes are considered equals if their contexts (as returned by
-     * <code>GraphNode.getNodeContext</code> are equals.
-     *
-     * @param mGraph
-     * @param subGraph
-     * @throws org.apache.clerezza.rdf.utils.GraphUtils.NoSuchSubGraphException
-     */
-    public static void removeSubGraph(Graph mGraph, Graph subGraph)
-            throws NoSuchSubGraphException {
-        //point to triples of mGraph that are to be removed (if something is removed)
-        final Set<Triple> removingTriples = new HashSet<Triple>();
-        //we first check only the grounded triples and put the non-grounded in here:
-        final Graph unGroundedTriples = new SimpleGraph();
-        for (Triple triple : subGraph) {
-            if (isGrounded(triple)) {
-                if (!mGraph.contains(triple)) {
-                    throw new NoSuchSubGraphException();
-                }
-                removingTriples.add(triple);
-            } else {
-                unGroundedTriples.add(triple);
-            }
-        }
-
-        //we first remove the context of bnodes we find in object position
-        OBJ_BNODE_LOOP: while (true) {
-            final Triple triple = getTripleWithBlankNodeObject(unGroundedTriples);
-            if (triple == null) {
-                break;
-            }
-            final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples);
-            BlankNodeOrIri subject = triple.getSubject();
-            ImmutableGraph context = objectGN.getNodeContext();
-            Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null);
-            while (potentialIter.hasNext()) {
-                try {
-                    final Triple potentialTriple = potentialIter.next();
-                    BlankNode potentialMatch = (BlankNode)potentialTriple.getObject();
-                    final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
-                    if (potentialContext.equals(context)) {
-                        removingTriples.addAll(potentialContext);
-                        unGroundedTriples.removeAll(context);
-                        continue OBJ_BNODE_LOOP;
-                    }
-                } catch (ClassCastException e) {
-                    continue;
-                }
-            }
-            throw new NoSuchSubGraphException();
-        }
-        SUBJ_BNODE_LOOP: while (true) {
-            final Triple triple = getTripleWithBlankNodeSubject(unGroundedTriples);
-            if (triple == null) {
-                break;
-            }
-            final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples);
-            RdfTerm object = triple.getObject();
-            if (object instanceof BlankNode) {
-                object = null;
-            }
-            ImmutableGraph context = subjectGN.getNodeContext();
-            Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object);
-            while (potentialIter.hasNext()) {
-                try {
-                    final Triple potentialTriple = potentialIter.next();
-                    BlankNode potentialMatch = (BlankNode)potentialTriple.getSubject();
-                    final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
-                    if (potentialContext.equals(context)) {
-                        removingTriples.addAll(potentialContext);
-                        unGroundedTriples.removeAll(context);
-                        continue SUBJ_BNODE_LOOP;
-                    }
-                } catch (ClassCastException e) {
-                    continue;
-                }
-            }
-            throw new NoSuchSubGraphException();
-        }
-        mGraph.removeAll(removingTriples);
-    }
-
-    private static boolean isGrounded(Triple triple) {
-        if (triple.getSubject() instanceof BlankNode) {
-            return false;
-        }
-        if (triple.getObject() instanceof BlankNode) {
-            return false;
-        }
-        return true;
-    }
-
-    /** retrun triples with a bnode only at object position
-     *
-     * @param triples
-     * @return
-     */
-    private static Triple getTripleWithBlankNodeObject(Graph triples) {
-        for (Triple triple : triples) {
-            if (triple.getSubject() instanceof BlankNode) {
-                continue;
-            }
-            if (triple.getObject() instanceof BlankNode) {
-                return triple;
-            }
-        }
-        return null;
-    }
-    private static Triple getTripleWithBlankNodeSubject(Graph triples) {
-        for (Triple triple : triples) {
-            if (triple.getSubject() instanceof BlankNode) {
-                return triple;
-            }
-        }
-        return null;
-    }
-
-    public static class NoSuchSubGraphException extends Exception {
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java
deleted file mode 100644
index 323c9f2..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-
-/**
- * A utility class for Iri and String manipulations.
- *
- * @author tio
- */
-public class IriUtil {
-
-    /**
-     * Strips #x00 - #x1F and #x7F-#x9F from a Unicode string
-     * @see <a href="http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference">
-     * http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference</a> and
-     * replaces all US-ASCII space character with a "+".
-     *
-     * @param inputChars
-     * @return the stripped string
-     * 
-     */
-    public static String stripNonIriChars(CharSequence inputChars) {
-
-        if (inputChars == null) {
-            return "";
-        }
-
-        StringBuffer buffer = new StringBuffer();
-
-        for (int i = 0; i < inputChars.length(); i++) {
-            char c = inputChars.charAt(i);
-
-            if (!isIllegal(c)) {
-                buffer.append(c);
-            }
-        }
-        return buffer.toString().replaceAll("\\s+", "+");
-    }
-
-    private static boolean isIllegal(char ch) {
-        if ((ch >= 0x7F) && (ch <= 0x9F)) {
-            return true;
-        }
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
deleted file mode 100644
index db994e9..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
+++ /dev/null
@@ -1,358 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import java.io.FileOutputStream;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.AbstractList;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.apache.clerezza.rdf.core.serializedform.Serializer;
-import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
-import org.apache.clerezza.rdf.ontologies.OWL;
-import org.apache.clerezza.rdf.ontologies.RDF;
-import org.apache.commons.rdf.Graph;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * An implementation of an <code>java.util.List</code> backed by an RDF
- * collection (rdf:List). The list allows modification that are reflected
- * to the underlying <code>Graph</code>. It reads the data from the
- * <code>Graph</code> when it is first needed, so changes to the
- * Graph affecting the rdf:List may or may not have an effect on the
- * values returned by instances of this class. For that reason only one
- * instance of this class should be used for accessing an rdf:List of sublists
- * thereof when the lists are being modified, having multiple lists exclusively
- * for read operations (such as for immutable <code>Graph</code>s) is
- * not problematic.
- *
- * @author rbn, mir
- */
-public class RdfList extends AbstractList<RdfTerm> {
-
-    private static final Logger logger = LoggerFactory.getLogger(RdfList.class);
-
-    private final static Iri RDF_NIL =
-            new Iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
-    /**
-     * a list of the linked rdf:List elements in order
-     */
-    private List<BlankNodeOrIri> listList = new ArrayList<BlankNodeOrIri>();
-    private List<RdfTerm> valueList = new ArrayList<RdfTerm>();
-    private BlankNodeOrIri firstList;
-    private Graph tc;
-    private boolean totallyExpanded = false;
-
-    /**
-     * Get a list for the specified resource.
-     *
-     * If the list is modified using the created instance
-     * <code>listRdfTerm</code> will always be the first list.
-     *
-     * @param listRdfTerm
-     * @param tc
-     */
-    public RdfList(BlankNodeOrIri listRdfTerm, Graph tc) {
-        firstList = listRdfTerm;
-        this.tc = tc;
-
-    }
-
-    /**
-     * Get a list for the specified resource node.
-     *
-     * @param listNode
-     */
-    public RdfList(GraphNode listNode) {
-        this((BlankNodeOrIri)listNode.getNode(), listNode.getGraph());
-    }
-
-    /**
-     * Creates an empty RdfList by writing a triple
-     * "{@code listRdfTerm} owl:sameAs rdf.nil ." to {@code tc}.
-     *
-     * @param listRdfTerm
-     * @param tc
-     * @return    an empty rdf:List.
-     * @throws IllegalArgumentException
-     *        if the provided {@code  listRdfTerm} is a non-empty rdf:List.
-     */
-    public static RdfList createEmptyList(BlankNodeOrIri listRdfTerm, Graph tc)
-            throws IllegalArgumentException {
-
-        if (!tc.filter(listRdfTerm, RDF.first, null).hasNext()) {
-            RdfList list = new RdfList(listRdfTerm, tc);
-            list.tc.add(new TripleImpl(listRdfTerm, OWL.sameAs, RDF_NIL));
-            return list;
-        } else {
-            throw new IllegalArgumentException(listRdfTerm + "is a non-empty rdf:List.");
-        }
-    }
-
-    private void expandTill(int pos) {
-        if (totallyExpanded) {
-            return;
-        }
-        BlankNodeOrIri currentList;
-        if (listList.size() > 0) {
-            currentList = listList.get(listList.size()-1);
-        } else {
-            currentList = firstList;
-            if (!tc.filter(currentList, RDF.first, null).hasNext()) {
-                return;
-            }
-            listList.add(currentList);
-            valueList.add(getFirstEntry(currentList));
-        }
-        if (listList.size() >= pos) {
-            return;
-        }
-        while (true) {                
-            currentList = getRest(currentList);
-            if (currentList.equals(RDF_NIL)) {
-                totallyExpanded = true;
-                break;
-            }
-            if (listList.size() == pos) {
-                break;
-            }
-            valueList.add(getFirstEntry(currentList));
-            listList.add(currentList);
-        }
-    }
-
-
-
-    @Override
-    public RdfTerm get(int index) {
-        expandTill(index + 1);
-        return valueList.get(index);
-    }
-
-    @Override
-    public int size() {
-        expandTill(Integer.MAX_VALUE);        
-        return valueList.size();
-    }
-
-    @Override
-    public void add(int index, RdfTerm element) {
-        expandTill(index);
-        if (index == 0) {
-            //special casing to make sure the first list remains the same resource
-            if (listList.size() == 0) {
-                tc.remove(new TripleImpl(firstList, OWL.sameAs, RDF_NIL));
-                tc.add(new TripleImpl(firstList, RDF.rest, RDF_NIL));
-                tc.add(new TripleImpl(firstList, RDF.first, element));
-                listList.add(firstList);
-            } else {
-                tc.remove(new TripleImpl(listList.get(0), RDF.first, valueList.get(0)));
-                tc.add(new TripleImpl(listList.get(0), RDF.first, element));
-                addInRdfList(1, valueList.get(0));
-            }
-        } else {
-            addInRdfList(index, element);
-        }
-        valueList.add(index, element);
-    }
-    
-    /**
-     *
-     * @param index is > 0
-     * @param element
-     */
-    private void addInRdfList(int index, RdfTerm element) {
-        expandTill(index+1);
-        BlankNodeOrIri newList = new BlankNode() {
-        };
-        tc.add(new TripleImpl(newList, RDF.first, element));
-        if (index < listList.size()) {
-            tc.add(new TripleImpl(newList, RDF.rest, listList.get(index)));
-            tc.remove(new TripleImpl(listList.get(index - 1), RDF.rest, listList.get(index)));
-        } else {
-            tc.remove(new TripleImpl(listList.get(index - 1), RDF.rest, RDF_NIL));
-            tc.add(new TripleImpl(newList, RDF.rest, RDF_NIL));
-
-        }
-        tc.add(new TripleImpl(listList.get(index - 1), RDF.rest, newList));
-        listList.add(index, newList);
-    }
-
-    @Override
-    public RdfTerm remove(int index) {
-        //keeping the first list resource
-        tc.remove(new TripleImpl(listList.get(index), RDF.first, valueList.get(index)));
-        if (index == (listList.size() - 1)) {
-            tc.remove(new TripleImpl(listList.get(index), RDF.rest, RDF_NIL));    
-            if (index > 0) {
-                tc.remove(new TripleImpl(listList.get(index - 1), RDF.rest, listList.get(index)));
-                tc.add(new TripleImpl(listList.get(index - 1), RDF.rest, RDF_NIL));
-            } else {
-                tc.add(new TripleImpl(listList.get(index), OWL.sameAs, RDF_NIL));
-            }
-            listList.remove(index);
-        } else {
-            tc.add(new TripleImpl(listList.get(index), RDF.first, valueList.get(index+1)));
-            tc.remove(new TripleImpl(listList.get(index), RDF.rest, listList.get(index + 1)));
-            tc.remove(new TripleImpl(listList.get(index + 1), RDF.first, valueList.get(index + 1)));
-            if (index == (listList.size() - 2)) {
-                tc.remove(new TripleImpl(listList.get(index + 1), RDF.rest, RDF_NIL));
-                tc.add(new TripleImpl(listList.get(index), RDF.rest, RDF_NIL));
-            } else {
-                tc.remove(new TripleImpl(listList.get(index + 1), RDF.rest, listList.get(index + 2)));
-                tc.add(new TripleImpl(listList.get(index), RDF.rest, listList.get(index + 2)));
-            }
-            listList.remove(index+1);
-        }
-        return valueList.remove(index);
-    }
-
-    private BlankNodeOrIri getRest(BlankNodeOrIri list) {
-        return (BlankNodeOrIri) tc.filter(list, RDF.rest, null).next().getObject();
-    }
-
-    private RdfTerm getFirstEntry(final BlankNodeOrIri listRdfTerm) {
-        try {
-            return tc.filter(listRdfTerm, RDF.first, null).next().getObject();
-        } catch (final NullPointerException e) {
-            RuntimeException runtimeEx = AccessController.doPrivileged(new PrivilegedAction<RuntimeException>() {
-                @Override
-                public RuntimeException run(){
-                    try {
-                        final FileOutputStream fileOutputStream = new FileOutputStream("/tmp/broken-list.nt");
-                        final GraphNode graphNode = new GraphNode(listRdfTerm, tc);
-                        Serializer.getInstance().serialize(fileOutputStream, graphNode.getNodeContext(), SupportedFormat.N_TRIPLE);
-                        fileOutputStream.flush();
-                        logger.warn("GraphNode: " + graphNode);
-                        final Iterator<Iri> properties = graphNode.getProperties();
-                        while (properties.hasNext()) {
-                            logger.warn("available: " + properties.next());
-                        }
-                        return new RuntimeException("broken list " + listRdfTerm, e);
-                    } catch (Exception ex) {
-                        return new RuntimeException(ex);
-                    }
-
-                }
-            });
-            throw runtimeEx;
-        }
-    }
-
-    public BlankNodeOrIri getListRdfTerm() {
-        return firstList;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final RdfList other = (RdfList) obj;
-
-        if (!other.firstList.equals(this.firstList)) {
-            return false;
-        }
-
-        if (!other.tc.equals(this.tc)) {
-            return false;
-        }
-
-        return true;
-    }
-
-    @Override
-    public int hashCode() {
-        return 17 * this.firstList.hashCode() + this.tc.hashCode();
-    }
-
-    /**
-     * Returns the rdf lists of which the specified <code>GraphNode</code> is
-     * an element of. Sublists of other lists are not returned.
-     *
-     * @param element
-     * @return
-     */
-    public static Set<RdfList> findContainingLists(GraphNode element) {
-        Set<GraphNode> listNodes = findContainingListNodes(element);
-        if (listNodes.isEmpty()) {
-            return null;
-        }
-
-        Set<RdfList> rdfLists = new HashSet<RdfList>();
-        for (Iterator<GraphNode> it = listNodes.iterator(); it.hasNext();) {
-            GraphNode listNode = it.next();
-            rdfLists.add(new RdfList(listNode));
-        }
-        return rdfLists;
-    }
-
-    /**
-     * Returns a set of <code>GraphNode</code>S which are the first list nodes (meaning
-     * they are not the beginning of a sublist) of the list containing the specified
-     * <code>GraphNode</code> as an element.
-     *
-     * @param element
-     * @return
-     */
-    public static Set<GraphNode> findContainingListNodes(GraphNode element) {
-        Iterator<GraphNode> partOfaListNodesIter = element.getSubjectNodes(RDF.first);
-        if (!partOfaListNodesIter.hasNext()) {
-            return null;
-        }
-        Set<GraphNode> listNodes = new HashSet<GraphNode>();
-
-        while (partOfaListNodesIter.hasNext()) {
-            listNodes.addAll(findAllListNodes(partOfaListNodesIter.next()));
-        }
-        return listNodes;
-    }
-    
-    private static Set<GraphNode> findAllListNodes(GraphNode listPart) {
-        Iterator<GraphNode> invRestNodesIter;
-        Set<GraphNode> listNodes = new HashSet<GraphNode>();
-        do {
-            invRestNodesIter = listPart.getSubjectNodes(RDF.rest);
-            if (invRestNodesIter.hasNext()) {
-                listPart = invRestNodesIter.next();
-                while (invRestNodesIter.hasNext()) {
-                    GraphNode graphNode = invRestNodesIter.next();
-                    listNodes.addAll(findAllListNodes(graphNode));
-                }
-            } else {
-                listNodes.add(listPart);
-                break;
-            }
-        } while (true);
-        return listNodes;
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
deleted file mode 100644
index fef7e4b..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.clerezza.rdf.utils;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.locks.Lock;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
-import org.apache.clerezza.rdf.core.access.TcManager;
-import org.apache.clerezza.rdf.ontologies.RDFS;
-
-/**
- * Expands a GraphNode expanding SeeAlso-References of the node.
- *
- * @author reto
- */
-public class SeeAlsoExpander {
-    /**
-     * using TcManger instead of TcProvider as this ensures LockableGraphs
-     */
-    private final TcManager tcManager;
-    public SeeAlsoExpander(TcManager tcManager) {
-        this.tcManager = tcManager;
-
-    }
-
-    /**
-     * expands a node dereferencing its rdfs:seeAlso references using the
-     * tcManager associated to this instance. If the added TripleCollections
-     * also associate rdfs:seeAlso properties to node this are expanded till
-     * the maximum recursion depth specified.
-     *
-     * @param node the node to be expanded
-     * @param recursion the maximum recursion depth
-     * @return a new GraphNode over the union of the original and all expansion graphs
-     */
-    public GraphNode expand(GraphNode node, int recursion) {
-        Set<Iri> alreadyVisited = new HashSet();
-        Set<Graph> resultTripleCollections = new HashSet<Graph>();
-        resultTripleCollections.add(node.getGraph());
-        for (Iri uriRef : expand(node, alreadyVisited, recursion)) {
-            try {
-                resultTripleCollections.add(tcManager.getGraph(uriRef));
-            } catch (NoSuchEntityException e) {
-                //ignore
-            }
-        }
-        return new GraphNode(node.getNode(),
-                new UnionGraph(resultTripleCollections.toArray(
-                new Graph[resultTripleCollections.size()])));
-
-    }
-
-    private Set<Iri> getSeeAlsoObjectUris(GraphNode node) {
-        Set<Iri> result = new HashSet<Iri>();
-        Lock l = node.readLock();
-        l.lock();
-        try {
-            Iterator<RdfTerm> objects = node.getObjects(RDFS.seeAlso);
-            while (objects.hasNext()) {
-                RdfTerm next = objects.next();
-                if (next instanceof Iri) {
-                    result.add((Iri)next);
-                }
-            }
-        } finally {
-            l.unlock();
-        }
-        return result;
-    }
-
-    private Set<Iri> expand(GraphNode node, Set<Iri> alreadyVisited, int recursion) {
-        Set<Iri> rdfSeeAlsoTargets = getSeeAlsoObjectUris(node);
-        Set<Iri> result = new HashSet<Iri>();
-        result.addAll(rdfSeeAlsoTargets);
-        recursion++;
-        if (recursion > 0) {
-            rdfSeeAlsoTargets.removeAll(alreadyVisited);
-            alreadyVisited.addAll(rdfSeeAlsoTargets);
-            for (Iri target : rdfSeeAlsoTargets) {
-                try {
-                    result.addAll(expand(new GraphNode(node.getNode(),
-                        tcManager.getGraph(target)), alreadyVisited, recursion));
-                } catch (NoSuchEntityException e) {
-                    //ignore
-                }
-            }
-        }
-        return result;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
deleted file mode 100644
index 8d0ea45..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import org.apache.commons.rdf.Graph;
-import org.apache.clerezza.rdf.utils.smushing.IfpSmusher;
-import org.apache.clerezza.rdf.utils.smushing.SameAsSmusher;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A utility to smush equivalent resources. For greater flexibility use the 
- * classes in the smushing package.
- * 
- * @author reto
- */
-public class Smusher {
-
-    static final Logger log = LoggerFactory.getLogger(Smusher.class);
-
-    /**
-     * smush mGaph given the ontological facts. Currently it does only one step
-     * ifp smushin, i.e. only ifps are taken in account and only nodes that have
-     * the same node as ifp object in the orignal graph are equates. (calling
-     * the method a second time might lead to additional smushings.)
-     *
-     * @param mGraph
-     * @param tBox
-     */
-    public static void smush(Graph mGraph, Graph tBox) {
-        new IfpSmusher().smush(mGraph, tBox);
-    }
-
-    /**
-     * Smushes the specified graph adding owl:sameAs statements pointing to the new canonical IRI
-     * 
-     * @param mGraph
-     * @param owlSameStatements 
-     */
-    public static void sameAsSmush(Graph mGraph, Graph owlSameStatements) {
-        new SameAsSmusher().smush(mGraph, owlSameStatements, true);
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java
deleted file mode 100644
index a928f79..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.AbstractGraph;
-
-/**
- *
- * This class represents the union of multiple triple collections. A UnionGraph
- * appears like a merge of the different graphs (see.
- * http://www.w3.org/TR/rdf-mt/#graphdefs).
- *
- * @author hasan
- */
-public class UnionGraph extends AbstractGraph {
-
-    protected Graph[] baseTripleCollections;
-    private Lock readLock;
-    private Lock writeLock;
-
-    /**
-     * Constructs a UnionGraph over the specified baseTripleCollections. Write
-     * and delete operations are forwarded to the first baseTripleCollections.
-     *
-     * @param baseTripleCollections the baseTripleCollections
-     */
-    public UnionGraph(Graph... baseTripleCollections) {
-        this.baseTripleCollections = baseTripleCollections;
-        readLock = getPartialReadLock(0);
-        writeLock = createWriteLock();
-    }
-
-    @Override
-    public int performSize() {
-        int size = 0;
-        for (Graph graph : baseTripleCollections) {
-            size += graph.size();
-        }
-        return size;
-    }
-
-    @Override
-    public Iterator<Triple> performFilter(final BlankNodeOrIri subject,
-            final Iri predicate, final RdfTerm object) {
-        if (baseTripleCollections.length == 0) {
-            return new HashSet<Triple>(0).iterator();
-        }
-        return new Iterator<Triple>() {
-
-            int currentBaseTC = 0;
-            Iterator<Triple> currentBaseIter = baseTripleCollections[0].filter(
-                    subject, predicate, object);
-            private Triple lastReturned;
-
-            @Override
-            public boolean hasNext() {
-                if (currentBaseIter.hasNext()) {
-                    return true;
-                }
-                if (currentBaseTC == baseTripleCollections.length - 1) {
-                    return false;
-                }
-                currentBaseTC++;
-                currentBaseIter = baseTripleCollections[currentBaseTC].filter(
-                        subject, predicate, object);
-                return hasNext();
-            }
-
-            @Override
-            public Triple next() {
-                lastReturned = hasNext() ? currentBaseIter.next() : null;
-                return lastReturned;
-            }
-
-            @Override
-            public void remove() {
-                if (lastReturned == null) {
-                    throw new IllegalStateException();
-                }
-                if (currentBaseTC == 0) {
-                    currentBaseIter.remove();
-                }
-                lastReturned = null;
-            }
-        };
-    }
-
-    @Override
-    public boolean add(Triple e) {
-        if (baseTripleCollections.length == 0) {
-            throw new RuntimeException("no base graph for adding triples");
-        }
-        return baseTripleCollections[0].add(e);
-    }
-
-    @Override
-    public boolean remove(Object e) {
-        if (baseTripleCollections.length == 0) {
-            throw new RuntimeException("no base graph for removing triples");
-        }
-        return baseTripleCollections[0].remove(e);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (!(obj.getClass().equals(getClass()))) {
-            return false;
-        }
-        UnionGraph other = (UnionGraph) obj;
-        Set<Graph> otherGraphs
-                = new HashSet(Arrays.asList(other.baseTripleCollections));
-        Set<Graph> thisGraphs
-                = new HashSet(Arrays.asList(baseTripleCollections));
-        return thisGraphs.equals(otherGraphs)
-                && baseTripleCollections[0].equals(other.baseTripleCollections[0]);
-    }
-
-    @Override
-    public int hashCode() {
-        int hash = 0;
-        for (Graph graph : baseTripleCollections) {
-            hash += graph.hashCode();
-        }
-        hash *= baseTripleCollections[0].hashCode();
-        return hash;
-    }
-
-    @Override
-    public ReadWriteLock getLock() {
-        return readWriteLock;
-    }
-    private ReadWriteLock readWriteLock = new ReadWriteLock() {
-
-        @Override
-        public Lock readLock() {
-            return readLock;
-        }
-
-        @Override
-        public Lock writeLock() {
-            return writeLock;
-        }
-    };
-
-    private Lock getPartialReadLock(int startPos) {
-        ArrayList<Lock> resultList = new ArrayList<Lock>();
-        for (int i = startPos; i < baseTripleCollections.length; i++) {
-            Graph graph = baseTripleCollections[i];
-
-            final Lock lock = graph.getLock().readLock();
-            resultList.add(lock);
-        }
-        return new UnionLock(resultList.toArray(new Lock[resultList.size()]));
-    }
-
-    private Lock createWriteLock() {
-        Lock partialReadLock = getPartialReadLock(1);
-
-        Lock baseWriteLock
-                = (baseTripleCollections[0]).getLock().writeLock();
-        return new UnionLock(baseWriteLock, partialReadLock);
-
-    }
-
-    ;
-
-
-    private static class UnionLock implements Lock {
-
-        Lock[] locks;
-
-        public UnionLock(Lock... locks) {
-            this.locks = locks;
-        }
-
-        @Override
-        public void lock() {
-            boolean isLocked = false;
-            while (!isLocked) {
-                try {
-                    isLocked = tryLock(10000, TimeUnit.NANOSECONDS);
-                } catch (InterruptedException ex) {
-
-                }
-            }
-        }
-
-        @Override
-        public void lockInterruptibly() throws InterruptedException {
-            Set<Lock> aquiredLocks = new HashSet<Lock>();
-            try {
-                for (Lock lock : locks) {
-                    lock.lockInterruptibly();
-                    aquiredLocks.add(lock);
-                }
-            } catch (InterruptedException e) {
-                for (Lock lock : aquiredLocks) {
-                    lock.unlock();
-                }
-                throw e;
-            }
-        }
-
-        @Override
-        public boolean tryLock() {
-            Set<Lock> aquiredLocks = new HashSet<Lock>();
-            for (Lock lock : locks) {
-                if (!lock.tryLock()) {
-                    for (Lock aquiredLock : aquiredLocks) {
-                        aquiredLock.unlock();
-                    }
-                    return false;
-                }
-                aquiredLocks.add(lock);
-            }
-            return true;
-        }
-
-        @Override
-        public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
-            Set<Lock> aquiredLocks = new HashSet<Lock>();
-            long timeInNanos = unit.convert(time, TimeUnit.NANOSECONDS);
-            long startTime = System.nanoTime();
-            try {
-                for (Lock lock : locks) {
-                    if (!lock.tryLock((timeInNanos + startTime) - System.nanoTime(),
-                            TimeUnit.NANOSECONDS)) {
-                        for (Lock aquiredLock : aquiredLocks) {
-                            aquiredLock.unlock();
-                        }
-                        return false;
-                    }
-                    aquiredLocks.add(lock);
-                }
-            } catch (InterruptedException e) {
-                for (Lock lock : aquiredLocks) {
-                    lock.unlock();
-                }
-                throw e;
-            }
-            return true;
-        }
-
-        @Override
-        public void unlock() {
-            for (Lock lock : locks) {
-                lock.unlock();
-            }
-        }
-
-        @Override
-        public Condition newCondition() {
-            throw new UnsupportedOperationException("Conditions not supported.");
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java
deleted file mode 100644
index 3892811..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2015 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.WatchableGraph;
-import org.apache.commons.rdf.event.FilterTriple;
-import org.apache.commons.rdf.event.GraphListener;
-
-/**
- *
- * @author developer
- */
-public class UnionWatchableGraph extends UnionGraph implements WatchableGraph {
-    
-    public UnionWatchableGraph(WatchableGraph... baseTripleCollections) {
-        super(baseTripleCollections);
-    }
-        @Override
-    public void addGraphListener(GraphListener listener, FilterTriple filter) {
-        for (Graph graph : baseTripleCollections) {
-            ((WatchableGraph)graph).addGraphListener(listener, filter);
-        }
-    }
-
-    @Override
-    public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
-        for (Graph graph : baseTripleCollections) {
-            ((WatchableGraph)graph).addGraphListener(listener, filter, delay);
-        }
-    }
-
-    @Override
-    public void removeGraphListener(GraphListener listener) {
-        for (Graph graph : baseTripleCollections) {
-            ((WatchableGraph)graph).removeGraphListener(listener);
-        }
-    }
-
-    
-}


[03/14] clerezza git commit: CLEREZZA-966: moved rdf.utils into the hierarchy

Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
new file mode 100644
index 0000000..8a1365f
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
@@ -0,0 +1,722 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import org.apache.commons.rdf.impl.*;
+import org.apache.commons.rdf.impl.utils.*;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+
+import java.util.*;
+import java.util.concurrent.locks.Lock;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.commons.rdf.*;
+
+/**
+ * This class represents a node in the context of a graph. It provides
+ * utility methods to explore and modify its neighbourhood. The method
+ * modifying the graph will throw an {@link UnsupportedOperationException}
+ * it the underlying Graph in immutable (i.e. is a {@link ImmutableGraph}.
+ *
+ * @since 0.2
+ * @author reto, mir
+ */
+public class GraphNode {
+
+    private final RdfTerm resource;
+    private final Graph graph;
+
+    /**
+     * Create a GraphNode representing resource within graph.
+     *
+     * @param resource the resource this GraphNode represents
+     * @param graph the Graph that describes the resource
+     */
+    public GraphNode(RdfTerm resource, Graph graph) {
+        if (resource == null) {
+            throw new IllegalArgumentException("resource may not be null");
+        }
+        if (graph == null) {
+            throw new IllegalArgumentException("graph may not be null");
+        }
+        this.resource = resource;
+        this.graph = graph;
+    }
+
+    /**
+     * Gets the graph the node represented by this instance is in
+     *
+     * @return the graph of this GraphNode
+     */
+    public Graph getGraph() {
+        return graph;
+    }
+
+    /**
+     * Gets the unwrapped node
+     *
+     * @return the node represented by this GraphNode
+     */
+    public RdfTerm getNode() {
+        return resource;
+    }
+
+    /**
+     * Deletes the context of a node
+     * @see getNodeContext()
+     */
+    public void deleteNodeContext() {
+        for (Triple triple : getNodeContext()) {
+            graph.remove(triple);
+        }
+    }
+
+    /**
+     * The context of a node are the triples containing a node
+     * as subject or object and recursively the context of the b-nodes in any
+     * of these statements.
+     *
+     * The triples in the ImmutableGraph returned by this method contain the same bnode
+     * instances as in the original graph.
+     *
+     * @return the context of the node represented by the instance
+     */
+    public ImmutableGraph getNodeContext() {
+        Lock l = readLock();
+        l.lock();
+        try {
+            final HashSet<RdfTerm> dontExpand = new HashSet<RdfTerm>();
+            dontExpand.add(resource);
+            if (resource instanceof Iri) {
+                return getContextOf((Iri) resource, dontExpand).getImmutableGraph();
+            }
+            return getContextOf(resource, dontExpand).getImmutableGraph();
+        } finally {
+            l.unlock();
+        }
+
+    }
+
+    private Graph getContextOf(Iri node, final Set<RdfTerm> dontExpand) {
+        final String uriPrefix = node.getUnicodeString()+'#';
+        return getContextOf(node, dontExpand, new Acceptor() {
+
+            @Override
+            public boolean expand(RdfTerm resource) {
+                if (resource instanceof BlankNode) {
+                    return true;
+                }
+                if (resource instanceof Iri) {
+                    return ((Iri)resource).getUnicodeString().startsWith(uriPrefix);
+                }
+                return false;
+            }
+        });
+    }
+
+    /**
+     * Returns the context of a <code>BlankNodeOrIri</code>
+     *
+     * @param node
+     * @param dontExpand a list of bnodes at which to stop expansion, if node
+     * is a BlankNode it should be contained (potentially faster)
+     * @return the context of a node
+     */
+    private Graph getContextOf(RdfTerm node, final Set<RdfTerm> dontExpand) {
+        return getContextOf(node, dontExpand, new Acceptor() {
+
+            @Override
+            public boolean expand(RdfTerm resource) {
+                if (resource instanceof BlankNode) {
+                    return true;
+                }
+                return false;
+            }
+        });
+    }
+
+    private interface Acceptor {
+        boolean expand(RdfTerm resource);
+    }
+    private Graph getContextOf(RdfTerm node, final Set<RdfTerm> dontExpand, Acceptor acceptor) {
+        Graph result = new SimpleGraph();
+        if (node instanceof BlankNodeOrIri) {
+            Iterator<Triple> forwardProperties = graph.filter((BlankNodeOrIri) node, null, null);
+            while (forwardProperties.hasNext()) {
+                Triple triple = forwardProperties.next();
+                result.add(triple);
+                RdfTerm object = triple.getObject();
+                if (acceptor.expand(object) && !dontExpand.contains(object)) {
+                    dontExpand.add(object);
+                    result.addAll(getContextOf(object, dontExpand, acceptor));
+                }
+            }
+        }
+        Iterator<Triple> backwardProperties = graph.filter(null, null, node);
+        while (backwardProperties.hasNext()) {
+            Triple triple = backwardProperties.next();
+            result.add(triple);
+            BlankNodeOrIri subject = triple.getSubject();
+            if (acceptor.expand(subject) && !dontExpand.contains(subject)) {
+                dontExpand.add(subject);
+                result.addAll(getContextOf(subject, dontExpand, acceptor));
+            }
+        }
+        return result;
+    }
+
+    private <T> Iterator<T> getTypeSelectedObjects(Iri property, final Class<T> type) {
+        final Iterator<RdfTerm> objects = getObjects(property);
+        return new Iterator<T>() {
+
+            T next = prepareNext();
+
+            @Override
+            public boolean hasNext() {
+                return next != null;
+            }
+
+            @Override
+            public T next() {
+                T result = next;
+                next = prepareNext();
+                return result;
+            }
+
+            @Override
+            public void remove() {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            private T prepareNext() {
+                while (objects.hasNext()) {
+                    RdfTerm nextObject = objects.next();
+                    if (type.isAssignableFrom(nextObject.getClass())) {
+                        return (T) nextObject;
+                    }
+                }
+                return null;
+            }
+        };
+    }
+
+    public Iterator<Literal> getLiterals(Iri property) {
+        final Iterator<RdfTerm> objects = getObjects(property);
+        return new Iterator<Literal>() {
+
+            Literal next = prepareNext();
+
+            @Override
+            public boolean hasNext() {
+                return next != null;
+            }
+
+            @Override
+            public Literal next() {
+                Literal result = next;
+                next = prepareNext();
+                return result;
+            }
+
+            @Override
+            public void remove() {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            private Literal prepareNext() {
+                while (objects.hasNext()) {
+                    RdfTerm nextObject = objects.next();
+                    if (nextObject instanceof Literal) {
+                        return (Literal) nextObject;
+                    }
+                }
+                return null;
+            }
+        };
+    }
+
+    /**
+     * Count the number of triples in the underlying triple-collection
+     * with this node as subject and a specified property as predicate.
+     *
+     * @param property the property to be examined
+     * @return the number of triples in the underlying triple-collection
+     *        which meet the specified condition
+     */
+    public int countObjects(Iri property) {
+        return countTriples(graph.filter((BlankNodeOrIri) resource, property, null));
+    }
+
+    private int countTriples(final Iterator<Triple> triples) {
+        int count = 0;
+        while (triples.hasNext()) {
+            triples.next();
+            count++;
+        }
+        return count;
+    }
+
+    /**
+     * Get the objects of statements with this node as subject and a specified
+     * property as predicate.
+     *
+     * @param property the property
+     * @return
+     */
+    public Iterator<RdfTerm> getObjects(Iri property) {
+        if (resource instanceof BlankNodeOrIri) {
+            final Iterator<Triple> triples = graph.filter((BlankNodeOrIri) resource, property, null);
+            return new Iterator<RdfTerm>() {
+
+                @Override
+                public boolean hasNext() {
+                    return triples.hasNext();
+                }
+
+                @Override
+                public RdfTerm next() {
+                    final Triple triple = triples.next();
+                    if (triple != null) {
+                        return triple.getObject();
+                    } else {
+                        return null;
+                    }
+                }
+
+                @Override
+                public void remove() {
+                    throw new UnsupportedOperationException("Not supported yet.");
+                }
+            };
+        } else {
+            return new Iterator<RdfTerm>() {
+
+                @Override
+                public boolean hasNext() {
+                    return false;
+                }
+
+                @Override
+                public RdfTerm next() {
+                    return null;
+                }
+
+                @Override
+                public void remove() {
+                    throw new UnsupportedOperationException("Not supported yet.");
+                }
+            };
+        }
+    }
+
+    /**
+     * Checks wether this node has the given property with the given value.
+     * If the given value is null, then it is checked if this node has the
+     * specified property regardless of its value.
+     *
+     * @param property
+     * @param object
+     * @return true if the node represented by this object is the subject of a
+     *         statement with the given prediate and object, false otherwise
+     */
+    public boolean hasProperty(Iri property, RdfTerm object) {
+        Lock l = readLock();
+        l.lock();
+        try {
+            Iterator<RdfTerm> objects = getObjects(property);
+            if (object == null) {
+                return objects.hasNext();
+            }
+            while (objects.hasNext()) {
+                if (objects.next().equals(object)) {
+                    return true;
+                }
+            }
+            return false;
+        } finally {
+            l.unlock();
+        }
+    }
+
+    /**
+     * Count the number of triples in the underlying triple-collection
+     * with this node as object and a specified property as predicate.
+     *
+     * @param property the property to be examined
+     * @return the number of triples in the underlying triple-collection
+     *        which meet the specified condition
+     */
+    public int countSubjects(Iri property) {
+        Lock l = readLock();
+        l.lock();
+        try {
+            return countTriples(graph.filter(null, property, resource));
+        } finally {
+            l.unlock();
+        }
+    }
+
+    /**
+     * Get the subjects of statements with this node as object and a specified
+     * property as predicate.
+     *
+     * @param property the property
+     * @return
+     */
+    public Iterator<BlankNodeOrIri> getSubjects(Iri property) {
+        final Iterator<Triple> triples = graph.filter(null, property, resource);
+        return new Iterator<BlankNodeOrIri>() {
+
+            @Override
+            public boolean hasNext() {
+                return triples.hasNext();
+            }
+
+            @Override
+            public BlankNodeOrIri next() {
+                return triples.next().getSubject();
+            }
+
+            @Override
+            public void remove() {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+        };
+    }
+
+    public Iterator<Iri> getIriObjects(Iri property) {
+        return getTypeSelectedObjects(property, Iri.class);
+
+    }
+
+    /**
+     * Get all available properties as an {@link Iterator}<{@link Iri}>.
+     * You can use <code>getObjects(Iri property)</code> to get the values of
+     * each property
+     *
+     * @return an iterator over properties of this node
+     */
+    public Iterator<Iri> getProperties() {
+        if (resource instanceof BlankNodeOrIri) {
+            final Iterator<Triple> triples = graph.filter((BlankNodeOrIri) resource, null, null);
+            return getUniquePredicates(triples);
+        } else {
+            return new Iterator<Iri>() {
+
+                @Override
+                public boolean hasNext() {
+                    return false;
+                }
+
+                @Override
+                public Iri next() {
+                    return null;
+                }
+
+                @Override
+                public void remove() {
+                    throw new UnsupportedOperationException("Not supported yet.");
+                }
+            };
+        }
+    }
+
+    /**
+     * Get all inverse properties as an {@link Iterator}<{@link Iri}>.
+     * You can use <code>getSubject(Iri property)</code> to get the values of
+     * each inverse property
+     *
+     * @return an iterator over properties pointing to this node
+     */
+    public Iterator<Iri> getInverseProperties() {
+        final Iterator<Triple> triples = graph.filter(null, null, resource);
+        return getUniquePredicates(triples);
+    }
+
+    /**
+     *
+     * @param triples
+     * @returnan {@link Iterator}<{@link Iri}> containing the predicates from
+     * an {@link Iterator}<{@link Triple}>
+     */
+    private Iterator<Iri> getUniquePredicates(final Iterator<Triple> triples) {
+        final Set<Iri> resultSet = new HashSet<Iri>();
+        while (triples.hasNext()) {
+            resultSet.add(triples.next().getPredicate());
+        }
+        return resultSet.iterator();
+    }
+
+    /**
+     * Adds a property to the node with the specified predicate and object
+     *
+     * @param predicate
+     * @param object
+     */
+    public void addProperty(Iri predicate, RdfTerm object) {
+        if (resource instanceof BlankNodeOrIri) {
+            graph.add(new TripleImpl((BlankNodeOrIri) resource, predicate, object));
+        } else {
+            throw new RuntimeException("Literals cannot be the subject of a statement");
+        }
+    }
+
+
+    /**
+     * Coverts the value into a typed literals and sets it as object of the
+     * specified property
+     *
+     * @param property the predicate of the triple to be created
+     * @param value the value of the typed literal object
+     */
+    public void addPropertyValue(Iri property, Object value) {
+        addProperty(property,
+                LiteralFactory.getInstance().createTypedLiteral(value));
+    }
+
+    /**
+     * Adds a property to the node with the inverse of the specified predicate and object
+     * In other words <code>subject</code> will be related via the property <code>relation</code> to this node.
+     *
+     * @param predicate
+     * @param subject
+     */
+    public void addInverseProperty(Iri predicate, RdfTerm subject) {
+        if (subject instanceof BlankNodeOrIri) {
+            graph.add(new TripleImpl((BlankNodeOrIri) subject, predicate, resource));
+        } else {
+            throw new RuntimeException("Literals cannot be the subject of a statement");
+        }
+    }
+
+
+    /**
+     * creates and returns an <code>RdfList</code> for the node and
+     * Graph represented by this object.
+     *
+     * @return a List to easy access the rdf:List represented by this node
+     */
+    public List<RdfTerm> asList() {
+        if (resource instanceof BlankNodeOrIri) {
+            return new RdfList((BlankNodeOrIri) resource, graph);
+        } else {
+            throw new RuntimeException("Literals cannot be the subject of a List");
+        }
+    }
+
+    /**
+     * Deletes all statement with the current node as subject and the specified
+     * predicate
+     *
+     * @param predicate
+     */
+    public void deleteProperties(Iri predicate) {
+        if (resource instanceof BlankNodeOrIri) {
+            Iterator<Triple> tripleIter = graph.filter((BlankNodeOrIri) resource, predicate, null);
+            Collection<Triple> toDelete = new ArrayList<Triple>();
+            while (tripleIter.hasNext()) {
+                Triple triple = tripleIter.next();
+                toDelete.add(triple);
+            }
+            for (Triple triple : toDelete) {
+                graph.remove(triple);
+            }
+        }
+    }
+
+    /**
+     * Delete property to the node with the specified predicate and object
+     *
+     * @param predicate
+     * @param object
+     */
+    public void deleteProperty(Iri predicate, RdfTerm object) {
+        if (resource instanceof BlankNodeOrIri) {
+            graph.remove(new TripleImpl((BlankNodeOrIri) resource, predicate, object));
+        }
+    }
+
+    @Override
+    public String toString() {
+        return resource.toString();
+    }
+
+    /**
+     * Replaces the graph node resouce with the specified <code>BlankNodeOrIri</code>.
+     * The resource is only replaced where it is either subject or object.
+     * @param replacement
+     * @return a GraphNode representing the replecement node
+     */
+    public GraphNode replaceWith(BlankNodeOrIri replacement) {
+        return replaceWith(replacement, false);
+    }
+
+    /**
+     * Replaces the graph node resouce with the specified <code>BlankNodeOrIri</code>.
+     * Over the boolean <code>checkPredicate</code> it can be specified if the
+     * resource should also be replaced where it is used as predicate.
+     * @param replacement
+     * @param checkPredicates
+     * @return a GraphNode representing the replecement node
+     */
+    public GraphNode replaceWith(BlankNodeOrIri replacement, boolean checkPredicates) {
+        Graph newTriples = new SimpleGraph();
+        if (!(resource instanceof Literal)) {
+            Iterator<Triple> subjectTriples = graph.filter((BlankNodeOrIri) resource, null,
+                    null);
+            while (subjectTriples.hasNext()) {
+                Triple triple = subjectTriples.next();
+                Triple newTriple = new TripleImpl(replacement, triple.getPredicate(),
+                        triple.getObject());
+                subjectTriples.remove();
+                newTriples.add(newTriple);
+            }
+            graph.addAll(newTriples);
+            newTriples.clear();
+        }
+
+        Iterator<Triple> objectTriples = graph.filter(null, null, resource);
+        while (objectTriples.hasNext()) {
+            Triple triple = objectTriples.next();
+            Triple newTriple = new TripleImpl(triple.getSubject(),
+                    triple.getPredicate(), replacement);
+            objectTriples.remove();
+            newTriples.add(newTriple);
+        }
+        graph.addAll(newTriples);
+        newTriples.clear();
+
+        if (checkPredicates && replacement instanceof Iri
+                && resource instanceof Iri) {
+            Iterator<Triple> predicateTriples = graph.filter(null,
+                    (Iri) resource, null);
+            while (predicateTriples.hasNext()) {
+                Triple triple = predicateTriples.next();
+                Triple newTriple = new TripleImpl(triple.getSubject(),
+                        (Iri) replacement, triple.getObject());
+                predicateTriples.remove();
+                newTriples.add(newTriple);
+            }
+            graph.addAll(newTriples);
+        }
+        return new GraphNode(replacement, graph);
+    }
+
+    /**
+     * Returns a iterator containing all objects of the triples where this
+     * graph node is the subject and has the specified property. The objects
+     * are returned as <code>GraphNode</code>s.
+     *
+     * @param property
+     * @return
+     */
+    public Iterator<GraphNode> getObjectNodes(Iri property) {
+        final Iterator<RdfTerm> objects = this.getObjects(property);
+        return new Iterator<GraphNode>() {
+
+            @Override
+            public boolean hasNext() {
+                return objects.hasNext();
+            }
+
+            @Override
+            public GraphNode next() {
+                RdfTerm object = objects.next();
+                return new GraphNode(object, graph);
+
+            }
+
+            @Override
+            public void remove() {
+                objects.remove();
+            }
+        };
+    }
+
+    /**
+     * Returns a iterator containing all subjects of the triples where this
+     * graph node is the object and has the specified property. The subjects
+     * are returned as <code>GraphNode</code>s.
+     *
+     * @param property
+     * @return
+     */
+    public Iterator<GraphNode> getSubjectNodes(Iri property) {
+        final Iterator<BlankNodeOrIri> subjects = this.getSubjects(property);
+        return new Iterator<GraphNode>() {
+
+            @Override
+            public boolean hasNext() {
+                return subjects.hasNext();
+            }
+
+            @Override
+            public GraphNode next() {
+                RdfTerm object = subjects.next();
+                return new GraphNode(object, graph);
+
+            }
+
+            @Override
+            public void remove() {
+                subjects.remove();
+            }
+        };
+    }
+
+    /**
+     *
+     * @param obj
+     * @return true if obj is an instance of the same class represening the same
+     * node in the same graph, subclasses may have different identity criteria.
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null || !(obj.getClass().equals(getClass()))) {
+            return false;
+        }
+        GraphNode other = (GraphNode) obj;
+        return getNode().equals(other.getNode())
+                && getGraph().equals(other.getGraph());
+    }
+
+    @Override
+    public int hashCode() {
+        return 13 * getNode().hashCode() + getGraph().hashCode();
+    }
+
+    /**
+     * @return a ReadLock if the underlying ImmutableGraph is a LockableGraph it returns its lock, otherwise null
+     */
+    public Lock readLock() {
+
+            return getGraph().getLock().readLock();
+
+    }
+
+    /**
+     *
+     * @return
+     */
+    public Lock writeLock() {
+
+            return (getGraph()).getLock().writeLock();
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java
new file mode 100644
index 0000000..dc3943b
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.rdf.utils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+
+/**
+ * Utility methods to manipulate <code>Graph</code>s
+ *
+ * @author reto
+ */
+public class GraphUtils {
+
+    /**
+     * Removes a subGraph from an Graph. The subGraph must match a subgraph of
+     * Graph so that for every node in <code>subGraph</code>
+     * each triple it appears in is also present in <code>mGraph</code>. Two
+     * bnodes are considered equals if their contexts (as returned by
+     * <code>GraphNode.getNodeContext</code> are equals.
+     *
+     * @param mGraph
+     * @param subGraph
+     * @throws org.apache.clerezza.rdf.utils.GraphUtils.NoSuchSubGraphException
+     */
+    public static void removeSubGraph(Graph mGraph, Graph subGraph)
+            throws NoSuchSubGraphException {
+        //point to triples of mGraph that are to be removed (if something is removed)
+        final Set<Triple> removingTriples = new HashSet<Triple>();
+        //we first check only the grounded triples and put the non-grounded in here:
+        final Graph unGroundedTriples = new SimpleGraph();
+        for (Triple triple : subGraph) {
+            if (isGrounded(triple)) {
+                if (!mGraph.contains(triple)) {
+                    throw new NoSuchSubGraphException();
+                }
+                removingTriples.add(triple);
+            } else {
+                unGroundedTriples.add(triple);
+            }
+        }
+
+        //we first remove the context of bnodes we find in object position
+        OBJ_BNODE_LOOP: while (true) {
+            final Triple triple = getTripleWithBlankNodeObject(unGroundedTriples);
+            if (triple == null) {
+                break;
+            }
+            final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples);
+            BlankNodeOrIri subject = triple.getSubject();
+            ImmutableGraph context = objectGN.getNodeContext();
+            Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null);
+            while (potentialIter.hasNext()) {
+                try {
+                    final Triple potentialTriple = potentialIter.next();
+                    BlankNode potentialMatch = (BlankNode)potentialTriple.getObject();
+                    final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
+                    if (potentialContext.equals(context)) {
+                        removingTriples.addAll(potentialContext);
+                        unGroundedTriples.removeAll(context);
+                        continue OBJ_BNODE_LOOP;
+                    }
+                } catch (ClassCastException e) {
+                    continue;
+                }
+            }
+            throw new NoSuchSubGraphException();
+        }
+        SUBJ_BNODE_LOOP: while (true) {
+            final Triple triple = getTripleWithBlankNodeSubject(unGroundedTriples);
+            if (triple == null) {
+                break;
+            }
+            final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples);
+            RdfTerm object = triple.getObject();
+            if (object instanceof BlankNode) {
+                object = null;
+            }
+            ImmutableGraph context = subjectGN.getNodeContext();
+            Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object);
+            while (potentialIter.hasNext()) {
+                try {
+                    final Triple potentialTriple = potentialIter.next();
+                    BlankNode potentialMatch = (BlankNode)potentialTriple.getSubject();
+                    final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
+                    if (potentialContext.equals(context)) {
+                        removingTriples.addAll(potentialContext);
+                        unGroundedTriples.removeAll(context);
+                        continue SUBJ_BNODE_LOOP;
+                    }
+                } catch (ClassCastException e) {
+                    continue;
+                }
+            }
+            throw new NoSuchSubGraphException();
+        }
+        mGraph.removeAll(removingTriples);
+    }
+
+    private static boolean isGrounded(Triple triple) {
+        if (triple.getSubject() instanceof BlankNode) {
+            return false;
+        }
+        if (triple.getObject() instanceof BlankNode) {
+            return false;
+        }
+        return true;
+    }
+
+    /** retrun triples with a bnode only at object position
+     *
+     * @param triples
+     * @return
+     */
+    private static Triple getTripleWithBlankNodeObject(Graph triples) {
+        for (Triple triple : triples) {
+            if (triple.getSubject() instanceof BlankNode) {
+                continue;
+            }
+            if (triple.getObject() instanceof BlankNode) {
+                return triple;
+            }
+        }
+        return null;
+    }
+    private static Triple getTripleWithBlankNodeSubject(Graph triples) {
+        for (Triple triple : triples) {
+            if (triple.getSubject() instanceof BlankNode) {
+                return triple;
+            }
+        }
+        return null;
+    }
+
+    public static class NoSuchSubGraphException extends Exception {
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java
new file mode 100644
index 0000000..323c9f2
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+
+/**
+ * A utility class for Iri and String manipulations.
+ *
+ * @author tio
+ */
+public class IriUtil {
+
+    /**
+     * Strips #x00 - #x1F and #x7F-#x9F from a Unicode string
+     * @see <a href="http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference">
+     * http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference</a> and
+     * replaces all US-ASCII space character with a "+".
+     *
+     * @param inputChars
+     * @return the stripped string
+     * 
+     */
+    public static String stripNonIriChars(CharSequence inputChars) {
+
+        if (inputChars == null) {
+            return "";
+        }
+
+        StringBuffer buffer = new StringBuffer();
+
+        for (int i = 0; i < inputChars.length(); i++) {
+            char c = inputChars.charAt(i);
+
+            if (!isIllegal(c)) {
+                buffer.append(c);
+            }
+        }
+        return buffer.toString().replaceAll("\\s+", "+");
+    }
+
+    private static boolean isIllegal(char ch) {
+        if ((ch >= 0x7F) && (ch <= 0x9F)) {
+            return true;
+        }
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
new file mode 100644
index 0000000..db994e9
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
@@ -0,0 +1,358 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import java.io.FileOutputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.commons.rdf.Graph;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An implementation of an <code>java.util.List</code> backed by an RDF
+ * collection (rdf:List). The list allows modification that are reflected
+ * to the underlying <code>Graph</code>. It reads the data from the
+ * <code>Graph</code> when it is first needed, so changes to the
+ * Graph affecting the rdf:List may or may not have an effect on the
+ * values returned by instances of this class. For that reason only one
+ * instance of this class should be used for accessing an rdf:List of sublists
+ * thereof when the lists are being modified, having multiple lists exclusively
+ * for read operations (such as for immutable <code>Graph</code>s) is
+ * not problematic.
+ *
+ * @author rbn, mir
+ */
+public class RdfList extends AbstractList<RdfTerm> {
+
+    private static final Logger logger = LoggerFactory.getLogger(RdfList.class);
+
+    private final static Iri RDF_NIL =
+            new Iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
+    /**
+     * a list of the linked rdf:List elements in order
+     */
+    private List<BlankNodeOrIri> listList = new ArrayList<BlankNodeOrIri>();
+    private List<RdfTerm> valueList = new ArrayList<RdfTerm>();
+    private BlankNodeOrIri firstList;
+    private Graph tc;
+    private boolean totallyExpanded = false;
+
+    /**
+     * Get a list for the specified resource.
+     *
+     * If the list is modified using the created instance
+     * <code>listRdfTerm</code> will always be the first list.
+     *
+     * @param listRdfTerm
+     * @param tc
+     */
+    public RdfList(BlankNodeOrIri listRdfTerm, Graph tc) {
+        firstList = listRdfTerm;
+        this.tc = tc;
+
+    }
+
+    /**
+     * Get a list for the specified resource node.
+     *
+     * @param listNode
+     */
+    public RdfList(GraphNode listNode) {
+        this((BlankNodeOrIri)listNode.getNode(), listNode.getGraph());
+    }
+
+    /**
+     * Creates an empty RdfList by writing a triple
+     * "{@code listRdfTerm} owl:sameAs rdf.nil ." to {@code tc}.
+     *
+     * @param listRdfTerm
+     * @param tc
+     * @return    an empty rdf:List.
+     * @throws IllegalArgumentException
+     *        if the provided {@code  listRdfTerm} is a non-empty rdf:List.
+     */
+    public static RdfList createEmptyList(BlankNodeOrIri listRdfTerm, Graph tc)
+            throws IllegalArgumentException {
+
+        if (!tc.filter(listRdfTerm, RDF.first, null).hasNext()) {
+            RdfList list = new RdfList(listRdfTerm, tc);
+            list.tc.add(new TripleImpl(listRdfTerm, OWL.sameAs, RDF_NIL));
+            return list;
+        } else {
+            throw new IllegalArgumentException(listRdfTerm + "is a non-empty rdf:List.");
+        }
+    }
+
+    private void expandTill(int pos) {
+        if (totallyExpanded) {
+            return;
+        }
+        BlankNodeOrIri currentList;
+        if (listList.size() > 0) {
+            currentList = listList.get(listList.size()-1);
+        } else {
+            currentList = firstList;
+            if (!tc.filter(currentList, RDF.first, null).hasNext()) {
+                return;
+            }
+            listList.add(currentList);
+            valueList.add(getFirstEntry(currentList));
+        }
+        if (listList.size() >= pos) {
+            return;
+        }
+        while (true) {                
+            currentList = getRest(currentList);
+            if (currentList.equals(RDF_NIL)) {
+                totallyExpanded = true;
+                break;
+            }
+            if (listList.size() == pos) {
+                break;
+            }
+            valueList.add(getFirstEntry(currentList));
+            listList.add(currentList);
+        }
+    }
+
+
+
+    @Override
+    public RdfTerm get(int index) {
+        expandTill(index + 1);
+        return valueList.get(index);
+    }
+
+    @Override
+    public int size() {
+        expandTill(Integer.MAX_VALUE);        
+        return valueList.size();
+    }
+
+    @Override
+    public void add(int index, RdfTerm element) {
+        expandTill(index);
+        if (index == 0) {
+            //special casing to make sure the first list remains the same resource
+            if (listList.size() == 0) {
+                tc.remove(new TripleImpl(firstList, OWL.sameAs, RDF_NIL));
+                tc.add(new TripleImpl(firstList, RDF.rest, RDF_NIL));
+                tc.add(new TripleImpl(firstList, RDF.first, element));
+                listList.add(firstList);
+            } else {
+                tc.remove(new TripleImpl(listList.get(0), RDF.first, valueList.get(0)));
+                tc.add(new TripleImpl(listList.get(0), RDF.first, element));
+                addInRdfList(1, valueList.get(0));
+            }
+        } else {
+            addInRdfList(index, element);
+        }
+        valueList.add(index, element);
+    }
+    
+    /**
+     *
+     * @param index is > 0
+     * @param element
+     */
+    private void addInRdfList(int index, RdfTerm element) {
+        expandTill(index+1);
+        BlankNodeOrIri newList = new BlankNode() {
+        };
+        tc.add(new TripleImpl(newList, RDF.first, element));
+        if (index < listList.size()) {
+            tc.add(new TripleImpl(newList, RDF.rest, listList.get(index)));
+            tc.remove(new TripleImpl(listList.get(index - 1), RDF.rest, listList.get(index)));
+        } else {
+            tc.remove(new TripleImpl(listList.get(index - 1), RDF.rest, RDF_NIL));
+            tc.add(new TripleImpl(newList, RDF.rest, RDF_NIL));
+
+        }
+        tc.add(new TripleImpl(listList.get(index - 1), RDF.rest, newList));
+        listList.add(index, newList);
+    }
+
+    @Override
+    public RdfTerm remove(int index) {
+        //keeping the first list resource
+        tc.remove(new TripleImpl(listList.get(index), RDF.first, valueList.get(index)));
+        if (index == (listList.size() - 1)) {
+            tc.remove(new TripleImpl(listList.get(index), RDF.rest, RDF_NIL));    
+            if (index > 0) {
+                tc.remove(new TripleImpl(listList.get(index - 1), RDF.rest, listList.get(index)));
+                tc.add(new TripleImpl(listList.get(index - 1), RDF.rest, RDF_NIL));
+            } else {
+                tc.add(new TripleImpl(listList.get(index), OWL.sameAs, RDF_NIL));
+            }
+            listList.remove(index);
+        } else {
+            tc.add(new TripleImpl(listList.get(index), RDF.first, valueList.get(index+1)));
+            tc.remove(new TripleImpl(listList.get(index), RDF.rest, listList.get(index + 1)));
+            tc.remove(new TripleImpl(listList.get(index + 1), RDF.first, valueList.get(index + 1)));
+            if (index == (listList.size() - 2)) {
+                tc.remove(new TripleImpl(listList.get(index + 1), RDF.rest, RDF_NIL));
+                tc.add(new TripleImpl(listList.get(index), RDF.rest, RDF_NIL));
+            } else {
+                tc.remove(new TripleImpl(listList.get(index + 1), RDF.rest, listList.get(index + 2)));
+                tc.add(new TripleImpl(listList.get(index), RDF.rest, listList.get(index + 2)));
+            }
+            listList.remove(index+1);
+        }
+        return valueList.remove(index);
+    }
+
+    private BlankNodeOrIri getRest(BlankNodeOrIri list) {
+        return (BlankNodeOrIri) tc.filter(list, RDF.rest, null).next().getObject();
+    }
+
+    private RdfTerm getFirstEntry(final BlankNodeOrIri listRdfTerm) {
+        try {
+            return tc.filter(listRdfTerm, RDF.first, null).next().getObject();
+        } catch (final NullPointerException e) {
+            RuntimeException runtimeEx = AccessController.doPrivileged(new PrivilegedAction<RuntimeException>() {
+                @Override
+                public RuntimeException run(){
+                    try {
+                        final FileOutputStream fileOutputStream = new FileOutputStream("/tmp/broken-list.nt");
+                        final GraphNode graphNode = new GraphNode(listRdfTerm, tc);
+                        Serializer.getInstance().serialize(fileOutputStream, graphNode.getNodeContext(), SupportedFormat.N_TRIPLE);
+                        fileOutputStream.flush();
+                        logger.warn("GraphNode: " + graphNode);
+                        final Iterator<Iri> properties = graphNode.getProperties();
+                        while (properties.hasNext()) {
+                            logger.warn("available: " + properties.next());
+                        }
+                        return new RuntimeException("broken list " + listRdfTerm, e);
+                    } catch (Exception ex) {
+                        return new RuntimeException(ex);
+                    }
+
+                }
+            });
+            throw runtimeEx;
+        }
+    }
+
+    public BlankNodeOrIri getListRdfTerm() {
+        return firstList;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final RdfList other = (RdfList) obj;
+
+        if (!other.firstList.equals(this.firstList)) {
+            return false;
+        }
+
+        if (!other.tc.equals(this.tc)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return 17 * this.firstList.hashCode() + this.tc.hashCode();
+    }
+
+    /**
+     * Returns the rdf lists of which the specified <code>GraphNode</code> is
+     * an element of. Sublists of other lists are not returned.
+     *
+     * @param element
+     * @return
+     */
+    public static Set<RdfList> findContainingLists(GraphNode element) {
+        Set<GraphNode> listNodes = findContainingListNodes(element);
+        if (listNodes.isEmpty()) {
+            return null;
+        }
+
+        Set<RdfList> rdfLists = new HashSet<RdfList>();
+        for (Iterator<GraphNode> it = listNodes.iterator(); it.hasNext();) {
+            GraphNode listNode = it.next();
+            rdfLists.add(new RdfList(listNode));
+        }
+        return rdfLists;
+    }
+
+    /**
+     * Returns a set of <code>GraphNode</code>S which are the first list nodes (meaning
+     * they are not the beginning of a sublist) of the list containing the specified
+     * <code>GraphNode</code> as an element.
+     *
+     * @param element
+     * @return
+     */
+    public static Set<GraphNode> findContainingListNodes(GraphNode element) {
+        Iterator<GraphNode> partOfaListNodesIter = element.getSubjectNodes(RDF.first);
+        if (!partOfaListNodesIter.hasNext()) {
+            return null;
+        }
+        Set<GraphNode> listNodes = new HashSet<GraphNode>();
+
+        while (partOfaListNodesIter.hasNext()) {
+            listNodes.addAll(findAllListNodes(partOfaListNodesIter.next()));
+        }
+        return listNodes;
+    }
+    
+    private static Set<GraphNode> findAllListNodes(GraphNode listPart) {
+        Iterator<GraphNode> invRestNodesIter;
+        Set<GraphNode> listNodes = new HashSet<GraphNode>();
+        do {
+            invRestNodesIter = listPart.getSubjectNodes(RDF.rest);
+            if (invRestNodesIter.hasNext()) {
+                listPart = invRestNodesIter.next();
+                while (invRestNodesIter.hasNext()) {
+                    GraphNode graphNode = invRestNodesIter.next();
+                    listNodes.addAll(findAllListNodes(graphNode));
+                }
+            } else {
+                listNodes.add(listPart);
+                break;
+            }
+        } while (true);
+        return listNodes;
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
new file mode 100644
index 0000000..fef7e4b
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.rdf.utils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.ontologies.RDFS;
+
+/**
+ * Expands a GraphNode expanding SeeAlso-References of the node.
+ *
+ * @author reto
+ */
+public class SeeAlsoExpander {
+    /**
+     * using TcManger instead of TcProvider as this ensures LockableGraphs
+     */
+    private final TcManager tcManager;
+    public SeeAlsoExpander(TcManager tcManager) {
+        this.tcManager = tcManager;
+
+    }
+
+    /**
+     * expands a node dereferencing its rdfs:seeAlso references using the
+     * tcManager associated to this instance. If the added TripleCollections
+     * also associate rdfs:seeAlso properties to node this are expanded till
+     * the maximum recursion depth specified.
+     *
+     * @param node the node to be expanded
+     * @param recursion the maximum recursion depth
+     * @return a new GraphNode over the union of the original and all expansion graphs
+     */
+    public GraphNode expand(GraphNode node, int recursion) {
+        Set<Iri> alreadyVisited = new HashSet();
+        Set<Graph> resultTripleCollections = new HashSet<Graph>();
+        resultTripleCollections.add(node.getGraph());
+        for (Iri uriRef : expand(node, alreadyVisited, recursion)) {
+            try {
+                resultTripleCollections.add(tcManager.getGraph(uriRef));
+            } catch (NoSuchEntityException e) {
+                //ignore
+            }
+        }
+        return new GraphNode(node.getNode(),
+                new UnionGraph(resultTripleCollections.toArray(
+                new Graph[resultTripleCollections.size()])));
+
+    }
+
+    private Set<Iri> getSeeAlsoObjectUris(GraphNode node) {
+        Set<Iri> result = new HashSet<Iri>();
+        Lock l = node.readLock();
+        l.lock();
+        try {
+            Iterator<RdfTerm> objects = node.getObjects(RDFS.seeAlso);
+            while (objects.hasNext()) {
+                RdfTerm next = objects.next();
+                if (next instanceof Iri) {
+                    result.add((Iri)next);
+                }
+            }
+        } finally {
+            l.unlock();
+        }
+        return result;
+    }
+
+    private Set<Iri> expand(GraphNode node, Set<Iri> alreadyVisited, int recursion) {
+        Set<Iri> rdfSeeAlsoTargets = getSeeAlsoObjectUris(node);
+        Set<Iri> result = new HashSet<Iri>();
+        result.addAll(rdfSeeAlsoTargets);
+        recursion++;
+        if (recursion > 0) {
+            rdfSeeAlsoTargets.removeAll(alreadyVisited);
+            alreadyVisited.addAll(rdfSeeAlsoTargets);
+            for (Iri target : rdfSeeAlsoTargets) {
+                try {
+                    result.addAll(expand(new GraphNode(node.getNode(),
+                        tcManager.getGraph(target)), alreadyVisited, recursion));
+                } catch (NoSuchEntityException e) {
+                    //ignore
+                }
+            }
+        }
+        return result;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
new file mode 100644
index 0000000..8d0ea45
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import org.apache.commons.rdf.Graph;
+import org.apache.clerezza.rdf.utils.smushing.IfpSmusher;
+import org.apache.clerezza.rdf.utils.smushing.SameAsSmusher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A utility to smush equivalent resources. For greater flexibility use the 
+ * classes in the smushing package.
+ * 
+ * @author reto
+ */
+public class Smusher {
+
+    static final Logger log = LoggerFactory.getLogger(Smusher.class);
+
+    /**
+     * smush mGaph given the ontological facts. Currently it does only one step
+     * ifp smushin, i.e. only ifps are taken in account and only nodes that have
+     * the same node as ifp object in the orignal graph are equates. (calling
+     * the method a second time might lead to additional smushings.)
+     *
+     * @param mGraph
+     * @param tBox
+     */
+    public static void smush(Graph mGraph, Graph tBox) {
+        new IfpSmusher().smush(mGraph, tBox);
+    }
+
+    /**
+     * Smushes the specified graph adding owl:sameAs statements pointing to the new canonical IRI
+     * 
+     * @param mGraph
+     * @param owlSameStatements 
+     */
+    public static void sameAsSmush(Graph mGraph, Graph owlSameStatements) {
+        new SameAsSmusher().smush(mGraph, owlSameStatements, true);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java
new file mode 100644
index 0000000..a928f79
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.AbstractGraph;
+
+/**
+ *
+ * This class represents the union of multiple triple collections. A UnionGraph
+ * appears like a merge of the different graphs (see.
+ * http://www.w3.org/TR/rdf-mt/#graphdefs).
+ *
+ * @author hasan
+ */
+public class UnionGraph extends AbstractGraph {
+
+    protected Graph[] baseTripleCollections;
+    private Lock readLock;
+    private Lock writeLock;
+
+    /**
+     * Constructs a UnionGraph over the specified baseTripleCollections. Write
+     * and delete operations are forwarded to the first baseTripleCollections.
+     *
+     * @param baseTripleCollections the baseTripleCollections
+     */
+    public UnionGraph(Graph... baseTripleCollections) {
+        this.baseTripleCollections = baseTripleCollections;
+        readLock = getPartialReadLock(0);
+        writeLock = createWriteLock();
+    }
+
+    @Override
+    public int performSize() {
+        int size = 0;
+        for (Graph graph : baseTripleCollections) {
+            size += graph.size();
+        }
+        return size;
+    }
+
+    @Override
+    public Iterator<Triple> performFilter(final BlankNodeOrIri subject,
+            final Iri predicate, final RdfTerm object) {
+        if (baseTripleCollections.length == 0) {
+            return new HashSet<Triple>(0).iterator();
+        }
+        return new Iterator<Triple>() {
+
+            int currentBaseTC = 0;
+            Iterator<Triple> currentBaseIter = baseTripleCollections[0].filter(
+                    subject, predicate, object);
+            private Triple lastReturned;
+
+            @Override
+            public boolean hasNext() {
+                if (currentBaseIter.hasNext()) {
+                    return true;
+                }
+                if (currentBaseTC == baseTripleCollections.length - 1) {
+                    return false;
+                }
+                currentBaseTC++;
+                currentBaseIter = baseTripleCollections[currentBaseTC].filter(
+                        subject, predicate, object);
+                return hasNext();
+            }
+
+            @Override
+            public Triple next() {
+                lastReturned = hasNext() ? currentBaseIter.next() : null;
+                return lastReturned;
+            }
+
+            @Override
+            public void remove() {
+                if (lastReturned == null) {
+                    throw new IllegalStateException();
+                }
+                if (currentBaseTC == 0) {
+                    currentBaseIter.remove();
+                }
+                lastReturned = null;
+            }
+        };
+    }
+
+    @Override
+    public boolean add(Triple e) {
+        if (baseTripleCollections.length == 0) {
+            throw new RuntimeException("no base graph for adding triples");
+        }
+        return baseTripleCollections[0].add(e);
+    }
+
+    @Override
+    public boolean remove(Object e) {
+        if (baseTripleCollections.length == 0) {
+            throw new RuntimeException("no base graph for removing triples");
+        }
+        return baseTripleCollections[0].remove(e);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj.getClass().equals(getClass()))) {
+            return false;
+        }
+        UnionGraph other = (UnionGraph) obj;
+        Set<Graph> otherGraphs
+                = new HashSet(Arrays.asList(other.baseTripleCollections));
+        Set<Graph> thisGraphs
+                = new HashSet(Arrays.asList(baseTripleCollections));
+        return thisGraphs.equals(otherGraphs)
+                && baseTripleCollections[0].equals(other.baseTripleCollections[0]);
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 0;
+        for (Graph graph : baseTripleCollections) {
+            hash += graph.hashCode();
+        }
+        hash *= baseTripleCollections[0].hashCode();
+        return hash;
+    }
+
+    @Override
+    public ReadWriteLock getLock() {
+        return readWriteLock;
+    }
+    private ReadWriteLock readWriteLock = new ReadWriteLock() {
+
+        @Override
+        public Lock readLock() {
+            return readLock;
+        }
+
+        @Override
+        public Lock writeLock() {
+            return writeLock;
+        }
+    };
+
+    private Lock getPartialReadLock(int startPos) {
+        ArrayList<Lock> resultList = new ArrayList<Lock>();
+        for (int i = startPos; i < baseTripleCollections.length; i++) {
+            Graph graph = baseTripleCollections[i];
+
+            final Lock lock = graph.getLock().readLock();
+            resultList.add(lock);
+        }
+        return new UnionLock(resultList.toArray(new Lock[resultList.size()]));
+    }
+
+    private Lock createWriteLock() {
+        Lock partialReadLock = getPartialReadLock(1);
+
+        Lock baseWriteLock
+                = (baseTripleCollections[0]).getLock().writeLock();
+        return new UnionLock(baseWriteLock, partialReadLock);
+
+    }
+
+    ;
+
+
+    private static class UnionLock implements Lock {
+
+        Lock[] locks;
+
+        public UnionLock(Lock... locks) {
+            this.locks = locks;
+        }
+
+        @Override
+        public void lock() {
+            boolean isLocked = false;
+            while (!isLocked) {
+                try {
+                    isLocked = tryLock(10000, TimeUnit.NANOSECONDS);
+                } catch (InterruptedException ex) {
+
+                }
+            }
+        }
+
+        @Override
+        public void lockInterruptibly() throws InterruptedException {
+            Set<Lock> aquiredLocks = new HashSet<Lock>();
+            try {
+                for (Lock lock : locks) {
+                    lock.lockInterruptibly();
+                    aquiredLocks.add(lock);
+                }
+            } catch (InterruptedException e) {
+                for (Lock lock : aquiredLocks) {
+                    lock.unlock();
+                }
+                throw e;
+            }
+        }
+
+        @Override
+        public boolean tryLock() {
+            Set<Lock> aquiredLocks = new HashSet<Lock>();
+            for (Lock lock : locks) {
+                if (!lock.tryLock()) {
+                    for (Lock aquiredLock : aquiredLocks) {
+                        aquiredLock.unlock();
+                    }
+                    return false;
+                }
+                aquiredLocks.add(lock);
+            }
+            return true;
+        }
+
+        @Override
+        public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
+            Set<Lock> aquiredLocks = new HashSet<Lock>();
+            long timeInNanos = unit.convert(time, TimeUnit.NANOSECONDS);
+            long startTime = System.nanoTime();
+            try {
+                for (Lock lock : locks) {
+                    if (!lock.tryLock((timeInNanos + startTime) - System.nanoTime(),
+                            TimeUnit.NANOSECONDS)) {
+                        for (Lock aquiredLock : aquiredLocks) {
+                            aquiredLock.unlock();
+                        }
+                        return false;
+                    }
+                    aquiredLocks.add(lock);
+                }
+            } catch (InterruptedException e) {
+                for (Lock lock : aquiredLocks) {
+                    lock.unlock();
+                }
+                throw e;
+            }
+            return true;
+        }
+
+        @Override
+        public void unlock() {
+            for (Lock lock : locks) {
+                lock.unlock();
+            }
+        }
+
+        @Override
+        public Condition newCondition() {
+            throw new UnsupportedOperationException("Conditions not supported.");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java
new file mode 100644
index 0000000..3892811
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.clerezza.rdf.utils;
+
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.WatchableGraph;
+import org.apache.commons.rdf.event.FilterTriple;
+import org.apache.commons.rdf.event.GraphListener;
+
+/**
+ *
+ * @author developer
+ */
+public class UnionWatchableGraph extends UnionGraph implements WatchableGraph {
+    
+    public UnionWatchableGraph(WatchableGraph... baseTripleCollections) {
+        super(baseTripleCollections);
+    }
+        @Override
+    public void addGraphListener(GraphListener listener, FilterTriple filter) {
+        for (Graph graph : baseTripleCollections) {
+            ((WatchableGraph)graph).addGraphListener(listener, filter);
+        }
+    }
+
+    @Override
+    public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
+        for (Graph graph : baseTripleCollections) {
+            ((WatchableGraph)graph).addGraphListener(listener, filter, delay);
+        }
+    }
+
+    @Override
+    public void removeGraphListener(GraphListener listener) {
+        for (Graph graph : baseTripleCollections) {
+            ((WatchableGraph)graph).removeGraphListener(listener);
+        }
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java
new file mode 100644
index 0000000..4b0a4dc
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.rdf.utils;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.locks.ReadWriteLock;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.AbstractGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleImmutableGraph;
+
+/**
+ * This wrapps a Triplecollection changing a prefix for the Iris contained
+ * in subject or object position.
+ *
+ * Currently it only supports read opearations.
+ *
+ * @author reto
+ */
+public class UriMutatingGraph implements Graph {
+
+    private final Graph base;
+    private final String sourcePrefix;
+    private final String targetPrefix;
+    private final int sourcePrefixLength;
+    private final int targetPrefixLength;
+
+    public UriMutatingGraph(Graph base, String sourcePrefix,
+            String targetPrefix) {
+        this.base = base;
+        this.sourcePrefix = sourcePrefix;
+        sourcePrefixLength= sourcePrefix.length();
+        this.targetPrefix = targetPrefix;
+        targetPrefixLength= targetPrefix.length();
+    }
+
+    private <R extends RdfTerm> R toTargetRdfTerm(final R sourceRdfTerm) {
+        if (sourceRdfTerm instanceof Iri) {
+            final Iri sourceIri = (Iri) sourceRdfTerm;
+            if (sourceIri.getUnicodeString().startsWith(sourcePrefix)) {
+                final String uriRest = sourceIri.getUnicodeString()
+                        .substring(sourcePrefixLength);
+                return (R) new Iri(targetPrefix+uriRest);
+            }
+        }
+        return sourceRdfTerm;            
+    }
+
+    private Triple toTargetTriple(Triple triple) {
+        if (triple == null) {
+            return null;
+        }
+        return new TripleImpl(toTargetRdfTerm(triple.getSubject()),
+                triple.getPredicate(), toTargetRdfTerm(triple.getObject()));
+    }
+
+    private <R extends RdfTerm> R toSourceRdfTerm(final R targetRdfTerm) {
+        if (targetRdfTerm instanceof Iri) {
+            final Iri sourceIri = (Iri) targetRdfTerm;
+            if (sourceIri.getUnicodeString().startsWith(targetPrefix)) {
+                final String uriRest = sourceIri.getUnicodeString()
+                        .substring(targetPrefixLength);
+                return (R) new Iri(sourcePrefix+uriRest);
+            }
+        }
+        return targetRdfTerm;
+    }
+
+    private Triple toSourceTriple(Triple triple) {
+        if (triple == null) {
+            return null;
+        }
+        return new TripleImpl(toSourceRdfTerm(triple.getSubject()),
+                triple.getPredicate(), toSourceRdfTerm(triple.getObject()));
+    }
+
+    @Override
+    public Iterator<Triple> filter(BlankNodeOrIri subject, Iri predicate, RdfTerm object) {
+        final Iterator<Triple> baseIter = base.filter(toSourceRdfTerm(subject),
+                predicate, toSourceRdfTerm(object));
+        return new WrappedIteraror(baseIter);
+
+
+    }
+
+
+    @Override
+    public int size() {
+        return base.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return base.isEmpty();
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        return base.contains(toSourceTriple((Triple)o));
+    }
+
+    @Override
+    public Iterator<Triple> iterator() {
+        return filter(null, null, null);
+    }
+
+    @Override
+    public Object[] toArray() {
+        Object[] result = base.toArray();
+        for (int i = 0; i < result.length; i++) {
+            Triple triple = (Triple) result[i];
+            result[i] = toTargetTriple(triple);
+        }
+        return result;
+    }
+
+    @Override
+    public <T> T[] toArray(T[] a) {
+        T[] result = base.toArray(a);
+        for (int i = 0; i < result.length; i++) {
+            Triple triple = (Triple) result[i];
+            result[i] = (T) toTargetTriple(triple);
+        }
+        return result;
+    }
+
+    @Override
+    public boolean add(Triple e) {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+        for (Object object : c) {
+            if (!contains(object)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Triple> c) {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    @Override
+    public void clear() {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        return new SimpleImmutableGraph(this);
+    }
+
+    @Override
+    public ReadWriteLock getLock() {
+        return base.getLock();
+    }
+
+    class WrappedIteraror implements Iterator<Triple>{
+        private final Iterator<Triple> baseIter;
+
+        private WrappedIteraror(Iterator<Triple> baseIter) {
+            this.baseIter = baseIter;
+        }
+
+        @Override
+        public boolean hasNext() {
+            return baseIter.hasNext();
+        }
+
+        @Override
+        public Triple next() {
+            return toTargetTriple(baseIter.next());
+        }
+
+        @Override
+        public void remove() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
new file mode 100644
index 0000000..03c73a5
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
@@ -0,0 +1,51 @@
+package org.apache.clerezza.rdf.utils.graphnodeprovider;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import org.apache.commons.rdf.Iri;
+import org.apache.clerezza.rdf.utils.GraphNode;
+
+/**
+ * A service that returns a GraphNode for a specified named resource, the
+ * returned GraphNode has as BaseGraph the ContentGraph provided by the
+ * ContentGraphProvider and the for remote uris the Graphs they dereference to
+ * and for local URIs with a path-section starting with /user/{username}/ the
+ * local-public-graph of that user.
+ */
+public interface GraphNodeProvider {
+
+    /**
+     * Get a GraphNode for the specified resource, see class comments for
+     * details.
+     */
+    GraphNode get(Iri uriRef);
+
+    /**
+     * Get a GraphNode for the specified resource, The resource is assumed to be
+     * local, i.e. the method behaves like get(Iri) for a Uri with an
+     * authority section contained in the Set retuned by
+     * <code>org.apache.clerezza.platform.config.PlatformConfig#getBaseUris()</code>
+     */
+    GraphNode getLocal(Iri uriRef);
+
+    /**
+     * return true iff getLocal(uriRef).getNodeContext.size > 0
+     */
+    boolean existsLocal(Iri uriRef);
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
----------------------------------------------------------------------
diff --git a/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
new file mode 100644
index 0000000..1841cd1
--- /dev/null
+++ b/rdf/utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.clerezza.rdf.utils.smushing;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.OWL;
+
+/**
+ *
+ * @author Reto
+ */
+public class BaseSmusher {
+
+    /**
+     * Smushes the resources in mGraph that belong to the same set in equivalenceSets,
+     * i.e. it adds all properties to one of the resources in the equivalence set.
+     * 
+     * Optionally owl:sameAs statement are added that point from the IRIs that 
+     * no longer have properties to the one with properties. If addOwlSameAs
+     * is false the IRIs will just disappear from the graph.
+     * 
+     * @param mGraph the graph to smush
+     * @param equivalenceSets sets of equivalent resources
+     * @param addOwlSameAs whether owl:sameAs statements should be added
+     */
+    public void smush(Graph mGraph, Set<Set<BlankNodeOrIri>> equivalenceSets, boolean addOwlSameAs) {
+        Map<BlankNodeOrIri, BlankNodeOrIri> current2ReplacementMap = new HashMap<BlankNodeOrIri, BlankNodeOrIri>();
+        final Graph owlSameAsGraph = new SimpleGraph();
+        for (Set<BlankNodeOrIri> equivalenceSet : equivalenceSets) {
+            final BlankNodeOrIri replacement = getReplacementFor(equivalenceSet, owlSameAsGraph);
+            for (BlankNodeOrIri current : equivalenceSet) {
+                if (!current.equals(replacement)) {
+                    current2ReplacementMap.put(current, replacement);
+                }
+            }
+        }
+        final Set<Triple> newTriples = new HashSet<Triple>();
+        Lock l = mGraph.getLock().writeLock();
+        l.lock();
+        try {
+            for (Iterator<Triple> it = mGraph.iterator(); it.hasNext();) {
+                final Triple triple = it.next();
+                final BlankNodeOrIri subject = triple.getSubject();
+                BlankNodeOrIri subjectReplacement = current2ReplacementMap.get(subject);
+                final RdfTerm object = triple.getObject();
+                @SuppressWarnings(value = "element-type-mismatch")
+                RdfTerm objectReplacement = current2ReplacementMap.get(object);
+                if ((subjectReplacement != null) || (objectReplacement != null)) {
+                    it.remove();
+                    if (subjectReplacement == null) {
+                        subjectReplacement = subject;
+                    }
+                    if (objectReplacement == null) {
+                        objectReplacement = object;
+                    }
+                    newTriples.add(new TripleImpl(subjectReplacement, triple.getPredicate(), objectReplacement));
+                }
+            }
+            for (Triple triple : newTriples) {
+                mGraph.add(triple);
+            }
+            mGraph.addAll(owlSameAsGraph);
+        } finally {
+            l.unlock();
+        }
+    }
+    
+    private BlankNodeOrIri getReplacementFor(Set<BlankNodeOrIri> equivalenceSet, 
+            Graph owlSameAsGraph) {
+        final Set<Iri> uriRefs = new HashSet<Iri>();
+        for (BlankNodeOrIri nonLiteral : equivalenceSet) {
+            if (nonLiteral instanceof Iri) {
+                uriRefs.add((Iri) nonLiteral);
+            }
+        }
+        switch (uriRefs.size()) {
+            case 1:
+                return uriRefs.iterator().next();
+            case 0:
+                return new BlankNode();
+        }
+        final Iri preferedIri = getPreferedIri(uriRefs);
+        final Iterator<Iri> uriRefIter = uriRefs.iterator();
+        while (uriRefIter.hasNext()) {
+            Iri uriRef = uriRefIter.next();
+            if (!uriRef.equals(preferedIri)) {
+                owlSameAsGraph.add(new TripleImpl(uriRef, OWL.sameAs, preferedIri));
+            }
+        }
+        return preferedIri;
+    }
+
+    
+    /**
+     * Returns a prefered IRI for the IRIs in a set. Typically and in the
+     * default implementation the IRI will be one of the set. Note however that 
+     * subclass implementations may also return another IRI to be used.
+     * 
+     * @param uriRefs
+     * @return 
+     */
+    protected Iri getPreferedIri(Set<Iri> uriRefs) {
+        final Iterator<Iri> uriRefIter = uriRefs.iterator();
+        //instead of an arbitrary one we might either decide lexicographically
+        //or look at their frequency in mGraph
+        return uriRefIter.next();
+    }
+    
+}


[11/14] clerezza git commit: CLEREZZA-966: moved jena.tdb.storage into the hierarchy

Posted by re...@apache.org.
CLEREZZA-966: moved jena.tdb.storage into the hierarchy

Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/dac431ca
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/dac431ca
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/dac431ca

Branch: refs/heads/rdf-commons
Commit: dac431ca927bdf9a17461976876b9622631309a9
Parents: 0a84a39
Author: Reto Gmuer <re...@apache.org>
Authored: Sun Mar 22 18:00:22 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Sun Mar 22 18:00:22 2015 +0000

----------------------------------------------------------------------
 pom.xml                                         |   1 -
 provisioning/rdf/pom.xml                        |   1 +
 rdf.jena.tdb.storage/LICENSE                    | 201 ------
 rdf.jena.tdb.storage/pom.xml                    | 112 ---
 .../jena/tdb/internals/DatasetLockedMGraph.java |  46 --
 .../rdf/jena/tdb/internals/ModelGraph.java      | 149 ----
 .../rdf/jena/tdb/internals/Symbols.java         |  22 -
 .../rdf/jena/tdb/internals/UriRefSet.java       |  62 --
 .../rdf/jena/tdb/storage/BaseTdbTcProvider.java | 110 ---
 .../tdb/storage/SingleTdbDatasetTcProvider.java | 717 -------------------
 .../rdf/jena/tdb/storage/TdbTcProvider.java     | 434 -----------
 ....clerezza.rdf.core.access.WeightedTcProvider |   1 -
 .../OSGI-INF/metatype/metatype.properties       |  47 --
 .../MultiThreadedSingleTdbDatasetTest.java      | 261 -------
 .../rdf/jena/tdb/storage/MultiThreadedTest.java | 143 ----
 .../tdb/storage/MultiThreadedTestSingleTdb.java | 150 ----
 .../tdb/storage/SingleTdbDatasetMGraphTest.java |  56 --
 .../storage/SingleTdbDatasetTcProviderTest.java | 168 -----
 .../rdf/jena/tdb/storage/TdbMGraphTest.java     | 107 ---
 .../rdf/jena/tdb/storage/TdbTcProviderTest.java |  61 --
 rdf/jena/pom.xml                                |   3 +-
 rdf/jena/tdb.storage/LICENSE                    | 201 ++++++
 rdf/jena/tdb.storage/pom.xml                    | 112 +++
 .../jena/tdb/internals/DatasetLockedMGraph.java |  46 ++
 .../rdf/jena/tdb/internals/ModelGraph.java      | 149 ++++
 .../rdf/jena/tdb/internals/Symbols.java         |  22 +
 .../rdf/jena/tdb/internals/UriRefSet.java       |  62 ++
 .../rdf/jena/tdb/storage/BaseTdbTcProvider.java | 110 +++
 .../tdb/storage/SingleTdbDatasetTcProvider.java | 717 +++++++++++++++++++
 .../rdf/jena/tdb/storage/TdbTcProvider.java     | 434 +++++++++++
 ....clerezza.rdf.core.access.WeightedTcProvider |   1 +
 .../OSGI-INF/metatype/metatype.properties       |  47 ++
 .../MultiThreadedSingleTdbDatasetTest.java      | 261 +++++++
 .../rdf/jena/tdb/storage/MultiThreadedTest.java | 143 ++++
 .../tdb/storage/MultiThreadedTestSingleTdb.java | 150 ++++
 .../tdb/storage/SingleTdbDatasetMGraphTest.java |  56 ++
 .../storage/SingleTdbDatasetTcProviderTest.java | 168 +++++
 .../rdf/jena/tdb/storage/TdbMGraphTest.java     | 107 +++
 .../rdf/jena/tdb/storage/TdbTcProviderTest.java |  61 ++
 39 files changed, 2850 insertions(+), 2849 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a9f6ebb..1ae7238 100644
--- a/pom.xml
+++ b/pom.xml
@@ -73,7 +73,6 @@
                 <module>rdf.cris</module>
                 <module>rdf.enrichment</module>
                 <module>rdf.file.storage</module>
-                <module>rdf.jena.tdb.storage</module>
                 <module>rdf.locking</module>
                 <module>rdf.rdfjson</module>
                 <module>rdf.scala.utils</module>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/provisioning/rdf/pom.xml
----------------------------------------------------------------------
diff --git a/provisioning/rdf/pom.xml b/provisioning/rdf/pom.xml
index aba5127..d5acc70 100644
--- a/provisioning/rdf/pom.xml
+++ b/provisioning/rdf/pom.xml
@@ -55,6 +55,7 @@
         <dependency>
             <groupId>org.wymiwyg</groupId>
             <artifactId>wymiwyg-commons-core</artifactId>
+            <version>0.8</version>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/LICENSE
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/LICENSE b/rdf.jena.tdb.storage/LICENSE
deleted file mode 100644
index 261eeb9..0000000
--- a/rdf.jena.tdb.storage/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
-   APPENDIX: How to apply the Apache License to your work.
-
-      To apply the Apache License to your work, attach the following
-      boilerplate notice, with the fields enclosed by brackets "[]"
-      replaced with your own identifying information. (Don't include
-      the brackets!)  The text should be enclosed in the appropriate
-      comment syntax for the file format. We also recommend that a
-      file or class name and description of purpose be included on the
-      same "printed page" as the copyright notice for easier
-      identification within third-party archives.
-
-   Copyright [yyyy] [name of copyright owner]
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/pom.xml b/rdf.jena.tdb.storage/pom.xml
deleted file mode 100644
index 9306ee3..0000000
--- a/rdf.jena.tdb.storage/pom.xml
+++ /dev/null
@@ -1,112 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements.  See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership.  The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License.  You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied.  See the License for the
- specific language governing permissions and limitations
- under the License.
-
---><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <artifactId>clerezza</artifactId>
-        <groupId>org.apache.clerezza</groupId>
-        <version>0.5</version>
-        <relativePath>../parent</relativePath>
-    </parent>
-    <groupId>org.apache.clerezza</groupId>
-    <artifactId>rdf.jena.tdb.storage</artifactId>
-    <packaging>bundle</packaging>
-    <version>1.0.0-SNAPSHOT</version>
-    <name>Clerezza - SCB Jena TDB Storage Provider</name>
-    <description>A Jena TDB based storage provider</description>
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.clerezza</groupId>
-            <artifactId>rdf.core</artifactId>
-            <version>0.14</version>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza</groupId>
-            <artifactId>rdf.ontologies</artifactId>
-            <version>0.12</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza</groupId>
-            <artifactId>rdf.jena.commons</artifactId>
-            <version>0.7</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza</groupId>
-            <artifactId>rdf.jena.storage</artifactId>
-            <version>0.7</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza</groupId>
-            <artifactId>rdf.jena.sparql</artifactId>
-            <version>0.7</version>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.jena</groupId>
-            <artifactId>jena-tdb</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>com.sun.jmx</groupId>
-                    <artifactId>jmxri</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>com.sun.jdmk</groupId>
-                    <artifactId>jmxtools</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>javax.jms</groupId>
-                    <artifactId>jms</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-            <version>14.0</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.clerezza</groupId>
-            <artifactId>rdf.core.test</artifactId>
-            <scope>test</scope>
-            <version>0.15</version>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-simple</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java b/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
deleted file mode 100644
index a3cdd19..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.internals;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.concurrent.locks.ReadWriteLock;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
-import org.apache.clerezza.rdf.core.event.FilterTriple;
-import org.apache.clerezza.rdf.core.event.GraphListener;
-import org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider;
-
-/**
- * {@link LockableMGraph} wrapper that uses a single {@link ReadWriteLock} for
- * the Jena TDB {@link SingleTdbDatasetTcProvider#dataset}
- * @author Rupert Westenthaler
- *
- */
-public class DatasetLockedMGraph extends LockableMGraphWrapper {
-
-
-    /**
-     * Constructs a LocalbleMGraph for an MGraph.
-     *
-     * @param providedMGraph a non-lockable mgraph
-     */
-    public DatasetLockedMGraph(final ReadWriteLock lock, final MGraph providedMGraph) {
-        super(providedMGraph, lock);
-    }
-
-    //Maybe overwriting this prevents unnecessary locking
-    /*
-    @Override
-    public Iterator<Triple> filter(NonLiteral subject, UriRef predicate, Resource object) {
-        //users will need to aquire a readlock while iterating
-        return wrapped.filter(subject, predicate, object);
-    }
-    */
-        
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java b/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
deleted file mode 100644
index 7b6421f..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.internals;
-
-import java.util.concurrent.locks.ReadWriteLock;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
-import org.apache.clerezza.rdf.core.impl.SimpleGraph;
-import org.apache.clerezza.rdf.core.impl.util.PrivilegedGraphWrapper;
-import org.apache.clerezza.rdf.core.impl.util.PrivilegedMGraphWrapper;
-import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
-import org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider;
-
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.sparql.core.DatasetGraph;
-import com.hp.hpl.jena.sparql.core.Quad;
-import com.hp.hpl.jena.tdb.TDB;
-
-/**
- * Represents the Jena {@link Model} and the Clerezza {@link Graph} or
- * {@link MGraph}. It also provide access to the {@link JenaGraphAdaptor}
- * so that this component can add parsed data to {@link Graph}s created
- * by calls to {@link SingleTdbDatasetTcProvider#createGraph(UriRef, TripleCollection)}.
- * @author Rupert Westenthaler
- *
- */
-public class ModelGraph {
-    /**
-     * The Jena Model
-     */
-    private final Model model;
-    /**
-     * The JenaGraphAdapter. Note that in case of read-only in anonymous
-     * subclass is used that prevents the creation of an in-memory copy
-     * of the data when calling {@link JenaGraphAdaptor#getGraph()}.
-     */
-    private JenaGraphAdaptor jenaAdapter;
-    /**
-     * The {@link Graph}(in case of read-only) or {@link MGraph} (if read/write)
-     * that can be shared with other components. The instance stored by this
-     * variable will use all the required Wrappers such as such as 
-     * {@link LockableMGraphWrapper lockable} and {@link PrivilegedMGraphWrapper
-     * privileged}.
-     */
-    private TripleCollection graph;
-    /**
-     * keeps the state if this represents an {@link Graph} (read-only) or
-     * {@link MGraph}(read/write) ModelGraph.
-     */
-    private final boolean readWrite;
-    
-    /**
-     * Constructs and initializes the ModelGraph
-     * @param model the Jena Model
-     * @param readWrite if the Clerezza counterpart should be read- and 
-     * write-able or read-only.
-     */
-    public ModelGraph(final ReadWriteLock lock, Model model, boolean readWrite){
-        if(model == null){
-            throw new IllegalArgumentException("The parsed Model MUST NOT be NULL");
-        }
-        this.model = model;
-        this.readWrite = readWrite;
-        if(!readWrite){ //construct an graph
-            jenaAdapter = new JenaGraphAdaptor(model.getGraph()){
-                /**
-                 * Ensure that no in-memory copies are created for read only
-                 * Jena Graphs
-                 * @return
-                 */
-                @Override
-                public Graph getGraph() {
-                    return new SimpleGraph(this,true);
-                }
-            };
-            graph = new PrivilegedGraphWrapper(jenaAdapter.getGraph());
-        } else { //construct an MGraph
-            jenaAdapter = new JenaGraphAdaptor(model.getGraph());
-            this.graph =  new DatasetLockedMGraph(lock,
-                new PrivilegedMGraphWrapper(jenaAdapter));
-        }
-    }
-    /**
-     * The {@link JenaGraphAdaptor}. For internal use only! Do not pass
-     * this instance to other components. Use {@link #getGraph()} and
-     * {@link #getMGraph()} instead!
-     * @return the plain {@link JenaGraphAdaptor}
-     */
-    public JenaGraphAdaptor getJenaAdapter(){
-        return jenaAdapter;
-    }
-
-    public boolean isReadWrite(){
-        return readWrite;
-    }
-    /**
-     * Getter for the {@link MGraph}
-     * @return the {@link MGraph}
-     * @throws IllegalStateException if this {@link ModelGraph} is NOT
-     * {@link #readWrite}
-     */
-    public MGraph getMGraph(){
-        if(!readWrite){
-            throw new IllegalStateException("Unable to return MGraph for read-only models");
-        }
-        return (MGraph)graph;
-    }
-    /**
-     * Getter for the {@link Graph}
-     * @return the {@link Graph}
-     * @throws IllegalStateException if this {@link ModelGraph} is 
-     * {@link #readWrite}
-     */
-    public Graph getGraph() {
-        if(readWrite){
-            throw new IllegalStateException("Unable to return Graph for read/write models.");
-        }
-        return (Graph)graph;
-    }
-    /**
-     * closes this ModelGraph and frees up all Jena TDB related resources.
-     */
-    public void close(){
-        this.graph = null;
-        this.jenaAdapter = null;
-        sync();
-        this.model.close();
-    }
-    /**
-     * Synchronize the Jena Model with the field system by calling
-     * {@link TDB#sync(Model)}
-     */
-    public void sync(){
-        TDB.sync(model);
-    }
-    /**
-     * Removes all triples from the Jena Model and than calls {@link #close()}
-     * to free remaining resources. Note that in Jena TDB a named model is 
-     * deleted if no more triples with the given context are present within
-     * the {@link Quad} store of the Jena TDB {@link DatasetGraph}.
-     */
-    public void delete(){
-        this.model.removeAll();
-        close();
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java b/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
deleted file mode 100644
index ccf3003..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.internals;
-
-import org.apache.clerezza.rdf.core.UriRef;
-
-/**
- * Provides static methods in order to represent classes used to
- * represent named graphs.
- * 
- * @author misl
- * 
- */
-public class Symbols {
-
-    public static UriRef Index = new UriRef("http://clerezza.apache.org/storage/Index");
-
-    public static UriRef Default = new UriRef("http://clerezza.apache.org/storage/Default");
-    
-    public static UriRef Graph = new UriRef("http://clerezza.apache.org/storage/Graph");
-
-    public static UriRef MGraph = new UriRef("http://clerezza.apache.org/storage/MGraph");
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java b/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
deleted file mode 100644
index fb165d0..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.internals;
-
-import java.util.AbstractSet;
-import java.util.Iterator;
-
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.ontologies.RDF;
-
-/**
- * Represents a set of uri ref Set<UriRef>
- * @author Minto van der Sluis
- */
-public class UriRefSet extends AbstractSet<UriRef> {
-    private ModelGraph graphNameIndex;
-    private UriRef graphType;
-
-    public UriRefSet(ModelGraph index, UriRef object) {
-        graphNameIndex = index;
-        graphType = object;
-    }
-  
-    @Override
-    public int size() {
-        // TODO: How to get the proper size based on graphType
-        return graphNameIndex.getMGraph().size();
-    }
-  
-    @Override
-    public Iterator<UriRef> iterator() {
-        final Iterator<Triple> indexIter = graphNameIndex.getMGraph().filter( null, RDF.type, graphType );
-        return new Iterator<UriRef>() {
-            @Override
-            public boolean hasNext() {
-                return indexIter.hasNext();
-            }
-  
-            @Override
-            public UriRef next() {
-                return UriRef.class.cast(indexIter.next().getSubject());
-            }
-  
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException();
-            }
-        };
-    }
-    
-    @Override
-    public boolean add(UriRef o) {
-        throw new UnsupportedOperationException();
-    }
-  
-    @Override
-    public boolean contains(Object o) {
-        if (o instanceof UriRef) {
-            return graphNameIndex.getMGraph().filter(UriRef.class.cast(o), RDF.type, graphType).hasNext();
-        }
-        return false;
-    }
-};    

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java b/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
deleted file mode 100644
index c8a7a5f..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.access.QueryableTcProvider;
-import org.apache.clerezza.rdf.core.sparql.query.Query;
-import org.apache.clerezza.rdf.jena.sparql.ResultSetWrapper;
-import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
-
-import com.hp.hpl.jena.query.Dataset;
-import com.hp.hpl.jena.query.QueryException;
-import com.hp.hpl.jena.query.QueryExecException;
-import com.hp.hpl.jena.query.QueryExecution;
-import com.hp.hpl.jena.query.QueryExecutionFactory;
-import com.hp.hpl.jena.query.QueryFactory;
-import com.hp.hpl.jena.update.GraphStore;
-import com.hp.hpl.jena.update.GraphStoreFactory;
-import com.hp.hpl.jena.update.UpdateAction;
-import org.apache.clerezza.rdf.core.UriRef;
-
-abstract class BaseTdbTcProvider implements QueryableTcProvider{
-
-	// ------------------------------------------------------------------------
-	// Object attributes
-	// ------------------------------------------------------------------------
-
-	private Dataset dataset;
-		
-	// ------------------------------------------------------------------------
-	// Implementing QueryableTcProvider
-	// ------------------------------------------------------------------------
-
-    @Override
-    public Object executeSparqlQuery(final String query, UriRef defaultGraph) {
-		// Missing permission (java.lang.RuntimePermission getClassLoader)
-		// when calling QueryFactory.create causes ExceptionInInitializerError
-		// to be thrown.
-		// QueryExecutionFactory.create requires
-		// (java.io.FilePermission [etc/]location-mapping.* read)
-		// Thus, they are placed within doPrivileged
-		QueryExecution qexec = AccessController
-				.doPrivileged(new PrivilegedAction<QueryExecution>() {
-
-					@Override
-					public QueryExecution run() {
-						try {
-							com.hp.hpl.jena.query.Query jenaQuery = QueryFactory
-									.create(query);
-							if (jenaQuery.isUnknownType()) {
-								return null;
-							}
-							return QueryExecutionFactory.create(jenaQuery, getDataset());
-						} catch (QueryException ex) {
-							return null;
-						}							
-					}
-				});
-
-		if (qexec == null) {
-			return executeUpdate(query);
-		}
-
-		try {
-			try {
-				return new ResultSetWrapper(qexec.execSelect());
-			} catch (QueryExecException e) {
-				try {
-					return Boolean.valueOf(qexec.execAsk());
-				} catch (QueryExecException e2) {
-					try {
-						return new JenaGraphAdaptor(qexec.execDescribe()
-								.getGraph()).getGraph();
-					} catch (QueryExecException e3) {
-						return new JenaGraphAdaptor(qexec.execConstruct()
-								.getGraph()).getGraph();
-					}
-				}
-			}
-		} finally {
-			qexec.close();
-		}
-    }
-
-	// ------------------------------------------------------------------------
-	// Getters / Setters
-	// ------------------------------------------------------------------------
-    
-    public Dataset getDataset() {
-    	if (dataset == null) {
-    		throw new RuntimeException("Missing Dataset!");
-    	}
-		return dataset;
-	}
-    
-    public void setDataset(Dataset dataset) {
-		this.dataset = dataset;
-	}
-
-	// ------------------------------------------------------------------------
-	// Private methods
-	// ------------------------------------------------------------------------
-    
-	private Object executeUpdate(String query) {
-        GraphStore graphStore = GraphStoreFactory.create(getDataset()) ;
-        UpdateAction.parseExecute(query, graphStore) ;
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java b/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
deleted file mode 100644
index b8df417..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
+++ /dev/null
@@ -1,717 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Dictionary;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
-import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
-import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
-import org.apache.clerezza.rdf.core.access.QueryableTcProvider;
-import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.jena.tdb.internals.ModelGraph;
-import org.apache.clerezza.rdf.jena.tdb.internals.Symbols;
-import org.apache.clerezza.rdf.jena.tdb.internals.UriRefSet;
-import org.apache.clerezza.rdf.ontologies.RDF;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.MapMaker;
-import com.hp.hpl.jena.query.Dataset;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.tdb.TDB;
-import com.hp.hpl.jena.tdb.TDBFactory;
-import org.apache.clerezza.rdf.core.access.TcManager;
-
-/**
- * {@link WeightedTcProvider} implementation for Jena TDB that uses a single
- * {@link TDBFactory#createDataset(String) Dataset} to store all created
- * {@link Graph} and {@link MGraph} instances.<p>
- * The {@link #TDB_DIR} is uses to configure the directory on the disc. It
- * supports property substitution <code>'${property}'</code> based on properties defined
- * in the {@link BundleContext#getProperty(String)} and 
- * {@link System#getProperty(String)}. This is to easily allow configurations
- * such as <code>"${myHome}/myRdfStore"</code><p>
- * The {@link #DEFAULT_GRAPH_NAME} property can be used to define the
- * name of the Graph that exposes the {@link Dataset#getDefaultModel()} as
- * both {@link TcProvider#getGraph(UriRef)} and {@link TcProvider#getMGraph(UriRef)}.
- * This easily allows to access the union graph of the Jena TDB dataset.<p>
- * This {@link TcProvider} {@link ConfigurationPolicy#REQUIRE requires} an
- * configuration and uses the {@link Component#configurationFactory() 
- * configuration factory}. Therefore it will be bot active until a valid
- * configuration is parsed to the {@link ConfigurationAdmin} service. However
- * it supports multiple instances to be created.<p>
- * Users that want to use multiple instances will need to use special filters
- * to ensure that the correct instance is injected to components. As by default
- * the instance with the highest {@link #WEIGHT} will be used by Clerezza
- * to create instances. A good practice to filter for multiple instances is
- * to add an additional user defined key to the configuration that can later
- * be used for filtering. Such additional keys will be savely ignored by
- * this implementation.<p>
- * 
- * @author Rupert Westenthaler, MInto van der Sluis
- *
- */
-@Component(metatype=true, immediate=true,
-    configurationFactory=true, policy=ConfigurationPolicy.OPTIONAL)
-@Service({WeightedTcProvider.class, TcProvider.class, QueryableTcProvider.class})
-@Properties(value={
-    @Property(name=SingleTdbDatasetTcProvider.TDB_DIR),
-    @Property(name=SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME),
-    @Property(name=SingleTdbDatasetTcProvider.SYNC_INTERVAL, intValue=SingleTdbDatasetTcProvider.DEFAULT_SYNC_INTERVAL),
-    @Property(name=SingleTdbDatasetTcProvider.WEIGHT, intValue=105),
-    @Property(name=TcManager.GENERAL_PURPOSE_TC, boolValue = true)
-})
-public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements WeightedTcProvider {
-
-    public static final String TDB_DIR = "tdb-dir";
-    public static final String DEFAULT_GRAPH_NAME = "default-graph-name";
-    public static final String WEIGHT = "weight";
-    public static final String SYNC_INTERVAL = "sync-interval";
-    public static final String USE_GRAPH_NAME_SUFFIXES = "use-graph-name-suffixes";
-    
-    public static final int DEFAULT_SYNC_INTERVAL = 6;
-    public static final int MIN_SYNC_INTERVAL = 3;
-    
-    private final Logger log = LoggerFactory.getLogger(SingleTdbDatasetTcProvider.class);
-
-    private int weight;
-    private ModelGraph graphNameIndex;
-    private int syncInterval = DEFAULT_SYNC_INTERVAL;
-    private SyncThread syncThread;
-
-    private final ReadWriteLock datasetLock = new ReentrantReadWriteLock();;
-    private UriRef defaultGraphName;
-
-    // Ensure that models not yet garbage collected get properly synced.
-    private final ConcurrentMap<UriRef, ModelGraph> syncModels = new MapMaker().weakValues().makeMap();
-    
-    /**
-     * This background thread ensures that changes to {@link Model}s are
-     * synchronized with the file system. Only {@link ModelGraph}s where
-     * <code>{@link ModelGraph#isReadWrite()} == true</code> are synced.<p>
-     * This is similar to the synchronize thread used by the {@link TdbTcProvider}.
-     * This thread is started during the 
-     * {@link ScalableSingleTdbDatasetTcProvider#activate(ComponentContext) activation}
-     * ad the shutdown is requested during 
-     * {@link ScalableSingleTdbDatasetTcProvider#deactivate(ComponentContext) deactivation}
-     */
-    class SyncThread extends Thread {
-        private boolean stopRequested = false;
-
-        @Override
-        public void run() {
-            while (!stopRequested) {
-                try {
-                    Thread.sleep(syncInterval*1000);
-                } catch (InterruptedException ex) {
-                    interrupt();
-                }
-                if (!stopRequested) {
-                    datasetLock.writeLock().lock();
-                    try {
-                        for(ModelGraph mg : syncModels.values()){
-                            if(mg.isReadWrite()){
-                                mg.sync();
-                            } //else we do not need to sync read-only models
-                        }
-                    } finally {
-                        datasetLock.writeLock().unlock();
-                    }
-                }
-            }
-        }
-        
-        public void requestStop() {
-            stopRequested = true;
-        }
-    }
-
-    /**
-     * Default constructor used by OSGI
-     */
-    public SingleTdbDatasetTcProvider(){}
-    
-    /**
-     * Creates a TDB single dataset {@link TcProvider} based on the parsed
-     * configuration.<p>
-     * The following properties are supported:<ul>
-     * <li> {@link #TDB_DIR} (required): The directory used by Jena TDB. Property
-     * substitution "${property-name}" with {@link System#getProperties()} is
-     * supported.
-     * <li> {@link #DEFAULT_GRAPH_NAME}: The name ({@link UriRef}) of the
-     * {@link Graph} that exports the union graph. This graph allows to query
-     * triples in any named model managed by this {@link TcProvider}.
-     * <li> {@link #SYNC_INTERVAL}: The sync interval that
-     * is used to write changes in the graph to the file system. If missing
-     * the {@link #DEFAULT_SYNC_INTERVAL} is used. Values lower than 
-     * {@link #MIN_SYNC_INTERVAL} are ignored
-     * <li>{@link #WEIGHT}: The weight of this {@link TcProvider}. If missing
-     * <code>0</code> is used as weight.
-     * </ul>
-     * <b>NOTE</b> Users need to call {@link #close()} to free up system 
-     * resources when they are no longer need this instance.
-     * @param config The configuration
-     * @throws IOException the 
-     * @throws ConfigurationException 
-     */
-    public SingleTdbDatasetTcProvider(Dictionary<String,Object> config) throws ConfigurationException, IOException{
-        activate(null,config);
-    }
-    /**
-     * Activate method used by OSGI
-     * @param ctx
-     * @throws ConfigurationException
-     * @throws IOException
-     */
-    @Activate
-    @SuppressWarnings("unchecked")
-    protected void activate(ComponentContext ctx) throws ConfigurationException, IOException {
-        activate(ctx.getBundleContext(),ctx.getProperties());
-    }
-
-    /**
-     * Internally used for activation to support  the instantiation via
-     * {@link #ScalableSingleTdbDatasetTcProvider(Dictionary)} - to be used outside
-     * an OSGI container.
-     * @param bc the BundleContext or <code>null</code> if activating outside
-     * an OSGI container. The BundleContext is just used to lookup properties
-     * for {@link #substituteProperty(String, BundleContext)}.
-     * @param config The configuration for this Instance. Note that {@link #TDB_DIR}
-     * is required to be present.
-     * @throws ConfigurationException if the parsed configuration is invalid
-     * @throws IOException on any error while creating/accessing the Jena TDB
-     * directory.
-     */
-    private void activate(BundleContext bc,Dictionary<String,Object> config) throws ConfigurationException, IOException {
-        log.info("Activating scalable single Dataset TDB provider");
-        Object value = config.get(WEIGHT);
-        if(value instanceof Number){
-            weight = ((Number)value).intValue();
-        } else if(value != null){
-            try {
-                weight = new BigDecimal(value.toString()).intValueExact();
-            } catch (RuntimeException e) {
-                throw new ConfigurationException(WEIGHT, "Unable to parse integer weight!", e);
-            }
-        } else { //weight not defined
-            weight = 0;
-        }
-        value = config.get(SYNC_INTERVAL);
-        if(value instanceof Number){
-            syncInterval = Math.max(((Number)value).intValue(),MIN_SYNC_INTERVAL);
-        } else if(value != null){
-            try {
-                syncInterval = Math.max(new BigDecimal(value.toString()).intValueExact(),MIN_SYNC_INTERVAL);
-            } catch (RuntimeException e) {
-                throw new ConfigurationException(SYNC_INTERVAL, "Unable to parse integer weight!", e);
-            }
-        } else { //sync interval not defined
-            syncInterval = DEFAULT_SYNC_INTERVAL;
-        }
-        value = config.get(TDB_DIR);
-        File dataDir;
-        if(value != null && !value.toString().isEmpty()){
-            dataDir = new File(substituteProperty(value.toString(),bc)).getAbsoluteFile();
-        } else {
-            value = config.get(Constants.SERVICE_PID);
-            if(value == null){
-                throw new ConfigurationException(TDB_DIR, "No Data Directory for "
-                    + "the Jena TDB store parsed. Also unable to use the "
-                    + "'service.pid' property as default because this property "
-                    + "is not present in the parsed configuration.");
-            }
-            dataDir = bc.getDataFile("singleTdb"+File.separatorChar+value.toString());
-            log.info("No TDB directory parsed - use default '{}'",dataDir);
-        }
-        //parse the default graph name
-        value = config.get(DEFAULT_GRAPH_NAME);
-        if(value != null && !value.toString().isEmpty()){
-            try {
-                new URI(value.toString());
-                defaultGraphName = new UriRef(value.toString());
-            } catch (URISyntaxException e) {
-                throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The parsed name '"
-                        + value + "'for the default graph (union over all "
-                		+ "named graphs managed by this Jena TDB dataset) MUST BE "
-                        + "an valid URI or NULL do deactivate this feature!",e);
-            }
-        } else {
-            defaultGraphName = null; //deactivate the default graph name
-        }
-        
-        //validate the parsed directory!
-        if(!dataDir.exists()){
-            if(dataDir.mkdirs()){
-                log.info("Created Jena TDB data directory {}",dataDir);
-            } else {
-                throw new ConfigurationException(TDB_DIR, "Unable to create Jena TDB data directory '"+dataDir+"'!");
-            }
-        } else if(!dataDir.isDirectory()){
-            throw new ConfigurationException("tdb.dir", "Configured jena TDB data directory '"
-                    + dataDir+"' already exists, but is not a Directory!");
-        } //else exists and is a directory ... nothing to do
-        TDB.getContext().set(TDB.symUnionDefaultGraph, true);
-        setDataset( TDBFactory.createDataset(dataDir.getAbsolutePath()) );
-        graphNameIndex = new ModelGraph(datasetLock, getDataset().getDefaultModel(),true);
-
-        // Remove existing default graph names from the index (if might have changed
-        // in the mean time).
-        removeDefaultGraphFromIndex();
-
-        //finally ensure the the defaultGraphName is not also used as a graph/mgraph name
-        if (defaultGraphName != null) {
-          if (isExistingGraphName(defaultGraphName)) {
-            throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The configured default graph name '"
-                +defaultGraphName+"' is already used as a Graph or MGraph name!");
-          } else {
-            addToIndex( defaultGraphName, Symbols.Default );
-            addToIndex( defaultGraphName, Symbols.Graph );
-          }
-        }
-
-        syncThread = new SyncThread();
-        syncThread.setDaemon(true);
-        syncThread.setName("SyncDaemon for Jena TDB "+dataDir.getAbsolutePath());
-        syncThread.start();
-    }
-    
-    /**
-     * call close in finalisation
-     */
-    @Override
-    protected void finalize() throws Throwable {
-        close();
-        super.finalize();
-    }
-
-    /**
-     * Closes this {@link TcProvider} instance and frees up all system resources.
-     * This method needs only to be called when using this TcProvider outside
-     * an OSGI environment.
-     */
-    public void close(){
-        deactivate(null);
-    }
-
-    /**
-     * Deactivates this component. Called by the OSGI environment if this
-     * component gets deactivated.
-     * @param ctx the ComponentContext. May be <code>null</code>
-     */
-    @Deactivate
-    protected void deactivate(ComponentContext ctx) {
-        if(syncThread != null){
-            syncThread.requestStop();
-            syncThread = null;
-        }
-    	Dataset dataset = getDataset();
-        if(dataset != null){ //avoid NPE on multiple calls
-            datasetLock.writeLock().lock();
-            try {
-                for(ModelGraph mg : syncModels.values()){
-                    mg.close(); //close also syncs!
-                }
-                syncModels.clear();
-
-                graphNameIndex.close();
-                graphNameIndex = null;
-
-                TDB.sync(dataset);
-                dataset.close();
-                setDataset(null);
-            } finally {
-                datasetLock.writeLock().unlock();
-            }
-        }
-    }
-    
-    /**
-     * Internal method used to retrieve an existing Jena {@link ModelGraph} 
-     * instance from {@link #syncModels} or initializes a new Jena TDB {@link Model}
-     * and Clerezza {@link Graph}s/{@link MGraph}s.
-     * @param name the name of the Graph to initialize/create
-     * @param readWrite if <code>true</code> a {@link MGraph} is initialized.
-     * Otherwise a {@link Graph} is created.
-     * @param create if this method is allowed to create an new {@link Model} or
-     * if an already existing model is initialized.
-     * @return the initialized {@link Model} and @link Graph} or {@link MGraph}.
-     * The returned instance will be also cached in {@link #syncModels}. 
-     * @throws NoSuchEntityException If <code>create == false</code> and no
-     * {@link Model} for the parsed <code>name</code> exists.
-     */
-    private ModelGraph getModelGraph(UriRef name, boolean readWrite,boolean create) throws NoSuchEntityException {
-        ModelGraph modelGraph = null;
-        datasetLock.readLock().lock();
-        try {
-            if(readWrite) {
-                // Reuse existing model if not yet garbage collected.
-                modelGraph = syncModels.get(name);
-            }
-            if((modelGraph != null || isExistingGraphName(name)) && create){
-                throw new EntityAlreadyExistsException(name);
-            } else if(modelGraph == null){
-                String modelName = name.getUnicodeString();
-                modelGraph = new ModelGraph(datasetLock, name.equals(defaultGraphName) ? 
-                		getDataset().getNamedModel("urn:x-arq:UnionGraph") : 
-                			getDataset().getNamedModel(modelName),readWrite);
-                if(readWrite) {
-                    // Keep track of readwrite model to be able to sync them.
-                    this.syncModels.put(name, modelGraph);
-                }
-            }
-        } finally {
-            datasetLock.readLock().unlock();
-        }
-        return modelGraph;
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#getGraph(org.apache.clerezza.rdf.core.UriRef)
-     */
-    @Override
-    public Graph getGraph(UriRef name) throws NoSuchEntityException {
-        if(name == null){
-            throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
-        }
-        datasetLock.readLock().lock();
-        try {
-            if (isExistingGraphName(name, Symbols.Graph) || name.equals(defaultGraphName)){
-                return getModelGraph(name,false,false).getGraph();
-            } else {
-                throw new NoSuchEntityException(name);
-            }
-        } finally {
-            datasetLock.readLock().unlock();
-        }
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#getMGraph(org.apache.clerezza.rdf.core.UriRef)
-     */
-    @Override
-    public MGraph getMGraph(UriRef name) throws NoSuchEntityException {
-        if(name == null){
-            throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
-        }
-        datasetLock.readLock().lock();
-        try {
-            if(isExistingGraphName(name, Symbols.MGraph)){
-                return getModelGraph(name,true,false).getMGraph();
-            } else {
-                throw new NoSuchEntityException(name);
-            }
-        } finally {
-            datasetLock.readLock().unlock();
-        }
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#getTriples(org.apache.clerezza.rdf.core.UriRef)
-     */
-    @Override
-    public TripleCollection getTriples(UriRef name) throws NoSuchEntityException {
-        if(name == null){
-            throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
-        }
-        datasetLock.readLock().lock();
-        try {
-            if(isExistingGraphName(name, Symbols.Graph) || name.equals(defaultGraphName)){
-                return getGraph(name);
-            } else if(isExistingGraphName(name, Symbols.MGraph)){
-                return getMGraph(name);
-            } else {
-                throw new NoSuchEntityException(name);
-            }
-        } finally {
-            datasetLock.readLock().unlock();
-        }
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#listGraphs()
-     */
-    @Override
-    public Set<UriRef> listGraphs() {
-        datasetLock.readLock().lock();
-        try {
-            return new HashSet(new UriRefSet( graphNameIndex, Symbols.Graph ));
-        } finally {
-            datasetLock.readLock().unlock();
-        }
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#listMGraphs()
-     */
-    @Override
-    public Set<UriRef> listMGraphs() {
-        datasetLock.readLock().lock();
-        try {
-            return  new HashSet(new UriRefSet( graphNameIndex, Symbols.MGraph ));
-        } finally {
-            datasetLock.readLock().unlock();
-        }
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#listTripleCollections()
-     */
-    @Override
-    public Set<UriRef> listTripleCollections() {
-        datasetLock.readLock().lock();
-        try {
-            return  new HashSet(new UriRefSet( graphNameIndex, null ));
-        } finally {
-            datasetLock.readLock().unlock();
-        }
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#createMGraph(org.apache.clerezza.rdf.core.UriRef)
-     */
-    @Override
-    public MGraph createMGraph(UriRef name) throws UnsupportedOperationException,
-                                           EntityAlreadyExistsException {
-        if(name == null){
-            throw new IllegalArgumentException("The parsed MGrpah name MUST NOT be NULL!");
-        }
-        datasetLock.writeLock().lock();
-        try {
-            if(isExistingGraphName(name)){
-                throw new EntityAlreadyExistsException(name);
-            }
-            MGraph graph = getModelGraph(name,true,true).getMGraph();
-            addToIndex( name, Symbols.MGraph);
-            return graph;
-        } finally {
-            datasetLock.writeLock().unlock();
-        }
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#createGraph(org.apache.clerezza.rdf.core.UriRef, org.apache.clerezza.rdf.core.TripleCollection)
-     */
-    @Override
-    public Graph createGraph(UriRef name, TripleCollection triples) throws UnsupportedOperationException,
-                                                                   EntityAlreadyExistsException {
-        if(name == null){
-            throw new IllegalArgumentException("The parsed Grpah name MUST NOT be NULL!");
-        }
-        ModelGraph mg;
-        datasetLock.writeLock().lock();
-        try {
-            if(isExistingGraphName(name)){
-                throw new EntityAlreadyExistsException(name);
-            }
-            mg = getModelGraph(name,false,true);
-            addToIndex( name, Symbols.Graph);
-            
-            //add the parsed data!
-            if(triples != null) { //load the initial and final set of triples
-                mg.getJenaAdapter().addAll(triples);
-                mg.sync();
-            }
-        } finally {
-            datasetLock.writeLock().unlock();
-        }
-        return mg.getGraph();
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#deleteTripleCollection(org.apache.clerezza.rdf.core.UriRef)
-     */
-    @Override
-    public void deleteTripleCollection(UriRef name) throws UnsupportedOperationException,
-                                                   NoSuchEntityException,
-                                                   EntityUndeletableException {
-        if(name == null){
-            throw new IllegalArgumentException("The parsed MGrpah name MUST NOT be NULL!");
-        }
-        datasetLock.writeLock().lock();
-        try {
-            if(isExistingGraphName(name,Symbols.MGraph)){
-                ModelGraph mg = getModelGraph(name, true, false);
-                mg.delete();
-                removeFromIndex( name, Symbols.MGraph );
-            } else if(isExistingGraphName(name,Symbols.Graph)){
-                ModelGraph mg = getModelGraph(name, false, false);
-                mg.delete();
-                removeFromIndex( name, Symbols.Graph );
-            } else if (name.equals(defaultGraphName)){
-                throw new EntityUndeletableException(defaultGraphName);
-            }
-            //delete the graph from the initModels list
-            syncModels.remove(name);
-        } finally {
-            datasetLock.writeLock().unlock();
-        }
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.TcProvider#getNames(org.apache.clerezza.rdf.core.Graph)
-     */
-    @Override
-    public Set<UriRef> getNames(Graph graph) {
-        //TODO: this method would require to compare the triples within the graph
-        //      because an equals check will not work with BNodes. 
-        Set<UriRef> graphNames = new HashSet<UriRef>();
-        for( Iterator<Triple> iterator = graphNameIndex.getMGraph().iterator(); iterator.hasNext(); ) {
-            Triple triple = iterator.next();
-            UriRef graphName = new UriRef(triple.getSubject().toString());
-            Graph currentGraph = getModelGraph(graphName, false, false).getGraph();
-            if(graph.equals(currentGraph)){
-                graphNames.add(graphName);
-            }
-        }
-        return graphNames;
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.access.WeightedTcProvider#getWeight()
-     */
-    @Override
-    public int getWeight() {
-        return weight;
-    }
-    
-    /**
-     * Substitutes ${property.name} with the values retrieved via <ul>
-     * <li> {@link BundleContext#getProperty(String)} or
-     * <li> {@link System#getProperty(String, String)} if the parsed
-     * {@link BundleContext} is <code>null</code>
-     * </ul>
-     * Substitutes with an empty string if the property is not present. If
-     * the substitution does not end with {@link File#separatorChar}, than it is
-     * appended to allow easily creating paths relative to root directory available
-     * as property regardless if the property includes/excludes the final
-     * separator char.
-     * <p>
-     * Nested substitutions are NOT supported. However multiple substitutions are supported.
-     * <p>
-     * If someone knows a default implementation feel free to replace!
-     * 
-     * @param value
-     *            the value to substitute
-     * @param bundleContext
-     *            If not <code>null</code> the {@link BundleContext#getProperty(String)} is used instead of
-     *            the {@link System#getProperty(String)}. By that it is possible to use OSGI only properties
-     *            for substitution.
-     * @return the substituted value
-     */
-    private static String substituteProperty(String value, BundleContext bundleContext) {
-        int prevAt = 0;
-        int foundAt = 0;
-        StringBuilder substitution = new StringBuilder();
-        while ((foundAt = value.indexOf("${", prevAt)) >= prevAt) {
-            substitution.append(value.substring(prevAt, foundAt));
-            String propertyName = value.substring(foundAt + 2, value.indexOf('}', foundAt));
-            String propertyValue = bundleContext == null ? // if no bundleContext is available
-            System.getProperty(propertyName) : // use the System properties
-                    bundleContext.getProperty(propertyName);
-            if(propertyValue != null) {
-                substitution.append(propertyValue);
-                if(propertyValue.charAt(propertyValue.length()-1) != File.separatorChar){
-                    substitution.append(File.separatorChar);
-                }
-            } //else nothing to append
-            prevAt = foundAt + propertyName.length() + 3; // +3 -> "${}".length
-        }
-        substitution.append(value.substring(prevAt, value.length()));
-        return substitution.toString();
-    }
-
-    /**
-     * Checks whether the given graph name already exists as the specified resource (either graph or mgraph).
-     * @param graphName the graph name
-     * @param graphType the resource type
-     * @return true if a resource with the given name and type already exists, false otherwise.
-     */
-    private boolean isExistingGraphName(UriRef graphName, UriRef graphType) {
-        return graphNameIndex.getMGraph().filter(graphName, RDF.type, graphType).hasNext();
-    }
-
-    /**
-     * Checks whether the given graph name already exists as either a graph or mgraph.
-     * @param graphName the graph name
-     * @return true if a graph or mgraph with the given name already exists, false otherwise.
-     */
-    private boolean isExistingGraphName(UriRef graphName) {
-        return isExistingGraphName(graphName, null);
-    }
-    
-    /**
-     * Adds a new graphname to the index of graphnames  
-     * @param graphName name of the graph
-     * @param graphType resourcetype for the graph to add.
-     */
-    private void addToIndex(UriRef graphName, UriRef graphType) {
-        graphNameIndex.getMGraph().add(new TripleImpl(graphName, RDF.type, graphType));
-        graphNameIndex.sync();
-    }
-    
-    /**
-     * Removes a graphanem from the index of graphnames
-     * @param graphName name of the graph to remove
-     * @param graphType resource type of the graph to remove.
-     */
-    private void removeFromIndex(UriRef graphName, UriRef graphType) {
-        MGraph index = graphNameIndex.getMGraph();
-        Iterator<Triple> triplesToRemove = index.filter(graphName, RDF.type, graphType);
-        for( ; triplesToRemove.hasNext(); ) {
-            triplesToRemove.next();
-            triplesToRemove.remove();
-        }
-        graphNameIndex.sync();
-    }
-    
-    private void removeDefaultGraphFromIndex() {
-      MGraph index = graphNameIndex.getMGraph();
-      Iterator<Triple> triplesToRemove = index.filter(null, RDF.type, Symbols.Default);
-      for( ; triplesToRemove.hasNext(); ) {
-          Triple triple = triplesToRemove.next();
-          triplesToRemove.remove();
-          removeFromIndex( UriRef.class.cast(triple.getSubject()), Symbols.Graph );
-      }
-      graphNameIndex.sync();
-    }
-} 

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java b/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
deleted file mode 100644
index f8924fc..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import com.hp.hpl.jena.query.Dataset;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.tdb.TDB;
-import com.hp.hpl.jena.tdb.TDBFactory;
-import com.hp.hpl.jena.tdb.base.block.FileMode;
-import com.hp.hpl.jena.tdb.sys.SystemTDB;
-import java.io.File;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.Lock;
-import java.util.logging.Level;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
-import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
-import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
-import org.apache.clerezza.rdf.core.access.TcManager;
-import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.util.PrivilegedMGraphWrapper;
-import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
-
-/**
- * A {@link org.apache.clerezza.rdf.core.access.WeightedTcProvider} based on
- * Jena TDB.
- *
- * @see <a href="http://jena.hpl.hp.com/wiki/TDB/JavaAPI">
- * TDB/JavaAPI</a>
- *
- * @author reto, hasan
- *
- *
- */
-@Component(metatype = true, immediate = true)
-@Service(WeightedTcProvider.class)
-@Properties({
-    @Property(name = "weight", intValue = 107),
-    @Property(name = TcManager.GENERAL_PURPOSE_TC, boolValue = true)})
-public class TdbTcProvider implements WeightedTcProvider {
-
-    static {
-        //not sure what the perfomance implication of this is
-        //it is only needed so that on windows the files of a dataset can be deleteds
-        SystemTDB.setFileMode(FileMode.direct);
-    }
-    @Property(intValue = 6, description = "Specifies the number of seconds to wait "
-            + "between synchronizations of the TDB datasets to the filesystem")
-    public static final String SYNC_INTERVAL = "sync-interval";
-    private int syncInterval = 6;
-    /**
-     * directory where all graphs are stored
-     */
-    private static final String DATA_PATH_NAME = "tdb-data/";
-    private String dataPathString = DATA_PATH_NAME;
-    private Map<UriRef, LockableMGraph> mGraphMap = new HashMap<UriRef, LockableMGraph>();
-    private Map<UriRef, Graph> graphMap = new HashMap<UriRef, Graph>();
-    private Map<File, com.hp.hpl.jena.graph.Graph> dir2JenaGraphMap = new HashMap<File, com.hp.hpl.jena.graph.Graph>();
-    private Map<File, Lock> dir2Lock = new HashMap<File, Lock>();
-    private final Map<File, Dataset> dir2Dataset = new HashMap<File, Dataset>();
-    private static final Logger log = LoggerFactory.getLogger(TdbTcProvider.class);
-    private int weight = 107;
-
-    class SyncThread extends Thread {
-
-        private boolean stopRequested = false;
-
-        @Override
-        public void run() {
-            while (!stopRequested) {
-                try {
-                    Thread.sleep(syncInterval * 1000);
-                } catch (InterruptedException ex) {
-                    interrupt();
-                }
-                if (!stopRequested) {
-                    syncWithFileSystem();
-                }
-            }
-        }
-
-        public void requestStop() {
-            stopRequested = true;
-        }
-    }
-    private SyncThread syncThread;
-
-    public TdbTcProvider() {
-    }
-
-    TdbTcProvider(File directory) {
-        dataPathString = directory.getAbsolutePath();
-        loadMGraphs();
-        loadGraphs();
-    }
-
-    public void activate(ComponentContext cCtx) {
-        log.info("Activating TDB provider");
-        if (cCtx != null) {
-            weight = (Integer) cCtx.getProperties().get("weight");
-            dataPathString = cCtx.getBundleContext().
-                    getDataFile(DATA_PATH_NAME).getAbsolutePath();
-            syncInterval = Integer.parseInt(cCtx.getProperties().get(SYNC_INTERVAL).toString());
-        }
-        loadMGraphs();
-        loadGraphs();
-        syncThread = new SyncThread();
-        syncThread.start();
-    }
-
-    public void deactivate(ComponentContext cCtx) {
-        syncThread.requestStop();
-        syncThread = null;
-        for (com.hp.hpl.jena.graph.Graph jenaGraph : dir2JenaGraphMap.values()) {
-            jenaGraph.close();
-        }
-        synchronized (dir2Dataset) {
-            for (Dataset dataset : dir2Dataset.values()) {
-                dataset.close();
-            }
-        }
-    }
-
-    @Override
-    public int getWeight() {
-        return weight;
-    }
-
-    @Override
-    public Graph getGraph(UriRef name) throws NoSuchEntityException {
-        if (!graphMap.containsKey(name)) {
-            throw new NoSuchEntityException(name);
-        }
-        return graphMap.get(name);
-    }
-
-    @Override
-    public synchronized MGraph getMGraph(UriRef name) throws NoSuchEntityException {
-        if (!mGraphMap.containsKey(name)) {
-            throw new NoSuchEntityException(name);
-        }
-        return mGraphMap.get(name);
-    }
-
-    @Override
-    public TripleCollection getTriples(UriRef name) throws NoSuchEntityException {
-        try {
-            return getMGraph(name);
-        } catch (NoSuchEntityException e) {
-            return getGraph(name);
-        }
-    }
-
-    @Override
-    public synchronized MGraph createMGraph(UriRef name)
-            throws UnsupportedOperationException, EntityAlreadyExistsException {
-        File tcDir = getMGraphDir(name);
-        if (tcDir.exists()) {
-            throw new EntityAlreadyExistsException(name);
-        }
-        tcDir.mkdirs();
-        File otimizationIndicator = new File(tcDir, "fixed.opt");
-        try {
-            otimizationIndicator.createNewFile();
-        } catch (IOException ex) {
-            throw new RuntimeException(ex);
-        }
-        LockableMGraph result = new LockableMGraphWrapper(getMGraph(tcDir));
-        dir2Lock.put(tcDir, result.getLock().writeLock());
-        mGraphMap.put(name, result);
-        return result;
-    }
-
-    @Override
-    public Graph createGraph(UriRef name, TripleCollection triples)
-            throws UnsupportedOperationException, EntityAlreadyExistsException {
-        File tcDir = getGraphDir(name);
-        if (tcDir.exists()) {
-            throw new EntityAlreadyExistsException(name);
-        }
-
-        if (triples == null) {
-            triples = new SimpleMGraph();
-        }
-        tcDir.mkdirs();
-        File otimizationIndicator = new File(tcDir, "fixed.opt");
-        try {
-            otimizationIndicator.createNewFile();
-        } catch (IOException ex) {
-            throw new RuntimeException(ex);
-        }
-        MGraph mGraph = getMGraph(tcDir);
-        mGraph.addAll(triples);
-        Graph result = mGraph.getGraph();
-        TDB.sync(dir2Dataset.get(tcDir));
-        graphMap.put(name, result);
-        return result;
-    }
-
-    @Override
-    public void deleteTripleCollection(UriRef name)
-            throws UnsupportedOperationException, NoSuchEntityException,
-            EntityUndeletableException {
-        syncWithFileSystem();
-        if (deleteTcDir(getGraphDir(name))) {
-            graphMap.remove(name);
-            return;
-        }
-        if (deleteTcDir(getMGraphDir(name))) {
-            mGraphMap.remove(name);
-            return;
-        }
-        throw new NoSuchEntityException(name);
-    }
-
-    private boolean deleteTcDir(File tcDir) {
-        if (tcDir.exists()) {
-            dir2JenaGraphMap.get(tcDir).close();
-            dir2JenaGraphMap.remove(tcDir);
-            synchronized (dir2Dataset) {
-                dir2Dataset.get(tcDir).close();
-                dir2Dataset.remove(tcDir);
-            }
-            try {
-                delete(tcDir);
-            } catch (IOException ex) {
-                for (int i = 0; i < 10; i++) {
-                    try {
-                        System.gc();
-                        delete(tcDir);
-                    } catch (IOException ex1) {
-                        try {
-                            Thread.sleep(10);
-                        } catch (InterruptedException ex2) {
-                            Thread.currentThread().interrupt();
-                        }
-                        continue;
-                    }
-                    return true;
-                }
-                throw new RuntimeException(ex);
-            }
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * Cleans the content of the specified directory recursively.
-     *
-     * @param dir Abstract path denoting the directory to clean.
-     */
-    private static void cleanDirectory(File dir) throws IOException {
-        File[] files = dir.listFiles();
-        if (files != null && files.length > 0) {
-            for (File file : files) {
-                delete(file);
-            }
-        }
-    }
-
-    /**
-     * Deletes the specified file or directory.
-     *
-     * @param file Abstract path denoting the file or directory to clean.
-     */
-    protected static void delete(File file) throws IOException {
-        if (file.isDirectory()) {
-            cleanDirectory(file);
-        }
-        //better but only in java 7
-        //java.nio.file.Files.delete(file.toPath());
-        if (!file.delete()) {
-            throw new IOException("couldn't delete " + file.getAbsolutePath());
-        }
-    }
-
-    @Override
-    public Set<UriRef> getNames(Graph graph) {
-        //this could be done more efficiently with an index, could be done with
-        //a MultiBidiMap (BidiMap allowing multiple keys for the same value)
-        Set<UriRef> result = new HashSet<UriRef>();
-        for (UriRef name : listGraphs()) {
-            if (getGraph(name).equals(graph)) {
-                result.add(name);
-            }
-        }
-        return result;
-    }
-
-    @Override
-    public Set<UriRef> listTripleCollections() {
-        Set<UriRef> result = new HashSet<UriRef>();
-        result.addAll(listGraphs());
-        result.addAll(listMGraphs());
-        return result;
-    }
-
-    @Override
-    public Set<UriRef> listGraphs() {
-        return graphMap.keySet();
-    }
-
-    @Override
-    public Set<UriRef> listMGraphs() {
-        return mGraphMap.keySet();
-    }
-
-    private Graph getGraph(File tcDir) {
-        return getMGraph(tcDir).getGraph();
-    }
-
-    private File getGraphDir(UriRef name) {
-        File base = new File(dataPathString);
-        return getTcDir(new File(base, "graph"), name);
-    }
-
-    private MGraph getMGraph(File tcDir) {
-        Dataset dataset = TDBFactory.createDataset(tcDir.getAbsolutePath());
-        Model model = dataset.getDefaultModel();
-        //Model model = TDBFactory.createModel(tcDir.getAbsolutePath());
-        final com.hp.hpl.jena.graph.Graph jenaGraph = model.getGraph();
-        dir2JenaGraphMap.put(tcDir, jenaGraph);
-        //dataset.
-        synchronized (dir2Dataset) {
-            dir2Dataset.put(tcDir, dataset);
-        }
-        return new PrivilegedMGraphWrapper(new JenaGraphAdaptor(jenaGraph));
-    }
-
-    private File getMGraphDir(UriRef name) {
-        File base = new File(dataPathString);
-        return getTcDir(new File(base, "mgraph"), name);
-    }
-
-    private File getTcDir(File directory, UriRef name) {
-        try {
-            String subDirName = URLEncoder.encode(name.getUnicodeString(), "utf-8");
-            return new File(directory, subDirName);
-        } catch (UnsupportedEncodingException ex) {
-            throw new RuntimeException("utf-8 not supported", ex);
-        }
-    }
-
-    private void loadGraphs() {
-        File graphsDir = new File(new File(dataPathString), "graph");
-        if (graphsDir.exists()) {
-            for (String graphDirName : graphsDir.list()) {
-                try {
-                    UriRef uri = new UriRef(URLDecoder.decode(graphDirName, "utf-8"));
-                    log.info("loading: " + graphDirName);
-                    graphMap.put(uri, getGraph(new File(graphsDir, graphDirName)));
-                } catch (UnsupportedEncodingException ex) {
-                    throw new RuntimeException("utf-8 not supported", ex);
-                } catch (Exception e) {
-                    log.error("Could not load tdb graph in " + graphDirName, e);
-                }
-            }
-        }
-    }
-
-    private void loadMGraphs() {
-        File mGraphsDir = new File(new File(dataPathString), "mgraph");
-        if (mGraphsDir.exists()) {
-            for (String mGraphDirName : mGraphsDir.list()) {
-                try {
-                    UriRef uri = new UriRef(URLDecoder.decode(mGraphDirName, "utf-8"));
-                    log.info("loading: " + mGraphDirName);
-                    final File tcDir = new File(mGraphsDir, mGraphDirName);
-                    final LockableMGraphWrapper lockableMGraph = new LockableMGraphWrapper(getMGraph(tcDir));
-                    mGraphMap.put(uri, lockableMGraph);
-                    dir2Lock.put(tcDir, lockableMGraph.getLock().writeLock());
-                } catch (UnsupportedEncodingException ex) {
-                    throw new RuntimeException("utf-8 not supported", ex);
-                } catch (Exception e) {
-                    log.error("Could not load tdb graph in " + mGraphDirName, e);
-                }
-            }
-        }
-    }
-
-    public void syncWithFileSystem() {
-        synchronized (dir2Dataset) {
-            for (Map.Entry<File, Dataset> entry : dir2Dataset.entrySet()) {
-                Lock l = dir2Lock.get(entry.getKey());
-                if (l == null) {
-                    return;
-                }
-                l.lock();
-                try {
-                    TDB.sync(entry.getValue());
-                } finally {
-                    l.unlock();
-                }
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider b/rdf.jena.tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider
deleted file mode 100644
index 5dbaf81..0000000
--- a/rdf.jena.tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.clerezza.rdf.jena.tdb.storage.TdbTcProvider
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties b/rdf.jena.tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties
deleted file mode 100644
index b2488eb..0000000
--- a/rdf.jena.tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ /dev/null
@@ -1,47 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Deactivate properties for component because those are not common for Apache Clerezza
-#org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider.name=Apache Stanbol Clerezza \
-#Single Jena TDB Provider
-#org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider.description=Tc Provider \
-#implementation that stores Clerezza TripleCollections as named graphs in a single Jena \
-#TDB store.
-
-#==============================================================
-#Properties and Options used to configure TDB dataset providers
-#==============================================================
-
-tdb-dir.name=Jena TDB directory
-tdb-dir.description= The directory for Jena the TDB database. This field \
-supports property substitution: '${property}' will be replaced with the value \
-of the 'property' available via the BundleContext or the system properties \
-(e.g. "${myHome}/myRdfStore")
-default-graph-name.name=Default Graph Name
-default-graph-name.description=The URI name of the default graph of the Jena \
-TDB database. Requests to the TcProvider with this URI will return an MGraph \
-that is the union over all the graphs managed by this TcProvider. If empty or \
-not defined the default graph is not exposed.
-weight.name=Weight
-weight.description=The weight of this TcProvider. Set to an low value (e.g. \
-value < 0) if you want to inject this instance by using a Filter. Set to a high \
-value (e.g. values > 1000) if you want this instance to be the default used by \
-Clerezza.
-sync-interval.name=Sync Interval
-sync-interval.description=The interval in seconds until changes are saved to \
-the file system. Sync will always occur if this provider is deactivated. However \
-on crashes all data since the last sync will be lost. The default is 6sec. \
-Higher values will reduce the overhead for periodically writing to the file \
-system.
\ No newline at end of file


[08/14] clerezza git commit: CLEREZZA-966: moved jena.tdb.storage into the hierarchy

Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java
new file mode 100644
index 0000000..2964385
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.io.File;
+import java.io.IOException;
+
+
+import org.junit.After;
+import org.junit.Before;
+import org.apache.clerezza.rdf.core.access.TcProvider;
+import org.apache.clerezza.rdf.core.test.TcProviderTest;
+
+/**
+ *
+ * @author mir
+ */
+public class TdbTcProviderTest extends TcProviderTest {
+
+    private File tempFile;
+    private TdbTcProvider lastInstance;
+
+    @Before
+    public void setupDirectory() throws IOException {
+        tempFile = File.createTempFile("tdbtest", null);
+        tempFile.delete();
+        tempFile.mkdirs();
+    }
+
+    @After
+    public void cleanUp() throws IOException {
+        TdbTcProvider.delete(tempFile);
+    }
+
+
+    @Override
+    protected TcProvider getInstance() {
+        if (lastInstance != null) {
+            lastInstance.deactivate(null);
+        }
+        lastInstance =  new TdbTcProvider(tempFile);
+        lastInstance.activate(null);
+        return lastInstance;
+    }
+}


[04/14] clerezza git commit: CLEREZZA-966: moved rdf.utils into the hierarchy

Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java
deleted file mode 100644
index 4b0a4dc..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.clerezza.rdf.utils;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.concurrent.locks.ReadWriteLock;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.ImmutableGraph;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.AbstractGraph;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.apache.commons.rdf.impl.utils.simple.SimpleImmutableGraph;
-
-/**
- * This wrapps a Triplecollection changing a prefix for the Iris contained
- * in subject or object position.
- *
- * Currently it only supports read opearations.
- *
- * @author reto
- */
-public class UriMutatingGraph implements Graph {
-
-    private final Graph base;
-    private final String sourcePrefix;
-    private final String targetPrefix;
-    private final int sourcePrefixLength;
-    private final int targetPrefixLength;
-
-    public UriMutatingGraph(Graph base, String sourcePrefix,
-            String targetPrefix) {
-        this.base = base;
-        this.sourcePrefix = sourcePrefix;
-        sourcePrefixLength= sourcePrefix.length();
-        this.targetPrefix = targetPrefix;
-        targetPrefixLength= targetPrefix.length();
-    }
-
-    private <R extends RdfTerm> R toTargetRdfTerm(final R sourceRdfTerm) {
-        if (sourceRdfTerm instanceof Iri) {
-            final Iri sourceIri = (Iri) sourceRdfTerm;
-            if (sourceIri.getUnicodeString().startsWith(sourcePrefix)) {
-                final String uriRest = sourceIri.getUnicodeString()
-                        .substring(sourcePrefixLength);
-                return (R) new Iri(targetPrefix+uriRest);
-            }
-        }
-        return sourceRdfTerm;            
-    }
-
-    private Triple toTargetTriple(Triple triple) {
-        if (triple == null) {
-            return null;
-        }
-        return new TripleImpl(toTargetRdfTerm(triple.getSubject()),
-                triple.getPredicate(), toTargetRdfTerm(triple.getObject()));
-    }
-
-    private <R extends RdfTerm> R toSourceRdfTerm(final R targetRdfTerm) {
-        if (targetRdfTerm instanceof Iri) {
-            final Iri sourceIri = (Iri) targetRdfTerm;
-            if (sourceIri.getUnicodeString().startsWith(targetPrefix)) {
-                final String uriRest = sourceIri.getUnicodeString()
-                        .substring(targetPrefixLength);
-                return (R) new Iri(sourcePrefix+uriRest);
-            }
-        }
-        return targetRdfTerm;
-    }
-
-    private Triple toSourceTriple(Triple triple) {
-        if (triple == null) {
-            return null;
-        }
-        return new TripleImpl(toSourceRdfTerm(triple.getSubject()),
-                triple.getPredicate(), toSourceRdfTerm(triple.getObject()));
-    }
-
-    @Override
-    public Iterator<Triple> filter(BlankNodeOrIri subject, Iri predicate, RdfTerm object) {
-        final Iterator<Triple> baseIter = base.filter(toSourceRdfTerm(subject),
-                predicate, toSourceRdfTerm(object));
-        return new WrappedIteraror(baseIter);
-
-
-    }
-
-
-    @Override
-    public int size() {
-        return base.size();
-    }
-
-    @Override
-    public boolean isEmpty() {
-        return base.isEmpty();
-    }
-
-    @Override
-    public boolean contains(Object o) {
-        return base.contains(toSourceTriple((Triple)o));
-    }
-
-    @Override
-    public Iterator<Triple> iterator() {
-        return filter(null, null, null);
-    }
-
-    @Override
-    public Object[] toArray() {
-        Object[] result = base.toArray();
-        for (int i = 0; i < result.length; i++) {
-            Triple triple = (Triple) result[i];
-            result[i] = toTargetTriple(triple);
-        }
-        return result;
-    }
-
-    @Override
-    public <T> T[] toArray(T[] a) {
-        T[] result = base.toArray(a);
-        for (int i = 0; i < result.length; i++) {
-            Triple triple = (Triple) result[i];
-            result[i] = (T) toTargetTriple(triple);
-        }
-        return result;
-    }
-
-    @Override
-    public boolean add(Triple e) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public boolean remove(Object o) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public boolean containsAll(Collection<?> c) {
-        for (Object object : c) {
-            if (!contains(object)) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    @Override
-    public boolean addAll(Collection<? extends Triple> c) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public boolean removeAll(Collection<?> c) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public boolean retainAll(Collection<?> c) {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public void clear() {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public ImmutableGraph getImmutableGraph() {
-        return new SimpleImmutableGraph(this);
-    }
-
-    @Override
-    public ReadWriteLock getLock() {
-        return base.getLock();
-    }
-
-    class WrappedIteraror implements Iterator<Triple>{
-        private final Iterator<Triple> baseIter;
-
-        private WrappedIteraror(Iterator<Triple> baseIter) {
-            this.baseIter = baseIter;
-        }
-
-        @Override
-        public boolean hasNext() {
-            return baseIter.hasNext();
-        }
-
-        @Override
-        public Triple next() {
-            return toTargetTriple(baseIter.next());
-        }
-
-        @Override
-        public void remove() {
-            throw new UnsupportedOperationException("Not supported yet.");
-        }
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
deleted file mode 100644
index 03c73a5..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.apache.clerezza.rdf.utils.graphnodeprovider;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.utils.GraphNode;
-
-/**
- * A service that returns a GraphNode for a specified named resource, the
- * returned GraphNode has as BaseGraph the ContentGraph provided by the
- * ContentGraphProvider and the for remote uris the Graphs they dereference to
- * and for local URIs with a path-section starting with /user/{username}/ the
- * local-public-graph of that user.
- */
-public interface GraphNodeProvider {
-
-    /**
-     * Get a GraphNode for the specified resource, see class comments for
-     * details.
-     */
-    GraphNode get(Iri uriRef);
-
-    /**
-     * Get a GraphNode for the specified resource, The resource is assumed to be
-     * local, i.e. the method behaves like get(Iri) for a Uri with an
-     * authority section contained in the Set retuned by
-     * <code>org.apache.clerezza.platform.config.PlatformConfig#getBaseUris()</code>
-     */
-    GraphNode getLocal(Iri uriRef);
-
-    /**
-     * return true iff getLocal(uriRef).getNodeContext.size > 0
-     */
-    boolean existsLocal(Iri uriRef);
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
deleted file mode 100644
index 1841cd1..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.clerezza.rdf.utils.smushing;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.Lock;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.apache.clerezza.rdf.ontologies.OWL;
-
-/**
- *
- * @author Reto
- */
-public class BaseSmusher {
-
-    /**
-     * Smushes the resources in mGraph that belong to the same set in equivalenceSets,
-     * i.e. it adds all properties to one of the resources in the equivalence set.
-     * 
-     * Optionally owl:sameAs statement are added that point from the IRIs that 
-     * no longer have properties to the one with properties. If addOwlSameAs
-     * is false the IRIs will just disappear from the graph.
-     * 
-     * @param mGraph the graph to smush
-     * @param equivalenceSets sets of equivalent resources
-     * @param addOwlSameAs whether owl:sameAs statements should be added
-     */
-    public void smush(Graph mGraph, Set<Set<BlankNodeOrIri>> equivalenceSets, boolean addOwlSameAs) {
-        Map<BlankNodeOrIri, BlankNodeOrIri> current2ReplacementMap = new HashMap<BlankNodeOrIri, BlankNodeOrIri>();
-        final Graph owlSameAsGraph = new SimpleGraph();
-        for (Set<BlankNodeOrIri> equivalenceSet : equivalenceSets) {
-            final BlankNodeOrIri replacement = getReplacementFor(equivalenceSet, owlSameAsGraph);
-            for (BlankNodeOrIri current : equivalenceSet) {
-                if (!current.equals(replacement)) {
-                    current2ReplacementMap.put(current, replacement);
-                }
-            }
-        }
-        final Set<Triple> newTriples = new HashSet<Triple>();
-        Lock l = mGraph.getLock().writeLock();
-        l.lock();
-        try {
-            for (Iterator<Triple> it = mGraph.iterator(); it.hasNext();) {
-                final Triple triple = it.next();
-                final BlankNodeOrIri subject = triple.getSubject();
-                BlankNodeOrIri subjectReplacement = current2ReplacementMap.get(subject);
-                final RdfTerm object = triple.getObject();
-                @SuppressWarnings(value = "element-type-mismatch")
-                RdfTerm objectReplacement = current2ReplacementMap.get(object);
-                if ((subjectReplacement != null) || (objectReplacement != null)) {
-                    it.remove();
-                    if (subjectReplacement == null) {
-                        subjectReplacement = subject;
-                    }
-                    if (objectReplacement == null) {
-                        objectReplacement = object;
-                    }
-                    newTriples.add(new TripleImpl(subjectReplacement, triple.getPredicate(), objectReplacement));
-                }
-            }
-            for (Triple triple : newTriples) {
-                mGraph.add(triple);
-            }
-            mGraph.addAll(owlSameAsGraph);
-        } finally {
-            l.unlock();
-        }
-    }
-    
-    private BlankNodeOrIri getReplacementFor(Set<BlankNodeOrIri> equivalenceSet, 
-            Graph owlSameAsGraph) {
-        final Set<Iri> uriRefs = new HashSet<Iri>();
-        for (BlankNodeOrIri nonLiteral : equivalenceSet) {
-            if (nonLiteral instanceof Iri) {
-                uriRefs.add((Iri) nonLiteral);
-            }
-        }
-        switch (uriRefs.size()) {
-            case 1:
-                return uriRefs.iterator().next();
-            case 0:
-                return new BlankNode();
-        }
-        final Iri preferedIri = getPreferedIri(uriRefs);
-        final Iterator<Iri> uriRefIter = uriRefs.iterator();
-        while (uriRefIter.hasNext()) {
-            Iri uriRef = uriRefIter.next();
-            if (!uriRef.equals(preferedIri)) {
-                owlSameAsGraph.add(new TripleImpl(uriRef, OWL.sameAs, preferedIri));
-            }
-        }
-        return preferedIri;
-    }
-
-    
-    /**
-     * Returns a prefered IRI for the IRIs in a set. Typically and in the
-     * default implementation the IRI will be one of the set. Note however that 
-     * subclass implementations may also return another IRI to be used.
-     * 
-     * @param uriRefs
-     * @return 
-     */
-    protected Iri getPreferedIri(Set<Iri> uriRefs) {
-        final Iterator<Iri> uriRefIter = uriRefs.iterator();
-        //instead of an arbitrary one we might either decide lexicographically
-        //or look at their frequency in mGraph
-        return uriRefIter.next();
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
deleted file mode 100644
index fad1d6b..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils.smushing;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.ontologies.OWL;
-import org.apache.clerezza.rdf.ontologies.RDF;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A utility to equate duplicate nodes in an Mgarph, currently only nodes with 
- * a shared ifp are equated.
- *
- * @author reto
- */
-public class IfpSmusher extends BaseSmusher {
-    
-    static final Logger log = LoggerFactory.getLogger(IfpSmusher.class);
-
-    /**
-     * smush mGaph given the ontological facts. Currently it does only
-     * one step ifp smushin, i.e. only ifps are taken in account and only
-     * nodes that have the same node as ifp object in the orignal graph are
-     * equates. (calling the method a second time might lead to additional
-     * smushings.)
-     *
-     * @param mGraph
-     * @param tBox
-     */
-    public void smush(Graph mGraph, Graph tBox) {
-        final Set<Iri> ifps = getIfps(tBox);
-        final Map<PredicateObject, Set<BlankNodeOrIri>> ifp2nodesMap = new HashMap<PredicateObject, Set<BlankNodeOrIri>>();
-        for (Iterator<Triple> it = mGraph.iterator(); it.hasNext();) {
-            final Triple triple = it.next();
-            final Iri predicate = triple.getPredicate();
-            if (!ifps.contains(predicate)) {
-                continue;
-            }
-            final PredicateObject po = new PredicateObject(predicate, triple.getObject());
-            Set<BlankNodeOrIri> equivalentNodes = ifp2nodesMap.get(po);
-            if (equivalentNodes == null) {
-                equivalentNodes = new HashSet<BlankNodeOrIri>();
-                ifp2nodesMap.put(po, equivalentNodes);
-            }
-            equivalentNodes.add(triple.getSubject());
-        }
-        Set<Set<BlankNodeOrIri>> unitedEquivalenceSets = uniteSetsWithCommonElement(ifp2nodesMap.values());
-        smush(mGraph, unitedEquivalenceSets, true);
-    }
-    
-
-    private Set<Iri> getIfps(Graph tBox) {
-        final Iterator<Triple> ifpDefinitions = tBox.filter(null, RDF.type,
-                OWL.InverseFunctionalProperty);
-        final Set<Iri> ifps = new HashSet<Iri>();
-        while (ifpDefinitions.hasNext()) {
-            final Triple triple = ifpDefinitions.next();
-            ifps.add((Iri) triple.getSubject());
-        }
-        return ifps;
-    }
-
-    private <T> Set<Set<T>> uniteSetsWithCommonElement(
-            Collection<Set<T>> originalSets) {
-        Set<Set<T>> result = new HashSet<Set<T>>();
-        Iterator<Set<T>> iter = originalSets.iterator();
-        while (iter.hasNext()) {
-            Set<T> originalSet = iter.next();
-            //TODO this could be done more efficiently with a map
-            Set<T> matchingSet = getMatchinSet(originalSet, result);
-            if (matchingSet != null) {
-                matchingSet.addAll(originalSet);
-            } else {
-                result.add(new HashSet<T>(originalSet));
-            }
-        }
-        if (result.size() < originalSets.size()) {
-            return uniteSetsWithCommonElement(result);
-        } else {
-            return result;
-        }
-    }
-
-    private <T> Set<T> getMatchinSet(Set<T> set, Set<Set<T>> setOfSet) {
-        for (Set<T> current : setOfSet) {
-            if (shareElements(set,current)) {
-                return current;
-            }
-        }
-        return null;
-    }
-
-    private <T> boolean shareElements(Set<T> set1, Set<T> set2) {
-        for (T elem : set2) {
-            if (set1.contains(elem)) {
-                return true;
-            }
-        }
-        return false;
-    }
-    
-
-    class PredicateObject {
-
-        final Iri predicate;
-        final RdfTerm object;
-
-        public PredicateObject(Iri predicate, RdfTerm object) {
-            this.predicate = predicate;
-            this.object = object;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (obj == null) {
-                return false;
-            }
-            if (getClass() != obj.getClass()) {
-                return false;
-            }
-            final PredicateObject other = (PredicateObject) obj;
-            if (this.predicate != other.predicate && !this.predicate.equals(other.predicate)) {
-                return false;
-            }
-            if (this.object != other.object && !this.object.equals(other.object)) {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public int hashCode() {
-            int hash = 3;
-            hash = 29 * hash + this.predicate.hashCode();
-            hash = 13 * hash + this.object.hashCode();
-            return hash;
-        }
-
-        @Override
-        public String toString() {
-            return "("+predicate+", "+object+")";
-        }
-
-
-    };
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
deleted file mode 100644
index e656a42..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils.smushing;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.ontologies.OWL;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A utility to equate duplicate nodes in an Mgraph. This unifies owl:sameAs
- * resources.
- *
- * @author reto
- */
-public class SameAsSmusher extends BaseSmusher {
-    
-    static final Logger log = LoggerFactory.getLogger(SameAsSmusher.class);
-    
-    /**
-     * This will ensure that all properties of sameAs resources are associated
-     * to the preferedIri as returned by {@code getPreferedIri}
-     * @param mGraph
-     * @param owlSameStatements 
-     * @param addCanonicalSameAsStatements if true owl:sameAsStatements with the preferedIri as object will be added
-     */
-    public void smush(Graph mGraph, 
-            Graph owlSameStatements,
-            boolean addCanonicalSameAsStatements) {
-    	
-    	log.info("Starting smushing");
-        
-    	// This hashmap contains a uri (key) and the set of equivalent uris (value)
-    	final Map<BlankNodeOrIri, Set<BlankNodeOrIri>> node2EquivalenceSet = new HashMap<BlankNodeOrIri, Set<BlankNodeOrIri>>();
-    	
-    	log.info("Creating the sets of equivalent uris of each subject or object in the owl:sameAs statements");
-    	// Determines for each subject and object in all the owl:sameAs statements the set of ewquivalent uris 
-    	for (Iterator<Triple> it = owlSameStatements.iterator(); it.hasNext();) {            
-    		final Triple triple = it.next();
-            final Iri predicate = triple.getPredicate();
-            if (!predicate.equals(OWL.sameAs)) {
-                throw new RuntimeException("Statements must use only <http://www.w3.org/2002/07/owl#sameAs> predicate.");
-            }
-            final BlankNodeOrIri subject = triple.getSubject();
-            //literals not yet supported
-            final BlankNodeOrIri object = (BlankNodeOrIri)triple.getObject();
-            
-            Set<BlankNodeOrIri> equivalentNodes = node2EquivalenceSet.get(subject);
-            
-            // if there is not a set of equivalent uris then create a new set
-            if (equivalentNodes == null) {
-            	equivalentNodes = node2EquivalenceSet.get(object);
-            	if (equivalentNodes == null) {
-                    equivalentNodes = new HashSet<BlankNodeOrIri>();
-                }
-            } else {
-                Set<BlankNodeOrIri> objectSet = node2EquivalenceSet.get(object);
-                if ((objectSet != null) && (objectSet != equivalentNodes)) {
-                    //merge two sets
-                    for (BlankNodeOrIri res : objectSet) {
-                        node2EquivalenceSet.remove(res);
-                    }
-                    for (BlankNodeOrIri res : objectSet) {
-                        node2EquivalenceSet.put(res,equivalentNodes);
-                    }
-                    equivalentNodes.addAll(objectSet);
-                }
-            }
-            
-            // add both subject and object of the owl:sameAs statement to the set of equivalent uris
-            equivalentNodes.add(subject);
-            equivalentNodes.add(object);
-            
-            // use both uris in the owl:sameAs statement as keys for the set of equivalent uris
-            node2EquivalenceSet.put(subject, equivalentNodes);
-            node2EquivalenceSet.put(object, equivalentNodes);
-            
-            log.info("Sets of equivalent uris created.");
-        
-    	}
-    	
-    	// This set contains the sets of equivalent uris
-    	Set<Set<BlankNodeOrIri>> unitedEquivalenceSets = new HashSet<Set<BlankNodeOrIri>>(node2EquivalenceSet.values());
-        smush(mGraph, unitedEquivalenceSets, addCanonicalSameAsStatements);
-    }
-
-    
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java
deleted file mode 100644
index fa14977..0000000
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.clerezza.rdf.utils;
-
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.apache.clerezza.rdf.utils.GraphUtils.NoSuchSubGraphException;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class GraphUtilsTest {
-
-    final Iri u1 = new Iri("http://ex.org/1");
-    final Iri u2 = new Iri("http://ex.org/2");
-    final Iri u3 = new Iri("http://ex.org/3");
-
-    @Test
-    public void removeSubGraph() throws NoSuchSubGraphException {
-        Graph baseGraph = createBaseGraph();
-
-        Graph subGraph = new SimpleGraph();
-        {
-            BlankNode bNode1 = new BlankNode();
-            BlankNode bNode2 = new BlankNode();
-            subGraph.add(new TripleImpl(u1, u2, bNode2));
-            subGraph.add(new TripleImpl(bNode2, u2, bNode2));
-            subGraph.add(new TripleImpl(bNode2, u2, bNode1));
-        }
-        GraphUtils.removeSubGraph(baseGraph, subGraph);
-        Assert.assertEquals(1, baseGraph.size());
-    }
-
-    private Graph createBaseGraph() {
-        Graph baseGraph = new SimpleGraph();
-        {
-            BlankNode bNode1 = new BlankNode();
-            BlankNode bNode2 = new BlankNode();
-            baseGraph.add(new TripleImpl(u1, u2, bNode2));
-            baseGraph.add(new TripleImpl(bNode2, u2, bNode2));
-            baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
-            baseGraph.add(new TripleImpl(u3, u2, u1));
-        }
-        return baseGraph;
-    }
-    
-    /** It is required that the subgraph comprises the whole context of the Bnodes it ioncludes
-     * 
-     * @throws org.apache.clerezza.rdf.utils.GraphUtils.NoSuchSubGraphException
-     */
-    @Test(expected=NoSuchSubGraphException.class)
-    public void removeIncompleteSubGraph() throws NoSuchSubGraphException {
-        Graph baseGraph = createBaseGraph();
-
-        Graph subGraph = new SimpleGraph();
-        {
-            BlankNode bNode1 = new BlankNode();
-            BlankNode bNode2 = new BlankNode();
-            subGraph.add(new TripleImpl(u1, u2, bNode2));
-            subGraph.add(new TripleImpl(bNode2, u2, bNode2));
-        }
-        GraphUtils.removeSubGraph(baseGraph, subGraph);
-    }
-
-    @Test(expected=NoSuchSubGraphException.class)
-    public void removeInvalidSubGraph() throws NoSuchSubGraphException {
-        Graph baseGraph = createBaseGraph();
-
-        Graph subGraph = new SimpleGraph();
-        {
-            BlankNode bNode1 = new BlankNode();
-            BlankNode bNode2 = new BlankNode();
-            subGraph.add(new TripleImpl(u1, u2, bNode2));
-            subGraph.add(new TripleImpl(bNode2, u2, bNode2));
-            baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
-            baseGraph.add(new TripleImpl(bNode2, u2, new BlankNode()));
-        }
-        GraphUtils.removeSubGraph(baseGraph, subGraph);
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
deleted file mode 100644
index d7a2b81..0000000
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.apache.clerezza.rdf.ontologies.FOAF;
-import org.apache.clerezza.rdf.ontologies.OWL;
-import org.apache.clerezza.rdf.ontologies.RDF;
-import org.apache.clerezza.rdf.ontologies.RDFS;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class IfpSmushTest {
-
-    private Graph ontology = new SimpleGraph();
-    {
-        ontology.add(new TripleImpl(FOAF.mbox, RDF.type, OWL.InverseFunctionalProperty));
-    }
-
-    @Test
-    public void simpleBlankNode()  {
-        Graph mGraph = new SimpleGraph();
-        Iri mbox1 = new Iri("mailto:foo@example.org");
-        final BlankNode bNode1 = new BlankNode();
-        mGraph.add(new TripleImpl(bNode1, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode1, RDFS.comment, 
-                new PlainLiteralImpl("a comment")));
-        final BlankNode bNode2 = new BlankNode();
-        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode2, RDFS.comment, 
-                new PlainLiteralImpl("another comment")));
-        Smusher.smush(mGraph, ontology);
-        Assert.assertEquals(3, mGraph.size());
-    }
-
-    @Test
-    public void overlappingEquivalenceClasses()  {
-        Graph mGraph = new SimpleGraph();
-        Iri mbox1 = new Iri("mailto:foo@example.org");
-        final BlankNode bNode1 = new BlankNode();
-        mGraph.add(new TripleImpl(bNode1, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode1, RDFS.comment,
-                new PlainLiteralImpl("a comment")));
-        final BlankNode bNode2 = new BlankNode();
-        Iri mbox2 = new Iri("mailto:bar@example.org");
-        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox2));
-        mGraph.add(new TripleImpl(bNode2, RDFS.comment,
-                new PlainLiteralImpl("another comment")));
-        final BlankNode bNode3 = new BlankNode();
-        mGraph.add(new TripleImpl(bNode3, FOAF.mbox, mbox2));
-        mGraph.add(new TripleImpl(bNode3, RDFS.comment,
-                new PlainLiteralImpl("yet another comment")));
-        Smusher.smush(mGraph, ontology);
-        Assert.assertEquals(5, mGraph.size());
-    }
-
-    @Test
-    public void oneIri()  {
-        Graph mGraph = new SimpleGraph();
-        Iri mbox1 = new Iri("mailto:foo@example.org");
-        final Iri resource = new Iri("http://example.org/");
-        mGraph.add(new TripleImpl(resource, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(resource, RDFS.comment,
-                new PlainLiteralImpl("a comment")));
-        final BlankNode bNode2 = new BlankNode();
-        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode2, RDFS.comment,
-                new PlainLiteralImpl("another comment")));
-        Smusher.smush(mGraph, ontology);
-        Assert.assertEquals(3, mGraph.size());
-    }
-
-    @Test
-    public void twoIris()  {
-        Graph mGraph = new SimpleGraph();
-        Iri mbox1 = new Iri("mailto:foo@example.org");
-        final Iri resource1 = new Iri("http://example.org/");
-        mGraph.add(new TripleImpl(resource1, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(resource1, RDFS.comment,
-                new PlainLiteralImpl("a comment")));
-        final Iri resource2 = new Iri("http://2.example.org/");
-        mGraph.add(new TripleImpl(resource2, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(resource2, RDFS.comment,
-                new PlainLiteralImpl("another comment")));
-        Smusher.smush(mGraph, ontology);
-        Assert.assertEquals(4, mGraph.size());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
deleted file mode 100644
index cd4045d..0000000
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import java.util.List;
-import java.util.Set;
-
-import junit.framework.Assert;
-
-import org.junit.Test;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-import static org.junit.Assert.*;
-
-/**
- *
- * @author rbn
- */
-public class RdfListTest {
-
-    @Test
-    public void listCreationAndAccess() {
-        Graph tc = new SimpleGraph();
-        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
-        assertEquals(0, list.size());
-        list.add(new PlainLiteralImpl("hello"));
-        list.add(new PlainLiteralImpl("world"));
-        assertEquals(new PlainLiteralImpl("hello"), list.get(0));
-        assertEquals(new PlainLiteralImpl("world"), list.get(1));
-        assertEquals(2, list.size());
-        list.add(new PlainLiteralImpl("welcome"));
-        assertEquals(3, list.size());
-        assertEquals(new PlainLiteralImpl("welcome"), list.get(2));
-        list.add(1, new PlainLiteralImpl("interesting"));
-        assertEquals(4, list.size());
-        assertEquals(new PlainLiteralImpl("interesting"), list.get(1));
-        assertEquals(new PlainLiteralImpl("world"), list.get(2));
-        assertEquals(new PlainLiteralImpl("welcome"), list.get(3));
-        list.add(0, new PlainLiteralImpl("start"));
-        assertEquals(5, list.size());
-        assertEquals(new PlainLiteralImpl("hello"), list.get(1));
-        assertEquals(new PlainLiteralImpl("interesting"), list.get(2));
-        List<RdfTerm> list2 = new RdfList(new Iri("http://example.org/mytest"), tc);
-        assertEquals(5, list2.size());
-        assertEquals(new PlainLiteralImpl("hello"), list2.get(1));
-        assertEquals(new PlainLiteralImpl("interesting"), list2.get(2));
-        list2.remove(2);
-        assertEquals(4, list2.size());
-        assertEquals(new PlainLiteralImpl("hello"), list2.get(1));
-        assertEquals(new PlainLiteralImpl("world"), list2.get(2));
-        while (list2.size() > 0) {
-            list2.remove(0);
-        }
-        assertEquals(1, tc.size()); //list = rdf:nil statement
-        list2.add(0, new PlainLiteralImpl("restart"));
-        list2.add(1, new PlainLiteralImpl("over"));
-        assertEquals(2, list2.size());
-        list2.add(new PlainLiteralImpl("2"));
-        list2.add(new PlainLiteralImpl("3"));
-        assertEquals(4, list2.size());
-        list2.add(new PlainLiteralImpl("4"));
-        list2.add(new PlainLiteralImpl("5"));
-        assertEquals(new PlainLiteralImpl("3"), list2.get(3));
-    }
-
-    @Test
-    public void listCreationAndAccess2() {
-        Graph tc = new SimpleGraph();
-        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
-        assertEquals(0, list.size());
-        list.add(0,new PlainLiteralImpl("world"));
-        list = new RdfList(new Iri("http://example.org/mytest"), tc);
-        list.add(0,new PlainLiteralImpl("beautifuly"));
-        list = new RdfList(new Iri("http://example.org/mytest"), tc);
-        list.add(0,new PlainLiteralImpl("hello"));
-        assertEquals(new PlainLiteralImpl("hello"), list.get(0));
-        assertEquals(new PlainLiteralImpl("beautifuly"), list.get(1));
-        assertEquals(new PlainLiteralImpl("world"), list.get(2));
-    }
-
-    @Test
-    public void listCreationAndAccess3() {
-        Graph tc = new SimpleGraph();
-        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
-        assertEquals(0, list.size());
-        BlankNode node0 = new BlankNode() {};
-        BlankNode node1 = new BlankNode() {};
-        BlankNode node2 = new BlankNode() {};
-        list.add(0,node2);
-        list.add(0,node1);
-        list.add(0,node0);
-        assertEquals(node0, list.get(0));
-        assertEquals(node1, list.get(1));
-        assertEquals(node2, list.get(2));
-    }
-
-    @Test
-    public void secondButLastElementAccessTest() {
-        Graph tc = new SimpleGraph();
-        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest2"), tc);
-        list.add(new PlainLiteralImpl("hello"));
-        list.add(new PlainLiteralImpl("world"));
-        list.remove(1);
-        assertEquals(1, list.size());
-    }
-
-    @Test
-    public void cleanGraphAfterRemoval() {
-        Graph tc = new SimpleGraph();
-        List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
-        list.add(new PlainLiteralImpl("hello"));
-        list.add(new PlainLiteralImpl("world"));
-        list.remove(1);
-        Assert.assertEquals(2, tc.size());
-
-    }
-
-    @Test
-    public void findContainingListNodesAndfindContainingListsTest() {
-        Graph tc = new SimpleGraph();
-        GraphNode listA = new GraphNode(new Iri("http:///listA"), tc);
-        GraphNode listB = new GraphNode(new Iri("http:///listB"), tc);
-        BlankNode element1 = new BlankNode();
-        BlankNode element2 = new BlankNode();
-        BlankNode element3 = new BlankNode();
-        BlankNode element4 = new BlankNode();
-        BlankNode element5 = new BlankNode();
-
-        RdfList rdfListA = new RdfList(listA);
-        rdfListA.add(element1);
-        rdfListA.add(element2);
-        rdfListA.add(element3);
-        rdfListA.add(element4);
-
-        RdfList rdfListB = new RdfList(listB);
-        rdfListB.add(element2);
-        rdfListB.add(element4);
-        rdfListB.add(element5);
-
-        Set<GraphNode> containingListNodes = RdfList.findContainingListNodes(
-                new GraphNode(element3, tc));
-        Assert.assertEquals(1, containingListNodes.size());
-        Assert.assertTrue(containingListNodes.contains(listA));
-
-        Set<RdfList> containingLists = RdfList.findContainingLists(
-                new GraphNode(element3, tc));
-        Assert.assertEquals(1, containingLists.size());
-        Assert.assertTrue(containingLists.contains(rdfListA));
-
-        containingListNodes = RdfList.findContainingListNodes(
-                new GraphNode(element4, tc));
-        Assert.assertEquals(2, containingListNodes.size());
-        Assert.assertTrue(containingListNodes.contains(listA));
-        Assert.assertTrue(containingListNodes.contains(listB));
-
-        containingLists = RdfList.findContainingLists(
-                new GraphNode(element4, tc));
-        Assert.assertEquals(2, containingLists.size());
-        Assert.assertTrue(containingLists.contains(rdfListA));
-        Assert.assertTrue(containingLists.contains(rdfListB));
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
deleted file mode 100644
index 66c4005..0000000
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import java.util.Iterator;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Literal;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.apache.clerezza.rdf.ontologies.FOAF;
-import org.apache.clerezza.rdf.ontologies.OWL;
-import org.apache.clerezza.rdf.ontologies.RDF;
-import org.apache.clerezza.rdf.ontologies.RDFS;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class SameAsSmushTest {
-    
-    private final Iri uriA = new Iri("http://example.org/A");
-    private final Iri uriB = new Iri("http://example.org/B");
-    private final Literal lit = new PlainLiteralImpl("That's me (and you)");
-
-    private Graph sameAsStatements = new SimpleGraph();
-    {
-        sameAsStatements.add(new TripleImpl(uriA, OWL.sameAs, uriB));
-    }
-    
-    private Graph  dataGraph = new SimpleGraph();
-    {
-        dataGraph.add(new TripleImpl(uriA, FOAF.knows, uriB));
-        dataGraph.add(new TripleImpl(uriB, RDFS.label, lit));
-        dataGraph.add(new TripleImpl(uriA, RDFS.label, lit));
-    }
-
-    @Test
-    public void simple()  {
-        Assert.assertEquals(3, dataGraph.size());
-        Smusher.sameAsSmush(dataGraph, sameAsStatements);
-        Assert.assertEquals(3, dataGraph.size());
-        Assert.assertTrue(dataGraph.filter(null, OWL.sameAs, null).hasNext());
-        //exactly one statement with literal 
-        Iterator<Triple> litStmts = dataGraph.filter(null, null, lit);
-        Assert.assertTrue(litStmts.hasNext());
-        Triple litStmt = litStmts.next();
-        Assert.assertFalse(litStmts.hasNext());
-        Iterator<Triple> knowsStmts = dataGraph.filter(null, FOAF.knows, null);
-        Assert.assertTrue(knowsStmts.hasNext());
-        Triple knowStmt = knowsStmts.next();
-        Assert.assertEquals(knowStmt.getSubject(), knowStmt.getObject());
-        Assert.assertEquals(litStmt.getSubject(), knowStmt.getObject());
-        Assert.assertEquals(litStmt.getSubject(), dataGraph.filter(null, OWL.sameAs, null).next().getObject());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
deleted file mode 100644
index af8434a..0000000
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import junit.framework.Assert;
-import org.junit.Test;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Literal;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.apache.clerezza.rdf.core.test.RandomGraph;
-
-/**
- *
- * @author reto, mir
- */
-public class TestGraphNode {
-
-    @Test
-    public void nodeContext() {
-        Graph g = new SimpleGraph();
-        BlankNode bNode1 = new BlankNode() {};
-        BlankNode bNode2 = new BlankNode() {};
-        Iri property1 = new Iri("http://example.org/property1");
-        Iri property2 = new Iri("http://example.org/property2");
-        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("literal")));
-        g.add(new TripleImpl(bNode1, property2, property1));
-        g.add(new TripleImpl(bNode2, property2, bNode1));
-        g.add(new TripleImpl(property1, property1, bNode2));
-        g.add(new TripleImpl(property1, property1, new PlainLiteralImpl("bla bla")));
-        GraphNode n = new GraphNode(bNode1, g);
-        Assert.assertEquals(4, n.getNodeContext().size());
-        n.deleteNodeContext();
-        Assert.assertEquals(1, g.size());
-        Assert.assertFalse(n.getObjects(property2).hasNext());
-    }
-
-    @Test
-    public void addNode() {
-        Graph g = new SimpleGraph();
-        BlankNode bNode1 = new BlankNode() {};
-        BlankNode bNode2 = new BlankNode() {};
-        Iri property1 = new Iri("http://example.org/property1");
-        GraphNode n = new GraphNode(bNode1, g);
-        n.addProperty(property1, bNode2);
-        Assert.assertEquals(1, g.size());
-    }
-
-    @Test
-    public void testGetSubjectAndObjectNodes() {
-        RandomGraph graph = new RandomGraph(500, 20, new SimpleGraph());
-        for (int j = 0; j < 200; j++) {
-            Triple randomTriple = graph.getRandomTriple();
-            GraphNode node = new GraphNode(randomTriple.getSubject(), graph);
-            Iterator<Iri> properties = node.getProperties();
-            while (properties.hasNext()) {
-                Iri property = properties.next();
-                Set<RdfTerm> objects = createSet(node.getObjects(property));
-                Iterator<GraphNode> objectNodes = node.getObjectNodes(property);
-                while (objectNodes.hasNext()) {
-                    GraphNode graphNode = objectNodes.next();
-                    Assert.assertTrue(objects.contains(graphNode.getNode()));
-                }
-            }
-        }
-
-        for (int j = 0; j < 200; j++) {
-            Triple randomTriple = graph.getRandomTriple();
-            GraphNode node = new GraphNode(randomTriple.getObject(), graph);
-            Iterator<Iri> properties = node.getProperties();
-            while (properties.hasNext()) {
-                Iri property = properties.next();
-                Set<RdfTerm> subjects = createSet(node.getSubjects(property));
-                Iterator<GraphNode> subjectNodes = node.getSubjectNodes(property);
-                while (subjectNodes.hasNext()) {
-                    GraphNode graphNode = subjectNodes.next();
-                    Assert.assertTrue(subjects.contains(graphNode.getNode()));
-                }
-            }
-        }
-    }
-
-    @Test
-    public void getAvailableProperties(){
-        Graph g = new SimpleGraph();
-        BlankNode bNode1 = new BlankNode() {};
-        BlankNode bNode2 = new BlankNode() {};
-        Iri property1 = new Iri("http://example.org/property1");
-        Iri property2 = new Iri("http://example.org/property2");
-        Iri property3 = new Iri("http://example.org/property3");
-        Iri property4 = new Iri("http://example.org/property4");
-        ArrayList<Iri> props = new ArrayList<Iri>();
-        props.add(property1);
-        props.add(property2);
-        props.add(property3);
-        props.add(property4);
-        GraphNode n = new GraphNode(bNode1, g);
-        n.addProperty(property1, bNode2);
-        n.addProperty(property2, bNode2);
-        n.addProperty(property3, bNode2);
-        n.addProperty(property4, bNode2);
-        Iterator<Iri> properties = n.getProperties();
-        int i = 0;
-        while(properties.hasNext()){
-            i++;
-            Iri prop = properties.next();
-            Assert.assertTrue(props.contains(prop));
-            props.remove(prop);
-        }
-        Assert.assertEquals(i, 4);
-        Assert.assertEquals(props.size(), 0);
-
-    }
-
-    @Test
-    public void deleteAll() {
-        Graph g = new SimpleGraph();
-        BlankNode bNode1 = new BlankNode() {};
-        BlankNode bNode2 = new BlankNode() {};
-        Iri property1 = new Iri("http://example.org/property1");
-        Iri property2 = new Iri("http://example.org/property2");
-        //the two properties two be deleted
-        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("literal")));
-        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("bla bla")));
-        //this 3 properties should stay
-        g.add(new TripleImpl(bNode1, property2, property1));
-        g.add(new TripleImpl(property1, property1, new PlainLiteralImpl("bla bla")));
-        g.add(new TripleImpl(bNode2, property1, new PlainLiteralImpl("bla bla")));
-        GraphNode n = new GraphNode(bNode1, g);
-        n.deleteProperties(property1);
-        Assert.assertEquals(3, g.size());
-    }
-
-    @Test
-    public void deleteSingleProperty() {
-        Graph g = new SimpleGraph();
-        BlankNode bNode1 = new BlankNode() {};
-        BlankNode bNode2 = new BlankNode() {};
-        Iri property1 = new Iri("http://example.org/property1");
-        Iri property2 = new Iri("http://example.org/property2");
-        //the properties two be deleted
-        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("literal")));
-        //this 4 properties should stay
-        g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("bla bla")));
-        g.add(new TripleImpl(bNode1, property2, property1));
-        g.add(new TripleImpl(property1, property1, new PlainLiteralImpl("bla bla")));
-        g.add(new TripleImpl(bNode2, property1, new PlainLiteralImpl("bla bla")));
-        GraphNode n = new GraphNode(bNode1, g);
-        n.deleteProperty(property1, new PlainLiteralImpl("literal"));
-        Assert.assertEquals(4, g.size());
-    }
-
-    @Test
-    public void replaceWith() {
-        Graph initialGraph = new SimpleGraph();
-        BlankNode bNode1 = new BlankNode();
-        BlankNode bNode2 = new BlankNode();
-        BlankNode newBnode = new BlankNode();
-        Iri property1 = new Iri("http://example.org/property1");
-        Iri property2 = new Iri("http://example.org/property2");
-        Iri newIri = new Iri("http://example.org/newName");
-        Literal literal1 = new PlainLiteralImpl("literal");
-        Literal literal2 = new PlainLiteralImpl("bla bla");
-
-        Triple triple1 = new TripleImpl(bNode1, property1, literal1);
-        Triple triple2 = new TripleImpl(bNode1, property2, property1);
-        Triple triple3 = new TripleImpl(bNode2, property2, bNode1);
-        Triple triple4 = new TripleImpl(property1, property1, bNode2);
-        Triple triple5 = new TripleImpl(property1, property1, literal2);
-        initialGraph.add(triple1);
-        initialGraph.add(triple2);
-        initialGraph.add(triple3);
-        initialGraph.add(triple4);
-        initialGraph.add(triple5);
-        GraphNode node = new GraphNode(property1,
-                new SimpleGraph(initialGraph.iterator()));
-
-        node.replaceWith(newIri, true);
-        Assert.assertEquals(5, node.getGraph().size());
-        Triple expectedTriple1 = new TripleImpl(bNode1, newIri, literal1);
-        Triple expectedTriple2 = new TripleImpl(bNode1, property2, newIri);
-        Triple expectedTriple3 = new TripleImpl(newIri, newIri, bNode2);
-        Triple expectedTriple4 = new TripleImpl(newIri, newIri, literal2);
-
-        Assert.assertTrue(node.getGraph().contains(expectedTriple1));
-        Assert.assertTrue(node.getGraph().contains(expectedTriple2));
-        Assert.assertTrue(node.getGraph().contains(expectedTriple3));
-        Assert.assertTrue(node.getGraph().contains(expectedTriple4));
-
-        Assert.assertFalse(node.getGraph().contains(triple1));
-        Assert.assertFalse(node.getGraph().contains(triple2));
-        Assert.assertFalse(node.getGraph().contains(triple4));
-        Assert.assertFalse(node.getGraph().contains(triple5));
-
-        node = new GraphNode(property1, new SimpleGraph(initialGraph.iterator()));
-        node.replaceWith(newBnode);
-        Triple expectedTriple5 = new TripleImpl(bNode1, property2, newBnode);
-        Triple expectedTriple6 = new TripleImpl(newBnode, property1, bNode2);
-        Triple expectedTriple7 = new TripleImpl(newBnode, property1, literal2);
-
-        Assert.assertTrue(node.getGraph().contains(triple1));
-        Assert.assertTrue(node.getGraph().contains(expectedTriple5));
-        Assert.assertTrue(node.getGraph().contains(expectedTriple6));
-        Assert.assertTrue(node.getGraph().contains(expectedTriple7));
-
-        node = new GraphNode(literal1, new SimpleGraph(initialGraph.iterator()));
-        node.replaceWith(newBnode);
-        Triple expectedTriple8 = new TripleImpl(bNode1, property1, newBnode);
-        Assert.assertTrue(node.getGraph().contains(expectedTriple8));
-
-        node = new GraphNode(property1, new SimpleGraph(initialGraph.iterator()));
-        node.replaceWith(newIri);
-        Triple expectedTriple9 = new TripleImpl(bNode1, property2, newIri);
-        Triple expectedTriple10 = new TripleImpl(newIri, property1, bNode2);
-        Triple expectedTriple11 = new TripleImpl(newIri, property1, literal2);
-        Assert.assertTrue(node.getGraph().contains(triple1));
-        Assert.assertTrue(node.getGraph().contains(expectedTriple9));
-        Assert.assertTrue(node.getGraph().contains(expectedTriple10));
-        Assert.assertTrue(node.getGraph().contains(expectedTriple11));
-    }
-
-    @Test
-    public void equality() {
-        Graph g = new SimpleGraph();
-        BlankNode bNode1 = new BlankNode() {};
-        BlankNode bNode2 = new BlankNode() {};
-        Iri property1 = new Iri("http://example.org/property1");
-        GraphNode n = new GraphNode(bNode1, g);
-        n.addProperty(property1, bNode2);
-        Assert.assertTrue(n.equals(new GraphNode(bNode1, g)));
-        Assert.assertFalse(n.equals(new GraphNode(bNode2, g)));
-        GraphNode n2 = null;
-        Assert.assertFalse(n.equals(n2));
-    }
-
-    private Set<RdfTerm> createSet(Iterator<? extends RdfTerm> resources) {
-        Set<RdfTerm> set = new HashSet<RdfTerm>();
-        while (resources.hasNext()) {
-            RdfTerm resource = resources.next();
-            set.add(resource);
-        }
-        return set;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java
deleted file mode 100644
index 2881eb4..0000000
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils;
-
-import java.util.Iterator;
-import org.junit.Test;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.junit.Assert;
-
-/**
- *
- * @author hasan
- */
-public class UnionGraphTest {
-
-    private final Iri uriRef1 =
-            new Iri("http://example.org/ontology#res1");
-    private final Iri uriRef2 =
-            new Iri("http://example.org/ontology#res2");
-    private final Iri uriRef3 =
-            new Iri("http://example.org/ontology#res3");
-    private final Iri uriRef4 =
-            new Iri("http://example.org/ontology#res4");
-
-    @Test
-    public void readAccess() {
-        Graph graph = new SimpleGraph();
-        Graph graph2 = new SimpleGraph();
-        BlankNode bnode = new BlankNode() {
-        };
-        graph.add(new TripleImpl(uriRef1, uriRef2, uriRef1));
-        graph2.add(new TripleImpl(bnode, uriRef1, uriRef3));
-        Graph unionGraph = new UnionGraph(graph, graph2);
-        Iterator<Triple> unionTriples = unionGraph.iterator();
-        Assert.assertTrue(unionTriples.hasNext());
-        unionTriples.next();
-        Assert.assertTrue(unionTriples.hasNext());
-        unionTriples.next();
-        Assert.assertFalse(unionTriples.hasNext());
-        Assert.assertEquals(2, unionGraph.size());
-    }
-    
-    @Test
-    public void writeAccess() {
-        Graph graph = new SimpleGraph();
-        Graph graph2 = new SimpleGraph();
-        BlankNode bnode = new BlankNode() {
-        };
-        graph2.add(new TripleImpl(bnode, uriRef1, uriRef3));
-        Graph unionGraph = new UnionGraph(graph, graph2);
-        Assert.assertEquals(1, unionGraph.size());
-        unionGraph.add(new TripleImpl(uriRef4, uriRef1, uriRef3));
-        Assert.assertEquals(1, graph.size());
-        Assert.assertEquals(2, unionGraph.size());
-        Assert.assertEquals(1, graph2.size());
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
deleted file mode 100644
index bab58e9..0000000
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.utils.smushing;
-
-import java.util.Iterator;
-import java.util.Set;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Literal;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
-import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
-import org.apache.commons.rdf.impl.utils.TripleImpl;
-import org.apache.clerezza.rdf.ontologies.FOAF;
-import org.apache.clerezza.rdf.ontologies.OWL;
-import org.apache.clerezza.rdf.ontologies.RDF;
-import org.apache.clerezza.rdf.ontologies.RDFS;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class SameAsSmushTest {
-    
-    private final Iri uriA = new Iri("http://example.org/A");
-    private final Iri uriB = new Iri("http://example.org/B");
-    private final Iri uriC = new Iri("http://example.org/C");
-    
-    private final Literal lit = new PlainLiteralImpl("That's me (and you)");
-
-    private Graph sameAsStatements = new SimpleGraph();
-    {
-        sameAsStatements.add(new TripleImpl(uriA, OWL.sameAs, uriB));
-    }
-    
-    private Graph  dataGraph = new SimpleGraph();
-    {
-        dataGraph.add(new TripleImpl(uriA, FOAF.knows, uriB));
-        dataGraph.add(new TripleImpl(uriB, RDFS.label, lit));
-        dataGraph.add(new TripleImpl(uriA, RDFS.label, lit));
-    }
-
-    @Test
-    public void simple()  {
-        SameAsSmusher smusher = new SameAsSmusher() {
-
-            @Override
-            protected Iri getPreferedIri(Set<Iri> uriRefs) {
-                if (!uriRefs.contains(uriA)) throw new RuntimeException("not the set we excpect");
-                if (!uriRefs.contains(uriB)) throw new RuntimeException("not the set we excpect");
-                return uriC;
-            }
-            
-        };
-        Assert.assertEquals(3, dataGraph.size());
-        smusher.smush(dataGraph, sameAsStatements, true);
-        Assert.assertEquals(4, dataGraph.size());
-        Assert.assertTrue(dataGraph.filter(null, OWL.sameAs, null).hasNext());
-        //exactly one statement with literal 
-        Iterator<Triple> litStmts = dataGraph.filter(null, null, lit);
-        Assert.assertTrue(litStmts.hasNext());
-        Triple litStmt = litStmts.next();
-        Assert.assertFalse(litStmts.hasNext());
-        Iterator<Triple> knowsStmts = dataGraph.filter(null, FOAF.knows, null);
-        Assert.assertTrue(knowsStmts.hasNext());
-        Triple knowStmt = knowsStmts.next();
-        Assert.assertEquals(knowStmt.getSubject(), knowStmt.getObject());
-        Assert.assertEquals(litStmt.getSubject(), knowStmt.getObject());
-        Assert.assertEquals(litStmt.getSubject(), dataGraph.filter(null, OWL.sameAs, null).next().getObject());
-        Assert.assertEquals(knowStmt.getSubject(), uriC);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/pom.xml b/rdf/pom.xml
index bd9f5e9..6ce2eff 100644
--- a/rdf/pom.xml
+++ b/rdf/pom.xml
@@ -45,13 +45,14 @@
     <modules>
         <module>core</module>
         <module>core.test</module>
-        <module>ontologies</module>
-        <module>schemagen/main</module>
-        <module>schemagen/maven-plugin</module>
         <module>jena</module>
         <module>metadata</module>
+        <module>schemagen/main</module>
+        <module>schemagen/maven-plugin</module>
+        <module>ontologies</module>
         <module>rdfa</module>
         <module>simple.storage</module>
+        <module>utils</module>
     </modules>
 
 </project>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/LICENSE
----------------------------------------------------------------------
diff --git a/rdf/utils/LICENSE b/rdf/utils/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/rdf/utils/LICENSE
@@ -0,0 +1,201 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

http://git-wip-us.apache.org/repos/asf/clerezza/blob/74f5fdb3/rdf/utils/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/utils/pom.xml b/rdf/utils/pom.xml
new file mode 100644
index 0000000..0f6b648
--- /dev/null
+++ b/rdf/utils/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>clerezza</artifactId>
+        <groupId>org.apache.clerezza</groupId>
+        <version>7-SNAPSHOT</version>
+        <relativePath>../parent</relativePath>
+    </parent>
+    <groupId>org.apache.clerezza</groupId>
+    <artifactId>rdf.utils</artifactId>
+    <packaging>bundle</packaging>
+    <version>1.0.0-SNAPSHOT</version>
+    <name>Clerezza - RDF - Utilities</name>
+    <description>Utility classed to deal with Clerezza Models</description>
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.core</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza.commons-rdf</groupId>
+            <artifactId>commons-rdf-api</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza.commons-rdf</groupId>
+            <artifactId>commons-rdf-impl-utils</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.ontologies</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>rdf.core.test</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file