clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [6/6] clerezza git commit: CLEREZZA-964: using rdf-commons from clerezza-rdf-core repository
Date Thu, 19 Mar 2015 21:34:40 GMT
CLEREZZA-964: using rdf-commons from clerezza-rdf-core repository

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

Branch: refs/heads/rdf-commons
Commit: de5881d42112f2c68ff3dc8d9edf120389a7133a
Parents: 4bc320a
Author: Reto Gmuer <reto@apache.org>
Authored: Thu Mar 19 21:34:13 2015 +0000
Committer: Reto Gmuer <reto@apache.org>
Committed: Thu Mar 19 21:34:13 2015 +0000

----------------------------------------------------------------------
 rdf.utils/pom.xml                               |  18 +-
 .../apache/clerezza/rdf/utils/GraphNode.java    | 244 +++++++-------
 .../apache/clerezza/rdf/utils/GraphUtils.java   | 163 ++++++++++
 .../org/apache/clerezza/rdf/utils/IriUtil.java  |  63 ++++
 .../apache/clerezza/rdf/utils/MGraphUtils.java  | 164 ----------
 .../org/apache/clerezza/rdf/utils/RdfList.java  |  88 +++---
 .../clerezza/rdf/utils/SeeAlsoExpander.java     |  42 +--
 .../org/apache/clerezza/rdf/utils/Smusher.java  |  24 +-
 .../apache/clerezza/rdf/utils/UnionGraph.java   | 286 +++++++++++++++++
 .../apache/clerezza/rdf/utils/UnionMGraph.java  | 314 -------------------
 .../clerezza/rdf/utils/UnionWatchableGraph.java |  54 ++++
 .../clerezza/rdf/utils/UriMutatingGraph.java    | 223 +++++++++++++
 .../rdf/utils/UriMutatingTripleCollection.java  | 222 -------------
 .../apache/clerezza/rdf/utils/UriRefUtil.java   |  63 ----
 .../graphnodeprovider/GraphNodeProvider.java    |  10 +-
 .../rdf/utils/smushing/BaseSmusher.java         |  61 ++--
 .../clerezza/rdf/utils/smushing/IfpSmusher.java |  42 ++-
 .../rdf/utils/smushing/SameAsSmusher.java       |  33 +-
 .../clerezza/rdf/utils/GraphUtilsTest.java      | 104 ++++++
 .../apache/clerezza/rdf/utils/IfpSmushTest.java |  56 ++--
 .../clerezza/rdf/utils/MGraphUtilsTest.java     | 104 ------
 .../apache/clerezza/rdf/utils/RdfListTest.java  |  62 ++--
 .../clerezza/rdf/utils/SameAsSmushTest.java     |  26 +-
 .../clerezza/rdf/utils/TestGraphNode.java       | 146 ++++-----
 .../clerezza/rdf/utils/UnionGraphTest.java      |  78 +++++
 .../clerezza/rdf/utils/UnionMGraphTest.java     |  78 -----
 .../rdf/utils/smushing/SameAsSmushTest.java     |  31 +-
 27 files changed, 1392 insertions(+), 1407 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.utils/pom.xml b/rdf.utils/pom.xml
index b446eb5..16e120c 100644
--- a/rdf.utils/pom.xml
+++ b/rdf.utils/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <artifactId>clerezza</artifactId>
         <groupId>org.apache.clerezza</groupId>
-        <version>0.5</version>
+        <version>1.0.0-SNAPSHOT</version>
         <relativePath>../parent</relativePath>
     </parent>
     <groupId>org.apache.clerezza</groupId>
@@ -42,17 +42,27 @@
         <dependency>
             <groupId>org.apache.clerezza</groupId>
             <artifactId>rdf.core</artifactId>
-            <version>0.14</version>
+            <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>0.12</version>
+            <version>1.0.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.clerezza</groupId>
             <artifactId>rdf.core.test</artifactId>
-            <version>0.15</version>
+            <version>1.0.0-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
     </dependencies>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/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 487d7d2..8a1365f 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,35 +18,37 @@
  */
 package org.apache.clerezza.rdf.utils;
 
-import org.apache.clerezza.rdf.core.*;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+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 TripleCollection in immutable (i.e. is a {@link Graph}.
+ * it the underlying Graph in immutable (i.e. is a {@link ImmutableGraph}.
  *
  * @since 0.2
  * @author reto, mir
  */
 public class GraphNode {
 
-    private final Resource resource;
-    private final TripleCollection graph;
+    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 TripleCollection that describes the resource
+     * @param graph the Graph that describes the resource
      */
-    public GraphNode(Resource resource, TripleCollection graph) {
+    public GraphNode(RdfTerm resource, Graph graph) {
         if (resource == null) {
             throw new IllegalArgumentException("resource may not be null");
         }
@@ -62,7 +64,7 @@ public class GraphNode {
      *
      * @return the graph of this GraphNode
      */
-    public TripleCollection getGraph() {
+    public Graph getGraph() {
         return graph;
     }
 
@@ -71,7 +73,7 @@ public class GraphNode {
      *
      * @return the node represented by this GraphNode
      */
-    public Resource getNode() {
+    public RdfTerm getNode() {
         return resource;
     }
 
@@ -90,38 +92,38 @@ public class GraphNode {
      * as subject or object and recursively the context of the b-nodes in any
      * of these statements.
      *
-     * The triples in the Graph returned by this method contain the same bnode
+     * 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 Graph getNodeContext() {
+    public ImmutableGraph getNodeContext() {
         Lock l = readLock();
         l.lock();
         try {
-            final HashSet<Resource> dontExpand = new HashSet<Resource>();
+            final HashSet<RdfTerm> dontExpand = new HashSet<RdfTerm>();
             dontExpand.add(resource);
-            if (resource instanceof UriRef) {
-                return getContextOf((UriRef) resource, dontExpand).getGraph();
+            if (resource instanceof Iri) {
+                return getContextOf((Iri) resource, dontExpand).getImmutableGraph();
             }
-            return getContextOf(resource, dontExpand).getGraph();
+            return getContextOf(resource, dontExpand).getImmutableGraph();
         } finally {
             l.unlock();
         }
 
     }
 
-    private MGraph getContextOf(UriRef node, final Set<Resource> dontExpand) {
+    private Graph getContextOf(Iri node, final Set<RdfTerm> dontExpand) {
         final String uriPrefix = node.getUnicodeString()+'#';
         return getContextOf(node, dontExpand, new Acceptor() {
 
             @Override
-            public boolean expand(Resource resource) {
-                if (resource instanceof BNode) {
+            public boolean expand(RdfTerm resource) {
+                if (resource instanceof BlankNode) {
                     return true;
                 }
-                if (resource instanceof UriRef) {
-                    return ((UriRef)resource).getUnicodeString().startsWith(uriPrefix);
+                if (resource instanceof Iri) {
+                    return ((Iri)resource).getUnicodeString().startsWith(uriPrefix);
                 }
                 return false;
             }
@@ -129,19 +131,19 @@ public class GraphNode {
     }
 
     /**
-     * Returns the context of a <code>NonLiteral</code>
+     * 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 BNode it should be contained (potentially faster)
+     * is a BlankNode it should be contained (potentially faster)
      * @return the context of a node
      */
-    private MGraph getContextOf(Resource node, final Set<Resource> dontExpand) {
+    private Graph getContextOf(RdfTerm node, final Set<RdfTerm> dontExpand) {
         return getContextOf(node, dontExpand, new Acceptor() {
 
             @Override
-            public boolean expand(Resource resource) {
-                if (resource instanceof BNode) {
+            public boolean expand(RdfTerm resource) {
+                if (resource instanceof BlankNode) {
                     return true;
                 }
                 return false;
@@ -150,16 +152,16 @@ public class GraphNode {
     }
 
     private interface Acceptor {
-        boolean expand(Resource resource);
+        boolean expand(RdfTerm resource);
     }
-    private MGraph getContextOf(Resource node, final Set<Resource> dontExpand, Acceptor acceptor) {
-        MGraph result = new SimpleMGraph();
-        if (node instanceof NonLiteral) {
-            Iterator<Triple> forwardProperties = graph.filter((NonLiteral) node, null, null);
+    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);
-                Resource object = triple.getObject();
+                RdfTerm object = triple.getObject();
                 if (acceptor.expand(object) && !dontExpand.contains(object)) {
                     dontExpand.add(object);
                     result.addAll(getContextOf(object, dontExpand, acceptor));
@@ -170,7 +172,7 @@ public class GraphNode {
         while (backwardProperties.hasNext()) {
             Triple triple = backwardProperties.next();
             result.add(triple);
-            NonLiteral subject = triple.getSubject();
+            BlankNodeOrIri subject = triple.getSubject();
             if (acceptor.expand(subject) && !dontExpand.contains(subject)) {
                 dontExpand.add(subject);
                 result.addAll(getContextOf(subject, dontExpand, acceptor));
@@ -179,8 +181,8 @@ public class GraphNode {
         return result;
     }
 
-    private <T> Iterator<T> getTypeSelectedObjects(UriRef property, final Class<T> type) {
-        final Iterator<Resource> objects = getObjects(property);
+    private <T> Iterator<T> getTypeSelectedObjects(Iri property, final Class<T> type) {
+        final Iterator<RdfTerm> objects = getObjects(property);
         return new Iterator<T>() {
 
             T next = prepareNext();
@@ -204,7 +206,7 @@ public class GraphNode {
 
             private T prepareNext() {
                 while (objects.hasNext()) {
-                    Resource nextObject = objects.next();
+                    RdfTerm nextObject = objects.next();
                     if (type.isAssignableFrom(nextObject.getClass())) {
                         return (T) nextObject;
                     }
@@ -214,8 +216,8 @@ public class GraphNode {
         };
     }
 
-    public Iterator<Literal> getLiterals(UriRef property) {
-        final Iterator<Resource> objects = getObjects(property);
+    public Iterator<Literal> getLiterals(Iri property) {
+        final Iterator<RdfTerm> objects = getObjects(property);
         return new Iterator<Literal>() {
 
             Literal next = prepareNext();
@@ -239,7 +241,7 @@ public class GraphNode {
 
             private Literal prepareNext() {
                 while (objects.hasNext()) {
-                    Resource nextObject = objects.next();
+                    RdfTerm nextObject = objects.next();
                     if (nextObject instanceof Literal) {
                         return (Literal) nextObject;
                     }
@@ -257,8 +259,8 @@ public class GraphNode {
      * @return the number of triples in the underlying triple-collection
      *        which meet the specified condition
      */
-    public int countObjects(UriRef property) {
-        return countTriples(graph.filter((NonLiteral) resource, property, null));
+    public int countObjects(Iri property) {
+        return countTriples(graph.filter((BlankNodeOrIri) resource, property, null));
     }
 
     private int countTriples(final Iterator<Triple> triples) {
@@ -277,10 +279,10 @@ public class GraphNode {
      * @param property the property
      * @return
      */
-    public Iterator<Resource> getObjects(UriRef property) {
-        if (resource instanceof NonLiteral) {
-            final Iterator<Triple> triples = graph.filter((NonLiteral) resource, property, null);
-            return new Iterator<Resource>() {
+    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() {
@@ -288,7 +290,7 @@ public class GraphNode {
                 }
 
                 @Override
-                public Resource next() {
+                public RdfTerm next() {
                     final Triple triple = triples.next();
                     if (triple != null) {
                         return triple.getObject();
@@ -303,7 +305,7 @@ public class GraphNode {
                 }
             };
         } else {
-            return new Iterator<Resource>() {
+            return new Iterator<RdfTerm>() {
 
                 @Override
                 public boolean hasNext() {
@@ -311,7 +313,7 @@ public class GraphNode {
                 }
 
                 @Override
-                public Resource next() {
+                public RdfTerm next() {
                     return null;
                 }
 
@@ -333,11 +335,11 @@ public class GraphNode {
      * @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(UriRef property, Resource object) {
+    public boolean hasProperty(Iri property, RdfTerm object) {
         Lock l = readLock();
         l.lock();
         try {
-            Iterator<Resource> objects = getObjects(property);
+            Iterator<RdfTerm> objects = getObjects(property);
             if (object == null) {
                 return objects.hasNext();
             }
@@ -360,7 +362,7 @@ public class GraphNode {
      * @return the number of triples in the underlying triple-collection
      *        which meet the specified condition
      */
-    public int countSubjects(UriRef property) {
+    public int countSubjects(Iri property) {
         Lock l = readLock();
         l.lock();
         try {
@@ -377,9 +379,9 @@ public class GraphNode {
      * @param property the property
      * @return
      */
-    public Iterator<NonLiteral> getSubjects(UriRef property) {
+    public Iterator<BlankNodeOrIri> getSubjects(Iri property) {
         final Iterator<Triple> triples = graph.filter(null, property, resource);
-        return new Iterator<NonLiteral>() {
+        return new Iterator<BlankNodeOrIri>() {
 
             @Override
             public boolean hasNext() {
@@ -387,7 +389,7 @@ public class GraphNode {
             }
 
             @Override
-            public NonLiteral next() {
+            public BlankNodeOrIri next() {
                 return triples.next().getSubject();
             }
 
@@ -398,24 +400,24 @@ public class GraphNode {
         };
     }
 
-    public Iterator<UriRef> getUriRefObjects(UriRef property) {
-        return getTypeSelectedObjects(property, UriRef.class);
+    public Iterator<Iri> getIriObjects(Iri property) {
+        return getTypeSelectedObjects(property, Iri.class);
 
     }
 
     /**
-     * Get all available properties as an {@link Iterator}<{@link UriRef}>.
-     * You can use <code>getObjects(UriRef property)</code> to get the values of
+     * 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<UriRef> getProperties() {
-        if (resource instanceof NonLiteral) {
-            final Iterator<Triple> triples = graph.filter((NonLiteral) resource, null, null);
+    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<UriRef>() {
+            return new Iterator<Iri>() {
 
                 @Override
                 public boolean hasNext() {
@@ -423,7 +425,7 @@ public class GraphNode {
                 }
 
                 @Override
-                public UriRef next() {
+                public Iri next() {
                     return null;
                 }
 
@@ -436,13 +438,13 @@ public class GraphNode {
     }
 
     /**
-     * Get all inverse properties as an {@link Iterator}<{@link UriRef}>.
-     * You can use <code>getSubject(UriRef property)</code> to get the values of
+     * 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<UriRef> getInverseProperties() {
+    public Iterator<Iri> getInverseProperties() {
         final Iterator<Triple> triples = graph.filter(null, null, resource);
         return getUniquePredicates(triples);
     }
@@ -450,11 +452,11 @@ public class GraphNode {
     /**
      *
      * @param triples
-     * @returnan {@link Iterator}<{@link UriRef}> containing the predicates from
+     * @returnan {@link Iterator}<{@link Iri}> containing the predicates from
      * an {@link Iterator}<{@link Triple}>
      */
-    private Iterator<UriRef> getUniquePredicates(final Iterator<Triple> triples) {
-        final Set<UriRef> resultSet = new HashSet<UriRef>();
+    private Iterator<Iri> getUniquePredicates(final Iterator<Triple> triples) {
+        final Set<Iri> resultSet = new HashSet<Iri>();
         while (triples.hasNext()) {
             resultSet.add(triples.next().getPredicate());
         }
@@ -467,9 +469,9 @@ public class GraphNode {
      * @param predicate
      * @param object
      */
-    public void addProperty(UriRef predicate, Resource object) {
-        if (resource instanceof NonLiteral) {
-            graph.add(new TripleImpl((NonLiteral) resource, predicate, 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");
         }
@@ -483,7 +485,7 @@ public class GraphNode {
      * @param property the predicate of the triple to be created
      * @param value the value of the typed literal object
      */
-    public void addPropertyValue(UriRef property, Object value) {
+    public void addPropertyValue(Iri property, Object value) {
         addProperty(property,
                 LiteralFactory.getInstance().createTypedLiteral(value));
     }
@@ -495,9 +497,9 @@ public class GraphNode {
      * @param predicate
      * @param subject
      */
-    public void addInverseProperty(UriRef predicate, Resource subject) {
-        if (subject instanceof NonLiteral) {
-            graph.add(new TripleImpl((NonLiteral) subject, predicate, resource));
+    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");
         }
@@ -506,13 +508,13 @@ public class GraphNode {
 
     /**
      * creates and returns an <code>RdfList</code> for the node and
-     * TripleCollection represented by this object.
+     * Graph represented by this object.
      *
      * @return a List to easy access the rdf:List represented by this node
      */
-    public List<Resource> asList() {
-        if (resource instanceof NonLiteral) {
-            return new RdfList((NonLiteral) resource, graph);
+    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");
         }
@@ -524,9 +526,9 @@ public class GraphNode {
      *
      * @param predicate
      */
-    public void deleteProperties(UriRef predicate) {
-        if (resource instanceof NonLiteral) {
-            Iterator<Triple> tripleIter = graph.filter((NonLiteral) resource, predicate, null);
+    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();
@@ -544,9 +546,9 @@ public class GraphNode {
      * @param predicate
      * @param object
      */
-    public void deleteProperty(UriRef predicate, Resource object) {
-        if (resource instanceof NonLiteral) {
-            graph.remove(new TripleImpl((NonLiteral) resource, predicate, object));
+    public void deleteProperty(Iri predicate, RdfTerm object) {
+        if (resource instanceof BlankNodeOrIri) {
+            graph.remove(new TripleImpl((BlankNodeOrIri) resource, predicate, object));
         }
     }
 
@@ -556,27 +558,27 @@ public class GraphNode {
     }
 
     /**
-     * Replaces the graph node resouce with the specified <code>NonLiteral</code>.
+     * 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(NonLiteral replacement) {
+    public GraphNode replaceWith(BlankNodeOrIri replacement) {
         return replaceWith(replacement, false);
     }
 
     /**
-     * Replaces the graph node resouce with the specified <code>NonLiteral</code>.
+     * 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(NonLiteral replacement, boolean checkPredicates) {
-        MGraph newTriples = new SimpleMGraph();
+    public GraphNode replaceWith(BlankNodeOrIri replacement, boolean checkPredicates) {
+        Graph newTriples = new SimpleGraph();
         if (!(resource instanceof Literal)) {
-            Iterator<Triple> subjectTriples = graph.filter((NonLiteral) resource, null,
+            Iterator<Triple> subjectTriples = graph.filter((BlankNodeOrIri) resource, null,
                     null);
             while (subjectTriples.hasNext()) {
                 Triple triple = subjectTriples.next();
@@ -600,14 +602,14 @@ public class GraphNode {
         graph.addAll(newTriples);
         newTriples.clear();
 
-        if (checkPredicates && replacement instanceof UriRef
-                && resource instanceof UriRef) {
+        if (checkPredicates && replacement instanceof Iri
+                && resource instanceof Iri) {
             Iterator<Triple> predicateTriples = graph.filter(null,
-                    (UriRef) resource, null);
+                    (Iri) resource, null);
             while (predicateTriples.hasNext()) {
                 Triple triple = predicateTriples.next();
                 Triple newTriple = new TripleImpl(triple.getSubject(),
-                        (UriRef) replacement, triple.getObject());
+                        (Iri) replacement, triple.getObject());
                 predicateTriples.remove();
                 newTriples.add(newTriple);
             }
@@ -624,8 +626,8 @@ public class GraphNode {
      * @param property
      * @return
      */
-    public Iterator<GraphNode> getObjectNodes(UriRef property) {
-        final Iterator<Resource> objects = this.getObjects(property);
+    public Iterator<GraphNode> getObjectNodes(Iri property) {
+        final Iterator<RdfTerm> objects = this.getObjects(property);
         return new Iterator<GraphNode>() {
 
             @Override
@@ -635,7 +637,7 @@ public class GraphNode {
 
             @Override
             public GraphNode next() {
-                Resource object = objects.next();
+                RdfTerm object = objects.next();
                 return new GraphNode(object, graph);
 
             }
@@ -655,8 +657,8 @@ public class GraphNode {
      * @param property
      * @return
      */
-    public Iterator<GraphNode> getSubjectNodes(UriRef property) {
-        final Iterator<NonLiteral> subjects = this.getSubjects(property);
+    public Iterator<GraphNode> getSubjectNodes(Iri property) {
+        final Iterator<BlankNodeOrIri> subjects = this.getSubjects(property);
         return new Iterator<GraphNode>() {
 
             @Override
@@ -666,7 +668,7 @@ public class GraphNode {
 
             @Override
             public GraphNode next() {
-                Resource object = subjects.next();
+                RdfTerm object = subjects.next();
                 return new GraphNode(object, graph);
 
             }
@@ -700,13 +702,12 @@ public class GraphNode {
     }
 
     /**
-     * @return a ReadLock if the underlying Graph is a LockableMGraph it returns its lock, otherwise null
+     * @return a ReadLock if the underlying ImmutableGraph is a LockableGraph it returns its lock, otherwise null
      */
     public Lock readLock() {
-        if (getGraph() instanceof LockableMGraph) {
-            return ((LockableMGraph) getGraph()).getLock().readLock();
-        }
-        return new FakeLock();
+
+            return getGraph().getLock().readLock();
+
     }
 
     /**
@@ -714,33 +715,8 @@ public class GraphNode {
      * @return
      */
     public Lock writeLock() {
-        if (getGraph() instanceof LockableMGraph) {
-            return ((LockableMGraph) getGraph()).getLock().writeLock();
-        }
-        return new FakeLock();
-    }
-
-    private static class FakeLock implements Lock {
-
-        public void lock() {
-        }
-
-        public void lockInterruptibly() throws java.lang.InterruptedException {
-        }
 
-        public boolean tryLock() {
-            return false;
-        }
+            return (getGraph()).getLock().writeLock();
 
-        public boolean tryLock(long l, java.util.concurrent.TimeUnit timeUnit) throws java.lang.InterruptedException {
-            return false;
-        }
-
-        public void unlock() {
-        }
-
-        public java.util.concurrent.locks.Condition newCondition() {
-            return null;
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/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/de5881d4/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/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java
deleted file mode 100644
index ab003b9..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java
+++ /dev/null
@@ -1,164 +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.clerezza.rdf.core.BNode;
-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.TripleCollection;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-
-/**
- * Utility methods to manipulate <code>MGraph</code>s
- *
- * @author reto
- */
-public class MGraphUtils {
-
-    /**
-     * Removes a subGraph from an MGraph. The subGraph must match a subgraph of
-     * MGraph 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.MGraphUtils.NoSuchSubGraphException
-     */
-    public static void removeSubGraph(MGraph mGraph, TripleCollection 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 TripleCollection unGroundedTriples = new SimpleMGraph();
-        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 = getTripleWithBNodeObject(unGroundedTriples);
-            if (triple == null) {
-                break;
-            }
-            final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples);
-            NonLiteral subject = triple.getSubject();
-            Graph context = objectGN.getNodeContext();
-            Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null);
-            while (potentialIter.hasNext()) {
-                try {
-                    final Triple potentialTriple = potentialIter.next();
-                    BNode potentialMatch = (BNode)potentialTriple.getObject();
-                    final Graph 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 = getTripleWithBNodeSubject(unGroundedTriples);
-            if (triple == null) {
-                break;
-            }
-            final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples);
-            Resource object = triple.getObject();
-            if (object instanceof BNode) {
-                object = null;
-            }
-            Graph context = subjectGN.getNodeContext();
-            Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object);
-            while (potentialIter.hasNext()) {
-                try {
-                    final Triple potentialTriple = potentialIter.next();
-                    BNode potentialMatch = (BNode)potentialTriple.getSubject();
-                    final Graph 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 BNode) {
-            return false;
-        }
-        if (triple.getObject() instanceof BNode) {
-            return false;
-        }
-        return true;
-    }
-
-    /** retrun triples with a bnode only at object position
-     *
-     * @param triples
-     * @return
-     */
-    private static Triple getTripleWithBNodeObject(TripleCollection triples) {
-        for (Triple triple : triples) {
-            if (triple.getSubject() instanceof BNode) {
-                continue;
-            }
-            if (triple.getObject() instanceof BNode) {
-                return triple;
-            }
-        }
-        return null;
-    }
-    private static Triple getTripleWithBNodeSubject(TripleCollection triples) {
-        for (Triple triple : triples) {
-            if (triple.getSubject() instanceof BNode) {
-                return triple;
-            }
-        }
-        return null;
-    }
-
-    public static class NoSuchSubGraphException extends Exception {
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/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
index edaa46d..db994e9 100644
--- 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
@@ -27,59 +27,59 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+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>TripleCollection</code>. It reads the data from the
- * <code>TripleCollection</code> when it is first needed, so changes to the
- * TripleCollection affecting the rdf:List may or may not have an effect on the
+ * 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>TripleCollection</code>s) is
+ * for read operations (such as for immutable <code>Graph</code>s) is
  * not problematic.
  *
  * @author rbn, mir
  */
-public class RdfList extends AbstractList<Resource> {
+public class RdfList extends AbstractList<RdfTerm> {
 
     private static final Logger logger = LoggerFactory.getLogger(RdfList.class);
 
-    private final static UriRef RDF_NIL =
-            new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
+    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<NonLiteral> listList = new ArrayList<NonLiteral>();
-    private List<Resource> valueList = new ArrayList<Resource>();
-    private NonLiteral firstList;
-    private TripleCollection tc;
+    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>listResource</code> will always be the first list.
+     * <code>listRdfTerm</code> will always be the first list.
      *
-     * @param listResource
+     * @param listRdfTerm
      * @param tc
      */
-    public RdfList(NonLiteral listResource, TripleCollection tc) {
-        firstList = listResource;
+    public RdfList(BlankNodeOrIri listRdfTerm, Graph tc) {
+        firstList = listRdfTerm;
         this.tc = tc;
 
     }
@@ -90,28 +90,28 @@ public class RdfList extends AbstractList<Resource> {
      * @param listNode
      */
     public RdfList(GraphNode listNode) {
-        this((NonLiteral)listNode.getNode(), listNode.getGraph());
+        this((BlankNodeOrIri)listNode.getNode(), listNode.getGraph());
     }
 
     /**
      * Creates an empty RdfList by writing a triple
-     * "{@code listResource} owl:sameAs rdf.nil ." to {@code tc}.
+     * "{@code listRdfTerm} owl:sameAs rdf.nil ." to {@code tc}.
      *
-     * @param listResource
+     * @param listRdfTerm
      * @param tc
      * @return    an empty rdf:List.
      * @throws IllegalArgumentException
-     *        if the provided {@code  listResource} is a non-empty rdf:List.
+     *        if the provided {@code  listRdfTerm} is a non-empty rdf:List.
      */
-    public static RdfList createEmptyList(NonLiteral listResource, TripleCollection tc)
+    public static RdfList createEmptyList(BlankNodeOrIri listRdfTerm, Graph tc)
             throws IllegalArgumentException {
 
-        if (!tc.filter(listResource, RDF.first, null).hasNext()) {
-            RdfList list = new RdfList(listResource, tc);
-            list.tc.add(new TripleImpl(listResource, OWL.sameAs, RDF_NIL));
+        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(listResource + "is a non-empty rdf:List.");
+            throw new IllegalArgumentException(listRdfTerm + "is a non-empty rdf:List.");
         }
     }
 
@@ -119,7 +119,7 @@ public class RdfList extends AbstractList<Resource> {
         if (totallyExpanded) {
             return;
         }
-        NonLiteral currentList;
+        BlankNodeOrIri currentList;
         if (listList.size() > 0) {
             currentList = listList.get(listList.size()-1);
         } else {
@@ -150,7 +150,7 @@ public class RdfList extends AbstractList<Resource> {
 
 
     @Override
-    public Resource get(int index) {
+    public RdfTerm get(int index) {
         expandTill(index + 1);
         return valueList.get(index);
     }
@@ -162,7 +162,7 @@ public class RdfList extends AbstractList<Resource> {
     }
 
     @Override
-    public void add(int index, Resource element) {
+    public void add(int index, RdfTerm element) {
         expandTill(index);
         if (index == 0) {
             //special casing to make sure the first list remains the same resource
@@ -187,9 +187,9 @@ public class RdfList extends AbstractList<Resource> {
      * @param index is > 0
      * @param element
      */
-    private void addInRdfList(int index, Resource element) {
+    private void addInRdfList(int index, RdfTerm element) {
         expandTill(index+1);
-        NonLiteral newList = new BNode() {
+        BlankNodeOrIri newList = new BlankNode() {
         };
         tc.add(new TripleImpl(newList, RDF.first, element));
         if (index < listList.size()) {
@@ -205,7 +205,7 @@ public class RdfList extends AbstractList<Resource> {
     }
 
     @Override
-    public Resource remove(int index) {
+    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)) {
@@ -233,28 +233,28 @@ public class RdfList extends AbstractList<Resource> {
         return valueList.remove(index);
     }
 
-    private NonLiteral getRest(NonLiteral list) {
-        return (NonLiteral) tc.filter(list, RDF.rest, null).next().getObject();
+    private BlankNodeOrIri getRest(BlankNodeOrIri list) {
+        return (BlankNodeOrIri) tc.filter(list, RDF.rest, null).next().getObject();
     }
 
-    private Resource getFirstEntry(final NonLiteral listResource) {
+    private RdfTerm getFirstEntry(final BlankNodeOrIri listRdfTerm) {
         try {
-            return tc.filter(listResource, RDF.first, null).next().getObject();
+            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(listResource, tc);
+                        final GraphNode graphNode = new GraphNode(listRdfTerm, tc);
                         Serializer.getInstance().serialize(fileOutputStream, graphNode.getNodeContext(), SupportedFormat.N_TRIPLE);
                         fileOutputStream.flush();
                         logger.warn("GraphNode: " + graphNode);
-                        final Iterator<UriRef> properties = graphNode.getProperties();
+                        final Iterator<Iri> properties = graphNode.getProperties();
                         while (properties.hasNext()) {
                             logger.warn("available: " + properties.next());
                         }
-                        return new RuntimeException("broken list " + listResource, e);
+                        return new RuntimeException("broken list " + listRdfTerm, e);
                     } catch (Exception ex) {
                         return new RuntimeException(ex);
                     }
@@ -265,7 +265,7 @@ public class RdfList extends AbstractList<Resource> {
         }
     }
 
-    public NonLiteral getListResource() {
+    public BlankNodeOrIri getListRdfTerm() {
         return firstList;
     }
 

http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/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
index ecf3ba5..fef7e4b 100644
--- 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
@@ -23,9 +23,9 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.concurrent.locks.Lock;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
+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;
@@ -37,7 +37,7 @@ import org.apache.clerezza.rdf.ontologies.RDFS;
  */
 public class SeeAlsoExpander {
     /**
-     * using TcManger instead of TcProvider as this ensures LockableMGraphs
+     * using TcManger instead of TcProvider as this ensures LockableGraphs
      */
     private final TcManager tcManager;
     public SeeAlsoExpander(TcManager tcManager) {
@@ -56,32 +56,32 @@ public class SeeAlsoExpander {
      * @return a new GraphNode over the union of the original and all expansion graphs
      */
     public GraphNode expand(GraphNode node, int recursion) {
-        Set<UriRef> alreadyVisited = new HashSet();
-        Set<TripleCollection> resultTripleCollections = new HashSet<TripleCollection>();
+        Set<Iri> alreadyVisited = new HashSet();
+        Set<Graph> resultTripleCollections = new HashSet<Graph>();
         resultTripleCollections.add(node.getGraph());
-        for (UriRef uriRef : expand(node, alreadyVisited, recursion)) {
+        for (Iri uriRef : expand(node, alreadyVisited, recursion)) {
             try {
-                resultTripleCollections.add(tcManager.getTriples(uriRef));
+                resultTripleCollections.add(tcManager.getGraph(uriRef));
             } catch (NoSuchEntityException e) {
                 //ignore
             }
         }
         return new GraphNode(node.getNode(),
-                new UnionMGraph(resultTripleCollections.toArray(
-                new TripleCollection[resultTripleCollections.size()])));
+                new UnionGraph(resultTripleCollections.toArray(
+                new Graph[resultTripleCollections.size()])));
 
     }
 
-    private Set<UriRef> getSeeAlsoObjectUris(GraphNode node) {
-        Set<UriRef> result = new HashSet<UriRef>();
+    private Set<Iri> getSeeAlsoObjectUris(GraphNode node) {
+        Set<Iri> result = new HashSet<Iri>();
         Lock l = node.readLock();
         l.lock();
         try {
-            Iterator<Resource> objects = node.getObjects(RDFS.seeAlso);
+            Iterator<RdfTerm> objects = node.getObjects(RDFS.seeAlso);
             while (objects.hasNext()) {
-                Resource next = objects.next();
-                if (next instanceof UriRef) {
-                    result.add((UriRef)next);
+                RdfTerm next = objects.next();
+                if (next instanceof Iri) {
+                    result.add((Iri)next);
                 }
             }
         } finally {
@@ -90,18 +90,18 @@ public class SeeAlsoExpander {
         return result;
     }
 
-    private Set<UriRef> expand(GraphNode node, Set<UriRef> alreadyVisited, int recursion) {
-        Set<UriRef> rdfSeeAlsoTargets = getSeeAlsoObjectUris(node);
-        Set<UriRef> result = new HashSet<UriRef>();
+    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 (UriRef target : rdfSeeAlsoTargets) {
+            for (Iri target : rdfSeeAlsoTargets) {
                 try {
                     result.addAll(expand(new GraphNode(node.getNode(),
-                        tcManager.getTriples(target)), alreadyVisited, recursion));
+                        tcManager.getGraph(target)), alreadyVisited, recursion));
                 } catch (NoSuchEntityException e) {
                     //ignore
                 }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/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
index 269ea92..8d0ea45 100644
--- 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
@@ -18,10 +18,7 @@
  */
 package org.apache.clerezza.rdf.utils;
 
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
+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;
@@ -46,8 +43,8 @@ public class Smusher {
      * @param mGraph
      * @param tBox
      */
-    public static void smush(MGraph mGraph, TripleCollection tBox) {
-        smush(lockable(mGraph), tBox);
+    public static void smush(Graph mGraph, Graph tBox) {
+        new IfpSmusher().smush(mGraph, tBox);
     }
 
     /**
@@ -56,20 +53,9 @@ public class Smusher {
      * @param mGraph
      * @param owlSameStatements 
      */
-    public static void sameAsSmush(MGraph mGraph, TripleCollection owlSameStatements) {
-        sameAsSmush(lockable(mGraph), owlSameStatements);
-    }
-    
-    public static void smush(LockableMGraph mGraph, TripleCollection tBox) {
-        new IfpSmusher().smush(mGraph, tBox);
-    }
-
-    public static void sameAsSmush(LockableMGraph mGraph, TripleCollection owlSameStatements) {
+    public static void sameAsSmush(Graph mGraph, Graph owlSameStatements) {
         new SameAsSmusher().smush(mGraph, owlSameStatements, true);
     }
 
-    private static LockableMGraph lockable(MGraph mGraph) {
-        return mGraph instanceof LockableMGraph ? 
-                (LockableMGraph) mGraph : new LockableMGraphWrapper(mGraph);
-    }
+
 }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/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/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionMGraph.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionMGraph.java
deleted file mode 100644
index dbcdf23..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionMGraph.java
+++ /dev/null
@@ -1,314 +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.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Resource;
-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.LockableMGraph;
-import org.apache.clerezza.rdf.core.event.FilterTriple;
-import org.apache.clerezza.rdf.core.event.GraphListener;
-import org.apache.clerezza.rdf.core.impl.AbstractMGraph;
-
-/**
- * 
- * 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 UnionMGraph extends AbstractMGraph implements LockableMGraph {
-
-    private TripleCollection[] baseTripleCollections;
-    private Lock readLock;
-    private Lock writeLock;
-
-    /**
-     * Constructs a UnionMGraph over the specified baseTripleCollections. Write
-     * and delete operations are forwarded to the first baseTripleCollections. 
-     * 
-     * @param baseTripleCollections the baseTripleCollections
-     */
-    public UnionMGraph(TripleCollection... baseTripleCollections) {
-        this.baseTripleCollections = baseTripleCollections;
-        readLock = getPartialReadLock(0);
-        writeLock = createWriteLock();
-    }
-
-    @Override
-    public int size() {
-        int size = 0;
-        for (TripleCollection tripleCollection : baseTripleCollections) {
-            size += tripleCollection.size();
-        }
-        return size;
-    }
-
-    @Override
-    public Iterator<Triple> performFilter(final NonLiteral subject,
-            final UriRef predicate, final Resource 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;
-        }
-        UnionMGraph other = (UnionMGraph) obj;
-        Set<TripleCollection> otherGraphs =
-                new HashSet(Arrays.asList(other.baseTripleCollections));
-        Set<TripleCollection> thisGraphs =
-                new HashSet(Arrays.asList(baseTripleCollections));
-        return thisGraphs.equals(otherGraphs)
-                && baseTripleCollections[0].equals(other.baseTripleCollections[0]);
-    }
-
-    @Override
-    public int hashCode() {
-        int hash = 0;
-        for (TripleCollection graph : baseTripleCollections) {
-            hash += graph.hashCode();
-        }
-        hash *= baseTripleCollections[0].hashCode();
-        return hash;
-    }
-
-    @Override
-    public void addGraphListener(GraphListener listener, FilterTriple filter) {
-        for (TripleCollection tripleCollection : baseTripleCollections) {
-            tripleCollection.addGraphListener(listener, filter);
-        }
-    }
-
-    @Override
-    public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
-        for (TripleCollection tripleCollection : baseTripleCollections) {
-            tripleCollection.addGraphListener(listener, filter, delay);
-        }
-    }
-
-    @Override
-    public void removeGraphListener(GraphListener listener) {
-        for (TripleCollection tripleCollection : baseTripleCollections) {
-            tripleCollection.removeGraphListener(listener);
-        }
-    }
-
-    @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++) {
-            TripleCollection tripleCollection = baseTripleCollections[i];
-            if (tripleCollection instanceof LockableMGraph) {
-                final Lock lock = ((LockableMGraph) tripleCollection).getLock().readLock();
-                resultList.add(lock);
-            }
-        }
-        return new UnionLock(resultList.toArray(new Lock[resultList.size()]));
-    }
-
-    
-    private Lock createWriteLock() {
-        Lock partialReadLock =  getPartialReadLock(1);
-        if (baseTripleCollections[0] instanceof LockableMGraph) {
-            Lock baseWriteLock =
-                    ((LockableMGraph)baseTripleCollections[0]).getLock().writeLock();
-            return new UnionLock(baseWriteLock, partialReadLock);
-
-        } else {
-            return 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/de5881d4/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);
+        }
+    }
+
+    
+}


Mime
View raw message