You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by ha...@apache.org on 2018/11/14 02:55:28 UTC

[1/3] clerezza git commit: CLEREZZA-1026: Copy additional classes from rdf.core to api.impl and refactor api.impl

Repository: clerezza
Updated Branches:
  refs/heads/reunited f06386fcf -> 829e5fa56


http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/graph/GraphTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/graph/GraphTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/graph/GraphTest.java
new file mode 100644
index 0000000..66ad861
--- /dev/null
+++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/graph/GraphTest.java
@@ -0,0 +1,563 @@
+/*
+ * 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.api.impl.graph;
+
+import org.apache.clerezza.api.*;
+import org.apache.clerezza.api.impl.TripleImpl;
+import org.apache.clerezza.api.impl.literal.PlainLiteralImpl;
+import org.apache.clerezza.api.impl.literal.TypedLiteralImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.*;
+
+
+
+/**
+ * A generic abstract test class, implementations overwrite this class,
+ * providing an implementation of the getEmptyGraph method.
+ *
+ * @author reto, szalay, mir, hhn
+ */
+public abstract class GraphTest {
+
+    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");
+    private final IRI xmlLiteralType =
+            new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral");
+    private Literal literal1 = new PlainLiteralImpl("literal1");
+    private Literal literal2 = new PlainLiteralImpl("literal2");
+    private BlankNode bnode1 = new BlankNode();
+    private BlankNode bnode2 = new BlankNode();
+    private Triple trpl1 = new TripleImpl(uriRef2, uriRef2, literal1);
+    private Triple trpl2 = new TripleImpl(uriRef1, uriRef2, uriRef1);
+    private Triple trpl3 = new TripleImpl(bnode2, uriRef3, literal2);
+    private Triple trpl4 = new TripleImpl(uriRef3, uriRef4, literal2);
+    
+    /**
+     * Subclasses implement this method to provide implementation instances of
+     * Graph. This method may be called an arbitrary amount of time,
+     * independently whether previously returned Graph are still in use or not.
+     *
+     * @return an empty Graph of the implementation to be tested
+     */
+    protected abstract Graph getEmptyGraph();
+    
+    @Test
+    public void testAddCountAndGetTriples() {
+        Graph graph = getEmptyGraph();
+        Assert.assertEquals(0, graph.size());
+        final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
+        graph.add(triple1);
+        Assert.assertEquals(1, graph.size());
+        Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, uriRef1);
+        Assert.assertTrue(tripleIter.hasNext());
+        Triple tripleGot = tripleIter.next();
+        Assert.assertEquals(triple1, tripleGot);
+        Assert.assertFalse(tripleIter.hasNext());
+        BlankNode bnode = new BlankNode() {};
+        graph.add(new TripleImpl(bnode, uriRef1, uriRef3));
+        graph.add(new TripleImpl(bnode, uriRef1, uriRef4));
+        tripleIter = graph.filter(null, uriRef1, null);
+        Set<BlankNodeOrIRI> subjectInMatchingTriples = new HashSet<BlankNodeOrIRI>();
+        Set<RDFTerm> objectsInMatchingTriples = new HashSet<RDFTerm>();
+        while (tripleIter.hasNext()) {
+            Triple triple = tripleIter.next();
+            subjectInMatchingTriples.add(triple.getSubject());
+            objectsInMatchingTriples.add(triple.getObject());
+        }
+        Assert.assertEquals(1, subjectInMatchingTriples.size());
+        Assert.assertEquals(2, objectsInMatchingTriples.size());
+        Set<RDFTerm> expectedObjects = new HashSet<RDFTerm>();
+        expectedObjects.add(uriRef3);
+        expectedObjects.add(uriRef4);
+        Assert.assertEquals(expectedObjects, objectsInMatchingTriples);
+        graph.add(new TripleImpl(bnode, uriRef4, bnode));
+        tripleIter = graph.filter(null, uriRef4, null);
+        Assert.assertTrue(tripleIter.hasNext());
+        Triple retrievedTriple = tripleIter.next();
+        Assert.assertFalse(tripleIter.hasNext());
+        Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
+        tripleIter = graph.filter(uriRef1, uriRef2, null);
+        Assert.assertTrue(tripleIter.hasNext());
+        retrievedTriple = tripleIter.next();
+        Assert.assertFalse(tripleIter.hasNext());
+        Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
+    }
+    
+    @Test
+    public void testRemoveAllTriples() {
+        Graph graph = getEmptyGraph();
+        Assert.assertEquals(0, graph.size());
+        graph.add(new TripleImpl(uriRef1, uriRef2, uriRef3));
+        graph.add(new TripleImpl(uriRef2, uriRef3, uriRef4));
+        Assert.assertEquals(2, graph.size());
+        graph.clear();
+        Assert.assertEquals(0, graph.size());
+    }
+
+    @Test
+    public void testUseTypedLiterals() {
+        Graph graph = getEmptyGraph();
+        Assert.assertEquals(0, graph.size());
+        Literal value = new TypedLiteralImpl("<elem>value</elem>",xmlLiteralType);
+        final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value);
+        graph.add(triple1);
+        Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null);
+        Assert.assertTrue(tripleIter.hasNext());
+        RDFTerm gotValue = tripleIter.next().getObject();
+        Assert.assertEquals(value, gotValue);
+    }
+
+    @Test
+    public void testUseLanguageLiterals() {
+        Graph graph = getEmptyGraph();
+        Assert.assertEquals(0, graph.size());
+        Language language = new Language("it");
+        Literal value = new PlainLiteralImpl("<elem>value</elem>",language);
+        final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value);
+        graph.add(triple1);
+        Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null);
+        Assert.assertTrue(tripleIter.hasNext());
+        RDFTerm gotValue = tripleIter.next().getObject();
+        Assert.assertEquals(value, gotValue);
+        Assert.assertEquals(language, ((Literal)gotValue).getLanguage());
+    }
+
+    @Test
+    public void testRemoveViaIterator() {
+        Graph graph = getEmptyGraph();
+        Assert.assertEquals(0, graph.size());
+        final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
+        graph.add(triple1);
+        final TripleImpl triple2 = new TripleImpl(uriRef1, uriRef2, uriRef4);
+        graph.add(triple2);
+        Assert.assertEquals(2, graph.size());
+        Iterator<Triple> iterator = graph.iterator();
+        while (iterator.hasNext()) {
+            iterator.next();
+            iterator.remove();
+        }
+        Assert.assertEquals(0, graph.size());
+    }
+
+    @Test
+    public void testGetSize() throws Exception {
+        Graph graph = getEmptyGraph();
+        // The test graph must always be empty after test fixture setup
+        Assert.assertEquals(0, graph.size());
+    }
+
+
+    @Test
+    public void testAddSingleTriple() throws Exception {
+        Graph graph = getEmptyGraph();
+        final Triple triple= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/alice");
+        Assert.assertEquals(0, graph.size());
+        Assert.assertTrue(graph.add(triple));
+        Assert.assertEquals(1, graph.size());
+    }
+
+
+    @Test
+    public void testAddSameTripleTwice() throws Exception {
+        Graph graph = getEmptyGraph();
+        final Triple triple= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/alice");
+        Assert.assertEquals(0, graph.size());
+        Assert.assertTrue(graph.add(triple));
+        Assert.assertFalse(graph.add(triple)); // ImmutableGraph does not change
+        Assert.assertEquals(1, graph.size());
+    }
+
+
+    @Test
+    public void testRemoveSingleTriple() throws Exception {
+        Graph graph = getEmptyGraph();
+        final Triple triple= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/alice");
+        Assert.assertTrue(graph.add(triple));
+        Assert.assertTrue(graph.remove(triple));
+        Assert.assertEquals(0, graph.size());
+    }
+
+    @Test
+    public void testRemoveSameTripleTwice() throws Exception {
+        Graph graph = getEmptyGraph();
+        final Triple tripleAlice= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/alice");
+        final Triple tripleBob= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/bob");
+        Assert.assertTrue(graph.add(tripleAlice));
+        Assert.assertTrue(graph.add(tripleBob));
+        Assert.assertTrue(graph.remove(tripleAlice));
+        Assert.assertFalse(graph.remove(tripleAlice));
+        Assert.assertEquals(1, graph.size());
+    }
+
+    @Test
+    public void testGetSameBlankNode() throws Exception {
+        Graph graph = getEmptyGraph();
+        BlankNode bNode = new BlankNode();
+        final IRI HAS_NAME = new IRI("http://example.org/ontology/hasName");
+        final PlainLiteralImpl name = new PlainLiteralImpl("http://example.org/people/alice");
+        final PlainLiteralImpl name2 = new PlainLiteralImpl("http://example.org/people/bob");
+        final Triple tripleAlice = new TripleImpl(bNode, HAS_NAME, name);
+        final Triple tripleBob = new TripleImpl(bNode, HAS_NAME, name2);
+        Assert.assertTrue(graph.add(tripleAlice));
+        Assert.assertTrue(graph.add(tripleBob));
+        Iterator<Triple> result = graph.filter(null, HAS_NAME, name);
+        Assert.assertEquals(bNode, result.next().getSubject());
+    }
+
+    @Test
+    public void testContainsIfContained() throws Exception {
+        Graph graph = getEmptyGraph();
+        final Triple triple= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/alice");
+        Assert.assertTrue(graph.add(triple));
+        Assert.assertTrue(graph.contains(triple));
+    }
+
+
+    @Test
+    public void testContainsIfEmpty() throws Exception {
+        Graph graph = getEmptyGraph();
+        final Triple triple= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/alice");
+        Assert.assertFalse(graph.contains(triple));
+    }
+
+
+    @Test
+    public void testContainsIfNotContained() throws Exception {
+        Graph graph = getEmptyGraph();
+        final Triple tripleAdd= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/alice");
+        final Triple tripleTest= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/bob");
+        Assert.assertTrue(graph.add(tripleAdd));
+        Assert.assertFalse(graph.contains(tripleTest));
+    }
+
+
+    @Test
+    public void testFilterEmptyGraph() throws Exception {
+        Graph graph = getEmptyGraph();
+        Iterator<Triple> i = graph.filter(null, null, null);
+        Assert.assertFalse(i.hasNext());
+    }
+
+
+    @Test
+    public void testFilterSingleEntry() throws Exception {
+        Graph graph = getEmptyGraph();
+        final Triple triple= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/alice");
+        Assert.assertTrue(graph.add(triple));
+
+        Iterator<Triple> i = graph.filter(null, null, null);
+        Collection<Triple> resultSet= toCollection(i);
+        Assert.assertEquals(1, resultSet.size());
+        Assert.assertTrue(resultSet.contains(triple));
+    }
+
+
+    @Test
+    public void testFilterByObject() throws Exception {
+        Graph graph = getEmptyGraph();
+        final Triple tripleAlice= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/alice");
+        final Triple tripleBob= createTriple(
+                "http://example.org/ontology/Person",
+                "http://example.org/ontology/hasName",
+                "http://example.org/people/bob");
+        Assert.assertTrue(graph.add(tripleAlice));
+        Assert.assertTrue(graph.add(tripleBob));
+
+        Iterator<Triple> iterator;
+        Collection<Triple> resultSet;
+
+        // Find bob
+        iterator = graph.filter(null, null,
+                new IRI("http://example.org/people/bob"));
+        resultSet= toCollection(iterator);
+        Assert.assertEquals(1, resultSet.size());
+        Assert.assertTrue(resultSet.contains(tripleBob));
+
+        // Find alice
+        iterator = graph.filter(null, null,
+                new IRI("http://example.org/people/alice"));
+        resultSet= toCollection(iterator);
+        Assert.assertEquals(1, resultSet.size());
+        Assert.assertTrue(resultSet.contains(tripleAlice));
+
+        // Find both
+        iterator = graph.filter(null, null, null);
+        resultSet= toCollection(iterator);
+        Assert.assertEquals(2, resultSet.size());
+        Assert.assertTrue(resultSet.contains(tripleAlice));
+        Assert.assertTrue(resultSet.contains(tripleBob));
+    }
+/*
+    @Test
+    public void graphEventTestAddRemove() {
+        Graph mGraph = getEmptyGraph();
+        TestGraphListener listener = new TestGraphListener();
+        mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+        mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+        mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));        
+        mGraph.add(trpl1);
+        Assert.assertNull(listener.getEvents());        
+        mGraph.add(trpl2);
+        Assert.assertEquals(1, listener.getEvents().size());
+        Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
+        Assert.assertTrue(listener.getEvents().get(0) instanceof  AddEvent);
+        listener.resetEvents();
+        mGraph.remove(trpl2);
+        Assert.assertEquals(1, listener.getEvents().size());
+        Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
+        Assert.assertTrue(listener.getEvents().get(0) instanceof RemoveEvent);
+        listener.resetEvents();        
+        mGraph.add(trpl3);
+        Assert.assertEquals(1, listener.getEvents().size());
+        Assert.assertEquals(trpl3, listener.getEvents().get(0).getTriple());
+        Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
+        listener.resetEvents();        
+        mGraph.remove(trpl4);
+        Assert.assertNull(listener.getEvents());
+    }
+    
+    @Test
+    public void graphEventTestAddAllRemoveAll() {
+        Graph mGraph = getEmptyGraph();
+        TestGraphListener listener = new TestGraphListener();
+        mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+        mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+        mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
+        Graph triples = new SimpleGraph();
+        triples.add(trpl1);
+        triples.add(trpl2);
+        triples.add(trpl3);
+        triples.add(trpl4);
+        mGraph.addAll(triples);
+        List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
+        Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
+        Assert.assertEquals(3, cumulatedEvents.size());
+        Assert.assertTrue(cumulatedEvents.get(0) instanceof AddEvent);
+        Assert.assertTrue(cumulatedTriples.contains(trpl2));
+        Assert.assertTrue(cumulatedTriples.contains(trpl3));
+        Assert.assertTrue(cumulatedTriples.contains(trpl4));
+        listener.resetCumulatedEvents();
+        mGraph.removeAll(triples);
+        cumulatedEvents = listener.getCumulatedEvents();
+        cumulatedTriples = getCumulatedTriples(cumulatedEvents);
+        Assert.assertEquals(3, cumulatedEvents.size());
+        Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
+        Assert.assertTrue(cumulatedTriples.contains(trpl2));
+        Assert.assertTrue(cumulatedTriples.contains(trpl3));
+        Assert.assertTrue(cumulatedTriples.contains(trpl4));
+    }
+
+    @Test
+    public void graphEventTestFilterRemove() {
+        Graph mGraph = getEmptyGraph();
+        TestGraphListener listener = new TestGraphListener();
+        mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+        mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+        mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
+        mGraph.add(trpl1);
+        mGraph.add(trpl2);
+        mGraph.add(trpl3);
+        mGraph.add(trpl4);
+        listener.resetCumulatedEvents();
+        Iterator<Triple> result = mGraph.filter(null, uriRef2, null);
+        while (result.hasNext()) {
+            result.next();
+            result.remove();
+        }
+        List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
+        Assert.assertEquals(1, cumulatedEvents.size());
+        Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
+        Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
+    }
+
+    @Test
+    public void graphEventTestIteratorRemove() {
+        Graph mGraph = getEmptyGraph();
+        TestGraphListener listener = new TestGraphListener();
+        mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+        mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+        mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
+        mGraph.add(trpl1);
+        mGraph.add(trpl2);
+        mGraph.add(trpl3);
+        mGraph.add(trpl4);
+        listener.resetCumulatedEvents();
+        Iterator<Triple> result = mGraph.iterator();
+        while (result.hasNext()) {
+            result.next();
+            result.remove();
+        }
+        List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
+        Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
+        Assert.assertEquals(3, cumulatedEvents.size());
+        Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
+        Assert.assertTrue(cumulatedTriples.contains(trpl2));
+        Assert.assertTrue(cumulatedTriples.contains(trpl3));
+        Assert.assertTrue(cumulatedTriples.contains(trpl4));
+    }
+
+    @Test
+    public void graphEventTestClear() {
+        Graph mGraph = getEmptyGraph();
+        TestGraphListener listener = new TestGraphListener();
+        mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+        mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+        mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
+        mGraph.add(trpl1);
+        mGraph.add(trpl2);
+        mGraph.add(trpl3);
+        mGraph.add(trpl4);
+        listener.resetCumulatedEvents();
+        mGraph.clear();
+        List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
+        Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
+        Assert.assertEquals(3, cumulatedEvents.size());
+        Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
+        Assert.assertTrue(cumulatedTriples.contains(trpl2));
+        Assert.assertTrue(cumulatedTriples.contains(trpl3));
+        Assert.assertTrue(cumulatedTriples.contains(trpl4));
+    }
+
+    private Set<Triple> getCumulatedTriples(List<GraphEvent> cumulatedEvents) {
+        Set<Triple> triples = new HashSet<Triple>();
+        for(GraphEvent event: cumulatedEvents) {
+            triples.add(event.getTriple());
+        }
+        return triples;
+    }
+
+    @Test
+    public void graphEventTestWithDelay() throws Exception{
+        Graph mGraph = getEmptyGraph();
+        TestGraphListener listener = new TestGraphListener();
+        mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null),
+                1000);
+
+        Triple triple0 = new TripleImpl(uriRef2, uriRef2, literal1);
+        Triple triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
+        Triple triple2 = new TripleImpl(uriRef1, uriRef2, literal1);
+        Triple triple3 = new TripleImpl(uriRef1, uriRef2, bnode1);
+        mGraph.add(triple0);
+        mGraph.add(triple1);
+        mGraph.add(triple2);
+        mGraph.add(triple3);
+        Thread.sleep(1500);
+        Assert.assertEquals(3, listener.getEvents().size());
+        Assert.assertEquals(triple1, listener.getEvents().get(0).getTriple());
+        Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
+        Assert.assertEquals(triple2, listener.getEvents().get(1).getTriple());
+        Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
+        Assert.assertEquals(triple3, listener.getEvents().get(2).getTriple());
+        Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
+    }
+
+    private static class TestGraphListener implements GraphListener {
+        private List<GraphEvent> events = null;
+        private List<GraphEvent> cumulatedEvents = new ArrayList<GraphEvent>();
+
+        @Override
+        public void graphChanged(List<GraphEvent> events) {
+            this.events = events;
+            Iterator<GraphEvent> eventIter = events.iterator();
+            while (eventIter.hasNext()) {
+                GraphEvent graphEvent = eventIter.next();
+                this.cumulatedEvents.add(graphEvent);
+            }            
+        }
+
+        public List<GraphEvent> getEvents() {
+            return events;
+        }
+
+        public List<GraphEvent> getCumulatedEvents() {
+            return cumulatedEvents;
+        }
+
+        public void resetEvents() {
+            events = null;
+        }
+
+        public void resetCumulatedEvents() {
+            cumulatedEvents = new ArrayList<GraphEvent>();
+        }
+    }
+*/
+    private Collection<Triple> toCollection(Iterator<Triple> iterator) {
+        Collection<Triple> result = new ArrayList<Triple>();
+        while (iterator.hasNext()) {
+            result.add(iterator.next());
+        }
+        return result;
+    }
+
+    /**
+     * Creates a new <code>Triple</code>.
+     * @param subject  the subject.
+     * @param predicate  the predicate.
+     * @param object  the object.
+     * @throws IllegalArgumentException  If an attribute is <code>null</code>.
+     */
+    private Triple createTriple(String subject, String predicate,
+            String object) {
+        return new TripleImpl(new IRI(subject), new IRI(predicate),
+                new IRI(object));
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/graph/SimpleGraphTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/graph/SimpleGraphTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/graph/SimpleGraphTest.java
new file mode 100644
index 0000000..cdfadab
--- /dev/null
+++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/graph/SimpleGraphTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.api.impl.graph;
+
+import org.apache.clerezza.api.impl.TripleImpl;
+
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.clerezza.api.Triple;
+import org.apache.clerezza.api.IRI;
+
+/**
+ *
+ * @author mir
+ */
+public class SimpleGraphTest {
+
+    private IRI uriRef1 = new IRI("http://example.org/foo");
+    private IRI uriRef2 = new IRI("http://example.org/bar");
+    private IRI uriRef3 = new IRI("http://example.org/test");
+    private Triple triple1 = new TripleImpl(uriRef1, uriRef2, uriRef3);
+    private Triple triple2 = new TripleImpl(uriRef2, uriRef2, uriRef1);
+    private Triple triple3 = new TripleImpl(uriRef3, uriRef1, uriRef3);
+    private Triple triple4 = new TripleImpl(uriRef1, uriRef3, uriRef2);
+    private Triple triple5 = new TripleImpl(uriRef2, uriRef3, uriRef2);
+        
+    @Test
+    public void iteratorRemove() {
+        SimpleGraph stc = new SimpleGraph();
+        stc.add(triple1);
+        stc.add(triple2);
+        stc.add(triple3);
+        stc.add(triple4);
+        stc.add(triple5);
+        Iterator<Triple> iter = stc.iterator();
+        while (iter.hasNext()) {
+            Triple triple = iter.next();
+            iter.remove();
+        }
+        Assert.assertEquals(0, stc.size());
+    }
+
+    @Test
+    public void removeAll() {
+        SimpleGraph stc = new SimpleGraph();
+        stc.add(triple1);
+        stc.add(triple2);
+        stc.add(triple3);
+        stc.add(triple4);
+        stc.add(triple5);
+        SimpleGraph stc2 = new SimpleGraph();
+        stc2.add(triple1);
+        stc2.add(triple3);
+        stc2.add(triple5);
+        stc.removeAll(stc2);
+        Assert.assertEquals(2, stc.size());
+    }
+    
+    @Test
+    public void filterIteratorRemove() {
+        SimpleGraph stc = new SimpleGraph();
+        stc.add(triple1);
+        stc.add(triple2);
+        stc.add(triple3);
+        stc.add(triple4);
+        stc.add(triple5);        
+        Iterator<Triple> iter = stc.filter(uriRef1, null, null);
+        while (iter.hasNext()) {
+            Triple triple = iter.next();
+            iter.remove();
+        }
+        Assert.assertEquals(3, stc.size());
+    }
+
+    @Test(expected=ConcurrentModificationException.class)
+    public void remove() {
+        SimpleGraph stc = new SimpleGraph();
+        stc.setCheckConcurrency(true);
+        stc.add(triple1);
+        stc.add(triple2);
+        stc.add(triple3);
+        stc.add(triple4);
+        stc.add(triple5);
+        Iterator<Triple> iter = stc.filter(uriRef1, null, null);
+        while (iter.hasNext()) {
+            Triple triple = iter.next();
+            stc.remove(triple);
+        }
+        Assert.assertEquals(3, stc.size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcherTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcherTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcherTest.java
index 00e02a2..4a39411 100644
--- a/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcherTest.java
+++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcherTest.java
@@ -20,7 +20,7 @@ package org.apache.clerezza.api.impl.graphmatching;
 
 import org.apache.clerezza.api.Graph;
 import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.impl.simple.SimpleMGraph;
+import org.apache.clerezza.api.impl.graph.SimpleMGraph;
 import org.apache.clerezza.api.impl.TripleImpl;
 
 import java.util.Map;

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/Utils4Testing.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/Utils4Testing.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/Utils4Testing.java
index 85dbc20..9dc1a8f 100644
--- a/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/Utils4Testing.java
+++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/graphmatching/Utils4Testing.java
@@ -22,7 +22,7 @@ package org.apache.clerezza.api.impl.graphmatching;
 import org.apache.clerezza.api.BlankNode;
 import org.apache.clerezza.api.Graph;
 import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.impl.simple.SimpleMGraph;
+import org.apache.clerezza.api.impl.graph.SimpleMGraph;
 import org.apache.clerezza.api.impl.TripleImpl;
 import org.apache.clerezza.api.BlankNodeOrIRI;
 

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/PlainLiteralImplTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/PlainLiteralImplTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/PlainLiteralImplTest.java
new file mode 100644
index 0000000..ff55388
--- /dev/null
+++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/PlainLiteralImplTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.api.impl.literal;
+
+import org.junit.Test;
+
+import org.apache.clerezza.api.Language;
+import org.apache.clerezza.api.Literal;
+import org.junit.Assert;
+
+/**
+ *
+ * @author reto
+ *
+ */
+
+public class PlainLiteralImplTest {
+
+    
+    @Test public void plainLiteralEquality() {
+        String stringValue = "some text";
+        Literal literal1 = new PlainLiteralImpl(stringValue);
+        Literal literal2 = new PlainLiteralImpl(stringValue);        
+        Assert.assertEquals(literal1, literal2);
+        Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
+        Literal literal3 = new PlainLiteralImpl("something else");
+        Assert.assertFalse(literal1.equals(literal3));
+    }
+    
+    @Test public void languageLiteralEquality() {
+        String stringValue = "some text";
+        Language lang = new Language("en-ca");
+        Literal literal1 = new PlainLiteralImpl(stringValue, lang);
+        Literal literal2 = new PlainLiteralImpl(stringValue, lang);        
+        Assert.assertEquals(literal1, literal2);
+        Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
+        Language lang2 = new Language("de");
+        Literal literal3 = new PlainLiteralImpl(stringValue, lang2);
+        Assert.assertFalse(literal1.equals(literal3));
+        Literal literal4 = new PlainLiteralImpl(stringValue, null);
+        Assert.assertFalse(literal3.equals(literal4));
+        Assert.assertFalse(literal4.equals(literal3));
+    }
+
+    /**
+     * hashCode of the lexical form plus the hashCode of the locale
+     */
+    @Test public void checkHashCode() {
+        String stringValue = "some text";
+        Language language = new Language("en");
+        Literal literal = new PlainLiteralImpl(stringValue, language);
+        Assert.assertEquals(literal.getDataType().hashCode() + stringValue.hashCode() + language.hashCode(), literal.hashCode());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/TripleImplTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/TripleImplTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/TripleImplTest.java
new file mode 100644
index 0000000..99e59ce
--- /dev/null
+++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/TripleImplTest.java
@@ -0,0 +1,57 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.apache.clerezza.api.impl.simple;
+/*
+ *
+ * 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.clerezza.api.BlankNodeOrIRI;
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+import org.apache.clerezza.api.impl.literal.PlainLiteralImpl;
+import org.apache.clerezza.api.impl.TripleImpl;
+import org.junit.Test;
+import junit.framework.Assert;
+
+/**
+ *
+ * @author reto
+ *
+ */
+
+public class TripleImplTest {
+    
+    
+    @Test public void tripleEquality() {
+        BlankNodeOrIRI subject = new IRI("http://example.org/");
+        IRI predicate = new IRI("http://example.org/property");
+        RDFTerm object = new PlainLiteralImpl("property value");
+        Triple triple1 = new TripleImpl(subject, predicate, object);
+        Triple triple2 = new TripleImpl(subject, predicate, object);
+        Assert.assertEquals(triple1.hashCode(), triple2.hashCode());
+        Assert.assertEquals(triple1, triple2);    
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/TypedLiteralImplTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/TypedLiteralImplTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/TypedLiteralImplTest.java
new file mode 100644
index 0000000..8589c4e
--- /dev/null
+++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/TypedLiteralImplTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.api.impl.simple;
+
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.impl.literal.TypedLiteralImpl;
+import org.junit.Test;
+import junit.framework.Assert;
+
+import org.apache.clerezza.api.Literal;
+/**
+ *
+ * @author reto/**
+ *
+ * @author reto/**
+ *
+ * @author reto/**
+ *
+ * @author reto
+ *
+ */
+
+public class TypedLiteralImplTest {
+    
+    
+    @Test public void typedLiteralEquality() {
+        String stringValue = "some text";
+        IRI uriRef = new IRI("http://example.org/datatypes/magic");
+        Literal literal1 = new TypedLiteralImpl(stringValue, uriRef);
+        Literal literal2 = new TypedLiteralImpl(stringValue, uriRef);        
+        Assert.assertEquals(literal1, literal2);
+        Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
+        Literal literal3 = new TypedLiteralImpl("something else", uriRef);
+        Assert.assertFalse(literal1.equals(literal3));
+        IRI uriRef2 = new IRI("http://example.org/datatypes/other");
+        Literal literal4 = new TypedLiteralImpl(stringValue, uriRef2);
+        Assert.assertFalse(literal1.equals(literal4));
+    }
+
+
+    /**
+     * The hascode is equals to the hascode of the lexical form plus the hashcode of the dataTyp
+     */
+    @Test public void checkHashCode() {
+        String stringValue = "some text";
+        IRI uriRef = new IRI("http://example.org/datatypes/magic");
+        Literal literal =  new TypedLiteralImpl(stringValue, uriRef);
+        Assert.assertEquals(stringValue.hashCode() + uriRef.hashCode(), literal.hashCode());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/PlainLiteralImplTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/PlainLiteralImplTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/PlainLiteralImplTest.java
deleted file mode 100644
index ff6e678..0000000
--- a/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/PlainLiteralImplTest.java
+++ /dev/null
@@ -1,71 +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.api.impl.simple;
-
-import org.apache.clerezza.api.impl.PlainLiteralImpl;
-import org.junit.Test;
-
-import org.apache.clerezza.api.Language;
-import org.apache.clerezza.api.Literal;
-import org.junit.Assert;
-/**
- *
- * @author reto
- *
- */
-
-public class PlainLiteralImplTest {
-
-    
-    @Test public void plainLiteralEquality() {
-        String stringValue = "some text";
-        Literal literal1 = new PlainLiteralImpl(stringValue);
-        Literal literal2 = new PlainLiteralImpl(stringValue);        
-        Assert.assertEquals(literal1, literal2);
-        Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
-        Literal literal3 = new PlainLiteralImpl("something else");
-        Assert.assertFalse(literal1.equals(literal3));
-    }
-    
-    @Test public void languageLiteralEquality() {
-        String stringValue = "some text";
-        Language lang = new Language("en-ca");
-        Literal literal1 = new PlainLiteralImpl(stringValue, lang);
-        Literal literal2 = new PlainLiteralImpl(stringValue, lang);        
-        Assert.assertEquals(literal1, literal2);
-        Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
-        Language lang2 = new Language("de");
-        Literal literal3 = new PlainLiteralImpl(stringValue, lang2);
-        Assert.assertFalse(literal1.equals(literal3));
-        Literal literal4 = new PlainLiteralImpl(stringValue, null);
-        Assert.assertFalse(literal3.equals(literal4));
-        Assert.assertFalse(literal4.equals(literal3));
-    }
-
-    /**
-     * hashCode of the lexical form plus the hashCode of the locale
-     */
-    @Test public void checkHashCode() {
-        String stringValue = "some text";
-        Language language = new Language("en");
-        Literal literal = new PlainLiteralImpl(stringValue, language);
-        Assert.assertEquals(literal.getDataType().hashCode() + stringValue.hashCode() + language.hashCode(), literal.hashCode());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/SimpleGraphTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/SimpleGraphTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/SimpleGraphTest.java
deleted file mode 100644
index ff3280d..0000000
--- a/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/SimpleGraphTest.java
+++ /dev/null
@@ -1,109 +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.api.impl.simple;
-
-import org.apache.clerezza.api.impl.TripleImpl;
-
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import org.junit.Assert;
-import org.junit.Test;
-import org.apache.clerezza.api.Triple;
-import org.apache.clerezza.api.IRI;
-
-/**
- *
- * @author mir
- */
-public class SimpleGraphTest {
-
-    private IRI uriRef1 = new IRI("http://example.org/foo");
-    private IRI uriRef2 = new IRI("http://example.org/bar");
-    private IRI uriRef3 = new IRI("http://example.org/test");
-    private Triple triple1 = new TripleImpl(uriRef1, uriRef2, uriRef3);
-    private Triple triple2 = new TripleImpl(uriRef2, uriRef2, uriRef1);
-    private Triple triple3 = new TripleImpl(uriRef3, uriRef1, uriRef3);
-    private Triple triple4 = new TripleImpl(uriRef1, uriRef3, uriRef2);
-    private Triple triple5 = new TripleImpl(uriRef2, uriRef3, uriRef2);
-        
-    @Test
-    public void iteratorRemove() {
-        SimpleGraph stc = new SimpleGraph();
-        stc.add(triple1);
-        stc.add(triple2);
-        stc.add(triple3);
-        stc.add(triple4);
-        stc.add(triple5);
-        Iterator<Triple> iter = stc.iterator();
-        while (iter.hasNext()) {
-            Triple triple = iter.next();
-            iter.remove();
-        }
-        Assert.assertEquals(0, stc.size());
-    }
-
-    @Test
-    public void removeAll() {
-        SimpleGraph stc = new SimpleGraph();
-        stc.add(triple1);
-        stc.add(triple2);
-        stc.add(triple3);
-        stc.add(triple4);
-        stc.add(triple5);
-        SimpleGraph stc2 = new SimpleGraph();
-        stc2.add(triple1);
-        stc2.add(triple3);
-        stc2.add(triple5);
-        stc.removeAll(stc2);
-        Assert.assertEquals(2, stc.size());
-    }
-    
-    @Test
-    public void filterIteratorRemove() {
-        SimpleGraph stc = new SimpleGraph();
-        stc.add(triple1);
-        stc.add(triple2);
-        stc.add(triple3);
-        stc.add(triple4);
-        stc.add(triple5);        
-        Iterator<Triple> iter = stc.filter(uriRef1, null, null);
-        while (iter.hasNext()) {
-            Triple triple = iter.next();
-            iter.remove();
-        }
-        Assert.assertEquals(3, stc.size());
-    }
-
-    @Test(expected=ConcurrentModificationException.class)
-    public void remove() {
-        SimpleGraph stc = new SimpleGraph();
-        stc.setCheckConcurrency(true);
-        stc.add(triple1);
-        stc.add(triple2);
-        stc.add(triple3);
-        stc.add(triple4);
-        stc.add(triple5);
-        Iterator<Triple> iter = stc.filter(uriRef1, null, null);
-        while (iter.hasNext()) {
-            Triple triple = iter.next();
-            stc.remove(triple);
-        }
-        Assert.assertEquals(3, stc.size());
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/TripleImplTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/TripleImplTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/TripleImplTest.java
deleted file mode 100644
index 9b38af9..0000000
--- a/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/TripleImplTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.apache.clerezza.api.impl.simple;
-/*
- *
- * 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.clerezza.api.BlankNodeOrIRI;
-import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.RDFTerm;
-import org.apache.clerezza.api.Triple;
-import org.apache.clerezza.api.impl.PlainLiteralImpl;
-import org.apache.clerezza.api.impl.TripleImpl;
-import org.junit.Test;
-import junit.framework.Assert;
-
-/**
- *
- * @author reto
- *
- */
-
-public class TripleImplTest {
-    
-    
-    @Test public void tripleEquality() {
-        BlankNodeOrIRI subject = new IRI("http://example.org/");
-        IRI predicate = new IRI("http://example.org/property");
-        RDFTerm object = new PlainLiteralImpl("property value");
-        Triple triple1 = new TripleImpl(subject, predicate, object);
-        Triple triple2 = new TripleImpl(subject, predicate, object);
-        Assert.assertEquals(triple1.hashCode(), triple2.hashCode());
-        Assert.assertEquals(triple1, triple2);    
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/TypedLiteralImplTest.java
----------------------------------------------------------------------
diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/TypedLiteralImplTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/TypedLiteralImplTest.java
deleted file mode 100644
index dbde617..0000000
--- a/api.impl/src/test/java/org/apache/clerezza/api/impl/simple/TypedLiteralImplTest.java
+++ /dev/null
@@ -1,67 +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.api.impl.simple;
-
-import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.impl.TypedLiteralImpl;
-import org.junit.Test;
-import junit.framework.Assert;
-
-import org.apache.clerezza.api.Literal;
-/**
- *
- * @author reto/**
- *
- * @author reto/**
- *
- * @author reto/**
- *
- * @author reto
- *
- */
-
-public class TypedLiteralImplTest {
-    
-    
-    @Test public void typedLiteralEquality() {
-        String stringValue = "some text";
-        IRI uriRef = new IRI("http://example.org/datatypes/magic");
-        Literal literal1 = new TypedLiteralImpl(stringValue, uriRef);
-        Literal literal2 = new TypedLiteralImpl(stringValue, uriRef);        
-        Assert.assertEquals(literal1, literal2);
-        Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
-        Literal literal3 = new TypedLiteralImpl("something else", uriRef);
-        Assert.assertFalse(literal1.equals(literal3));
-        IRI uriRef2 = new IRI("http://example.org/datatypes/other");
-        Literal literal4 = new TypedLiteralImpl(stringValue, uriRef2);
-        Assert.assertFalse(literal1.equals(literal4));
-    }
-
-
-    /**
-     * The hascode is equals to the hascode of the lexical form plus the hashcode of the dataTyp
-     */
-    @Test public void checkHashCode() {
-        String stringValue = "some text";
-        IRI uriRef = new IRI("http://example.org/datatypes/magic");
-        Literal literal =  new TypedLiteralImpl(stringValue, uriRef);
-        Assert.assertEquals(stringValue.hashCode() + uriRef.hashCode(), literal.hashCode());
-    }
-
-}


[3/3] clerezza git commit: CLEREZZA-1026: Copy additional classes from rdf.core to api.impl and refactor api.impl

Posted by ha...@apache.org.
CLEREZZA-1026: Copy additional classes from rdf.core to api.impl and refactor api.impl


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

Branch: refs/heads/reunited
Commit: 829e5fa56892352edd7969a661693671067bfa54
Parents: f06386f
Author: Hasan <ha...@apache.org>
Authored: Wed Nov 14 03:54:16 2018 +0100
Committer: Hasan <ha...@apache.org>
Committed: Wed Nov 14 03:54:16 2018 +0100

----------------------------------------------------------------------
 .../apache/clerezza/api/impl/AbstractGraph.java | 307 ----------
 .../api/impl/AbstractImmutableGraph.java        | 112 ----
 .../clerezza/api/impl/AbstractLiteral.java      |  61 --
 .../clerezza/api/impl/DelayedNotificator.java   | 113 ----
 .../apache/clerezza/api/impl/LiteralImpl.java   |  82 ---
 .../clerezza/api/impl/LockingIterator.java      |  73 ---
 .../clerezza/api/impl/PlainLiteralImpl.java     |  80 ---
 .../clerezza/api/impl/TypedLiteralImpl.java     |  79 ---
 .../api/impl/WatchableGraphWrapper.java         | 290 ----------
 .../clerezza/api/impl/graph/AbstractGraph.java  | 306 ++++++++++
 .../api/impl/graph/AbstractImmutableGraph.java  | 112 ++++
 .../api/impl/graph/DelayedNotificator.java      | 113 ++++
 .../api/impl/graph/LockingIterator.java         |  73 +++
 .../api/impl/graph/PrivilegedGraphWrapper.java  | 254 +++++++++
 .../graph/PrivilegedImmuatbleGraphWrapper.java  |  36 ++
 .../api/impl/graph/ReadOnlyException.java       |  50 ++
 .../clerezza/api/impl/graph/SimpleGraph.java    | 206 +++++++
 .../api/impl/graph/SimpleImmutableGraph.java    |  78 +++
 .../clerezza/api/impl/graph/SimpleMGraph.java   |  56 ++
 .../api/impl/graph/WatchableGraphWrapper.java   | 276 +++++++++
 .../api/impl/graph/WriteBlockedGraph.java       | 113 ++++
 .../api/impl/graphmatching/GraphMatcher.java    |   2 +-
 .../api/impl/literal/AbstractLiteral.java       |  61 ++
 .../literal/InvalidLiteralTypeException.java    |  40 ++
 .../api/impl/literal/LiteralFactory.java        |  83 +++
 .../clerezza/api/impl/literal/LiteralImpl.java  |  82 +++
 .../api/impl/literal/NoConvertorException.java  |  41 ++
 .../api/impl/literal/PlainLiteralImpl.java      |  80 +++
 .../api/impl/literal/SimpleLiteralFactory.java  | 305 ++++++++++
 .../api/impl/literal/TypedLiteralImpl.java      |  79 +++
 .../apache/clerezza/api/impl/package-info.java  |   3 -
 .../clerezza/api/impl/simple/SimpleGraph.java   | 219 --------
 .../api/impl/simple/SimpleImmutableGraph.java   |  80 ---
 .../clerezza/api/impl/simple/SimpleMGraph.java  |  56 --
 .../apache/clerezza/api/impl/util/Base64.java   | 120 ++++
 .../clerezza/api/impl/util/W3CDateFormat.java   | 196 +++++++
 .../clerezza/api/impl/graph/GraphTest.java      | 563 +++++++++++++++++++
 .../api/impl/graph/SimpleGraphTest.java         | 110 ++++
 .../impl/graphmatching/GraphMatcherTest.java    |   2 +-
 .../api/impl/graphmatching/Utils4Testing.java   |   2 +-
 .../api/impl/literal/PlainLiteralImplTest.java  |  71 +++
 .../api/impl/literal/TripleImplTest.java        |  57 ++
 .../api/impl/literal/TypedLiteralImplTest.java  |  67 +++
 .../api/impl/simple/PlainLiteralImplTest.java   |  71 ---
 .../api/impl/simple/SimpleGraphTest.java        | 109 ----
 .../api/impl/simple/TripleImplTest.java         |  57 --
 .../api/impl/simple/TypedLiteralImplTest.java   |  67 ---
 47 files changed, 3631 insertions(+), 1862 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractGraph.java
deleted file mode 100644
index ab236b6..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractGraph.java
+++ /dev/null
@@ -1,307 +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.api.impl;
-
-import java.util.AbstractCollection;
-import java.util.Collection;
-import java.util.Iterator;
-
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import org.apache.clerezza.api.Graph;
-import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.BlankNodeOrIRI;
-import org.apache.clerezza.api.RDFTerm;
-import org.apache.clerezza.api.Triple;
-import org.apache.clerezza.api.ImmutableGraph;
-import org.apache.clerezza.api.impl.simple.SimpleImmutableGraph;
-import org.apache.clerezza.api.impl.debug.ReentrantReadWriteLockTracker;
-
-/**
- * An abstract implementation of <code>Graph</code> implementing
- * <code>iterator</code> and <code>contains</code> calling <code>filter</code>.
- *
- * @author reto
- */
-public abstract class AbstractGraph extends AbstractCollection<Triple>
-        implements Graph {
-
-    
-    private static final String DEBUG_MODE = "rdfLocksDebugging";
-    private final ReadWriteLock lock;
-
-    private final Lock readLock;
-    private final Lock writeLock;
-
-    /**
-     * Constructs a LocalbleMGraph for an Graph.
-     *
-     * @param providedMGraph a non-lockable graph
-     */
-    public AbstractGraph() {
-        {
-            String debugMode = System.getProperty(DEBUG_MODE);
-            if (debugMode != null && debugMode.toLowerCase().equals("true")) {
-                lock = new ReentrantReadWriteLockTracker();
-            } else {
-                lock = new ReentrantReadWriteLock();
-            }
-        }
-        readLock = lock.readLock();
-        writeLock = lock.writeLock();
-    }
-    
-    public AbstractGraph(final ReadWriteLock lock) {
-        this.lock = lock;
-        readLock = lock.readLock();
-        writeLock = lock.writeLock();
-    }
-
-    @Override
-    public ReadWriteLock getLock() {
-        return lock;
-    }
-
-    @Override
-    public ImmutableGraph getImmutableGraph() {
-        readLock.lock();
-        try {
-            return performGetImmutableGraph();
-        } finally {
-            readLock.unlock();
-        }
-    }
-    
-    public ImmutableGraph performGetImmutableGraph() {
-        return new SimpleImmutableGraph(this);
-    }
-
-    @Override
-    public Iterator<Triple> filter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-        readLock.lock();
-        try {
-            return new LockingIterator(performFilter(subject, predicate, object), lock);
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    public int size() {
-        readLock.lock();
-        try {
-            return performSize();
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    public boolean isEmpty() {
-        readLock.lock();
-        try {
-            return performIsEmpty();
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    @SuppressWarnings("element-type-mismatch")
-    public boolean contains(Object o) {
-        readLock.lock();
-        try {
-            return performContains(o);
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    public Iterator<Triple> iterator() {
-        readLock.lock();
-        try {
-            return new LockingIterator(performIterator(), lock);
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    public Object[] toArray() {
-        readLock.lock();
-        try {
-            return performToArray();
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    public <T> T[] toArray(T[] a) {
-        readLock.lock();
-        try {
-            return performToArray(a);
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    public boolean containsAll(Collection<?> c) {
-        readLock.lock();
-        try {
-            return performContainsAll(c);
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    public boolean add(Triple e) {
-        writeLock.lock();
-        try {
-            return performAdd(e);
-        } finally {
-            writeLock.unlock();
-        }
-    }
-
-    @Override
-    public boolean remove(Object o) {
-        writeLock.lock();
-        try {
-            return performRemove(o);
-        } finally {
-            writeLock.unlock();
-        }
-    }
-
-    @Override
-    public boolean addAll(Collection<? extends Triple> c) {
-        writeLock.lock();
-        try {
-            return performAddAll(c);
-        } finally {
-            writeLock.unlock();
-        }
-    }
-
-    @Override
-    public boolean removeAll(Collection<?> c) {
-        writeLock.lock();
-        try {
-            return performRemoveAll(c);
-        } finally {
-            writeLock.unlock();
-        }
-    }
-
-    @Override
-    public boolean retainAll(Collection<?> c) {
-        writeLock.lock();
-        try {
-            return performRetainAll(c);
-        } finally {
-            writeLock.unlock();
-        }
-    }
-
-    @Override
-    public void clear() {
-        writeLock.lock();
-        try {
-            performClear();
-        } finally {
-            writeLock.unlock();
-        }
-    }
-
-    
-    @Override
-    public boolean equals(Object obj) {
-        /*if (obj == null) {
-            return false;
-        }
-        if (obj == this) {
-            return true;
-        }
-        if (obj.getClass() != getClass()) {
-            return false;
-        }*/
-        return this == obj;
-    }
-
-
-    protected abstract Iterator<Triple> performFilter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
-    protected abstract int performSize();
-
-    protected boolean performIsEmpty() {
-        return super.isEmpty();
-    }
-
-    protected Object[] performToArray() {
-        return super.toArray();
-    }
-
-    protected boolean performRemove(Object o) {
-        return super.remove(o);
-    }
-
-    protected boolean performAddAll(Collection<? extends Triple> c) {
-        return super.addAll(c);
-    }
-
-    protected boolean performRemoveAll(Collection<?> c) {
-        return super.removeAll(c);
-    }
-
-    protected boolean performRetainAll(Collection<?> c) {
-        return super.retainAll(c);
-    }
-
-    protected void performClear() {
-        super.clear();
-    }
-
-    protected boolean performContains(Object o) {
-        return super.contains(o);
-    }
-
-    protected Iterator<Triple> performIterator() {
-        return performFilter(null, null, null);
-    }
-
-    protected boolean performContainsAll(Collection<?> c) {
-        return super.containsAll(c);
-    }
-
-    protected <T> T[] performToArray(T[] a) {
-        return super.toArray(a);
-    }
-
-    protected boolean performAdd(Triple e) {
-        return super.add(e);
-    }
-
- 
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractImmutableGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractImmutableGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractImmutableGraph.java
deleted file mode 100644
index c46f0fc..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractImmutableGraph.java
+++ /dev/null
@@ -1,112 +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.api.impl;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.apache.clerezza.api.impl.graphmatching.GraphMatcher;
-import org.apache.clerezza.api.BlankNode;
-import org.apache.clerezza.api.ImmutableGraph;
-import org.apache.clerezza.api.RDFTerm;
-import org.apache.clerezza.api.Triple;
-
-/**
- * <code>AbstractGraph</code> is an abstract implementation of <code>ImmutableGraph</code> 
- * implementing the <code>equals</code> and the <code>hashCode</code> methods.
- * 
- * @author reto
- * 
- */
-public abstract class AbstractImmutableGraph extends AbstractGraph
-        implements ImmutableGraph {
-
-    public final synchronized int hashCode() {
-        int result = 0;
-        for (Iterator<Triple> iter = iterator(); iter.hasNext();) {
-            result += getBlankNodeBlindHash(iter.next());
-        }
-        return result;
-    }
-
-    /**
-     * @param triple
-     * @return hash without BNode hashes
-     */
-    private int getBlankNodeBlindHash(Triple triple) {
-        int hash = triple.getPredicate().hashCode();
-        RDFTerm subject = triple.getSubject();
-
-        if (!(subject instanceof BlankNode)) {
-            hash ^= subject.hashCode() >> 1;
-        }
-        RDFTerm object = triple.getObject();
-        if (!(object instanceof BlankNode)) {
-            hash ^= object.hashCode() << 1;
-        }
-
-        return hash;
-    }
-
-    @Override
-    public boolean add(Triple e) {
-        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
-
-    }
-
-    @Override
-    public boolean addAll(Collection<? extends Triple> c) {
-        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
-    }
-
-    @Override
-    public boolean remove(Object o) {
-        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
-    }
-
-    @Override
-    public boolean removeAll(Collection<?> c) {
-        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
-    }
-
-    @Override
-    public void clear() {
-        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
-    }
-    
-    
-    @Override
-    public ImmutableGraph getImmutableGraph() {
-        return this;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof ImmutableGraph)) {
-            return false;
-        }
-        if (hashCode() != obj.hashCode()) {
-            return false;
-        }
-        return GraphMatcher.getValidMapping(this, (ImmutableGraph) obj) != null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractLiteral.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractLiteral.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractLiteral.java
deleted file mode 100644
index 48e3221..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractLiteral.java
+++ /dev/null
@@ -1,61 +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.api.impl;
-
-import org.apache.clerezza.api.Literal;
-
-/**
- *
- * @author developer
- */
-public abstract class AbstractLiteral implements Literal {
-
-    @Override
-    public int hashCode() {
-        int result = 0;
-        if (getLanguage() != null) {
-            result = getLanguage().hashCode();
-        }
-        result += getLexicalForm().hashCode();
-        result += getDataType().hashCode();
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof Literal) {
-            Literal other = (Literal) obj;
-            
-            if (getLanguage() == null) {
-                if (other.getLanguage() != null) {
-                    return false;
-                }
-            } else {
-                if (!getLanguage().equals(other.getLanguage())) {
-                    return false;
-                }
-            }
-            boolean res = getDataType().equals(other.getDataType()) && getLexicalForm().equals(other.getLexicalForm());
-            return res;
-        } else {
-            return false;
-        }
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/DelayedNotificator.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/DelayedNotificator.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/DelayedNotificator.java
deleted file mode 100644
index 39d52f5..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/DelayedNotificator.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.api.impl;
-
-import java.lang.ref.WeakReference;
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.clerezza.api.event.GraphEvent;
-import org.apache.clerezza.api.event.GraphListener;
-
-
-/**
- *
- * @author reto
- */
-class DelayedNotificator {
-
-    private static final Logger log = Logger.getLogger(DelayedNotificator.class.getName());
-    private static Timer timer = new Timer("Event delivery timer",true);
-
-    static class ListenerHolder {
-
-        long delay;
-        List<GraphEvent> events = null;
-        WeakReference<GraphListener> listenerRef;
-
-        public ListenerHolder(GraphListener listener, long delay) {
-            this.listenerRef = new WeakReference<GraphListener>(listener);
-            this.delay = delay;
-        }
-
-        private void registerEvent(GraphEvent event) {
-            synchronized (this) {
-                if (events == null) {
-                    events = new ArrayList<GraphEvent>();
-                    events.add(event);
-                    timer.schedule(new TimerTask() {
-
-                        @Override
-                        public void run() {
-                            List<GraphEvent> eventsLocal;
-                            synchronized (ListenerHolder.this) {
-                                eventsLocal = events;
-                                events = null;
-                            }
-                            GraphListener listener = listenerRef.get();
-                            if (listener == null) {
-                                log.fine("Ignoring garbage collected listener");
-                            } else {
-                                try {
-                                    listener.graphChanged(eventsLocal);
-                                } catch (Exception e) {
-                                    log.log(Level.WARNING, "Exception delivering ImmutableGraph event", e);
-                                }
-                            }
-                        }
-                    }, delay);
-                } else {
-                    events.add(event);
-                }
-            }
-        }
-    }
-    
-    private final Map<GraphListener, ListenerHolder> map = Collections.synchronizedMap(
-            new WeakHashMap<GraphListener, ListenerHolder>());
-
-    void addDelayedListener(GraphListener listener, long delay) {
-        map.put(listener, new ListenerHolder(listener, delay));
-    }
-
-    /**
-     * removes a Listener, this doesn't prevent the listenerRef from receiving
-     * events alreay scheduled.
-     *
-     * @param listenerRef
-     */
-    void removeDelayedListener(GraphListener listener) {
-        map.remove(listener);
-    }
-
-    /**
-     * if the listenerRef has not been registered as delayed listenerRef te events is
-     * forwarded synchroneously
-     * @param event
-     */
-    void sendEventToListener(GraphListener listener, GraphEvent event) {
-        ListenerHolder holder = map.get(listener);
-        if (holder == null) {
-            listener.graphChanged(Collections.singletonList(event));
-        } else {
-            holder.registerEvent(event);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/LiteralImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/LiteralImpl.java
deleted file mode 100644
index e8ac986..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/LiteralImpl.java
+++ /dev/null
@@ -1,82 +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.api.impl;
-
-import java.io.Serializable;
-
-import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.Language;
-
-/**
- *
- * @author reto
- */
-public class LiteralImpl extends AbstractLiteral implements  Serializable {
-    private String lexicalForm;
-    private IRI dataType;
-    private int hashCode;
-    private Language language;
-
-    /**
-     * @param lexicalForm 
-     * @param dataType 
-     * @param Language the language of this literal
-     */
-    public LiteralImpl(String lexicalForm, IRI dataType, Language language) {
-        this.lexicalForm = lexicalForm;
-        this.dataType = dataType;
-        this.language = language;
-        this.hashCode = super.hashCode();
-    }
-    
-    public IRI getDataType() {
-        return dataType;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.LiteralNode#getLexicalForm()
-     */
-    @Override
-    public String getLexicalForm() {
-        return lexicalForm;
-    }
-
-    @Override
-    public int hashCode() {
-        return hashCode;
-    }
-    
-
-    @Override
-    public String toString() {
-        StringBuffer result = new StringBuffer();
-        result.append('\"');
-        result.append(getLexicalForm());
-        result.append('\"');
-        result.append("^^");
-        result.append(getDataType());
-        return result.toString();
-    }
-
-    @Override
-    public Language getLanguage() {
-        return language;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/LockingIterator.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/LockingIterator.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/LockingIterator.java
deleted file mode 100644
index 84b73de..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/LockingIterator.java
+++ /dev/null
@@ -1,73 +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.api.impl;
-
-import java.util.Iterator;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import org.apache.clerezza.api.Triple;
-
-/**
- * Wrapps an iterator<Triple> reading entering a read-lock on every invocation
- * of hasNext and next
- * @author reto
- */
-class LockingIterator implements Iterator<Triple> {
-
-    private Iterator<Triple> base;
-    private Lock readLock;
-    private Lock writeLock;
-
-    public LockingIterator(Iterator<Triple> iterator, ReadWriteLock lock) {
-        base = iterator;
-        readLock = lock.readLock();
-        writeLock = lock.writeLock();
-    }
-
-    @Override
-    public boolean hasNext() {
-        readLock.lock();
-        try {
-            return base.hasNext();
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    public Triple next() {
-        readLock.lock();
-        try {
-            return base.next();
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-    @Override
-    public void remove() {
-        writeLock.lock();
-        try {
-            base.remove();
-        } finally {
-            writeLock.unlock();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/PlainLiteralImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/PlainLiteralImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/PlainLiteralImpl.java
deleted file mode 100644
index 012aeca..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/PlainLiteralImpl.java
+++ /dev/null
@@ -1,80 +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.api.impl;
-
-import java.io.Serializable;
-
-import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.Language;
-import org.apache.clerezza.api.Literal;
-
-/**
- *
- * @author reto
- */
-public class PlainLiteralImpl extends AbstractLiteral implements Literal, Serializable {
-
-    private final String lexicalForm;
-    private final Language language;
-
-    public PlainLiteralImpl(String value) {
-        this(value, null);
-    }
-
-    public PlainLiteralImpl(String value, Language language) {
-        if (value == null) {
-            throw new IllegalArgumentException("The literal string cannot be null");
-        }
-        this.lexicalForm = value;
-        this.language = language;
-        if (language == null) {
-            dataType = XSD_STRING;
-        } else {
-            dataType = RDF_LANG_STRING;
-        }
-    }
-
-    @Override
-    public String getLexicalForm() {
-        return lexicalForm;
-    }
-
-    @Override
-    public Language getLanguage() {
-        return language;
-    }
-
-    @Override
-    public String toString() {
-        final StringBuilder result = new StringBuilder();
-        result.append('\"').append(lexicalForm).append('\"');
-        if (language != null) {
-            result.append("@").append(language.toString());
-        }
-        return result.toString();
-    }
-
-    @Override
-    public IRI getDataType() {
-        return dataType;
-    }
-    private final IRI dataType;
-    private static final IRI XSD_STRING = new IRI("http://www.w3.org/2001/XMLSchema#string");
-    private static final IRI RDF_LANG_STRING = new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/TypedLiteralImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/TypedLiteralImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/TypedLiteralImpl.java
deleted file mode 100644
index 0be7ab3..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/TypedLiteralImpl.java
+++ /dev/null
@@ -1,79 +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.api.impl;
-
-import java.io.Serializable;
-
-import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.Language;
-
-/**
- *
- * @author reto
- */
-public class TypedLiteralImpl extends AbstractLiteral implements  Serializable {
-    private String lexicalForm;
-    private IRI dataType;
-    private int hashCode;
-
-    /**
-     * @param lexicalForm 
-     * @param dataType 
-     */
-    public TypedLiteralImpl(String lexicalForm, IRI dataType) {
-        this.lexicalForm = lexicalForm;
-        this.dataType = dataType;
-        this.hashCode = super.hashCode();
-    }
-    
-    public IRI getDataType() {
-        return dataType;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.clerezza.rdf.core.LiteralNode#getLexicalForm()
-     */
-    @Override
-    public String getLexicalForm() {
-        return lexicalForm;
-    }
-
-    @Override
-    public int hashCode() {
-        return hashCode;
-    }
-    
-
-    @Override
-    public String toString() {
-        StringBuffer result = new StringBuffer();
-        result.append('\"');
-        result.append(getLexicalForm());
-        result.append('\"');
-        result.append("^^");
-        result.append(getDataType());
-        return result.toString();
-    }
-
-    @Override
-    public Language getLanguage() {
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/WatchableGraphWrapper.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/WatchableGraphWrapper.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/WatchableGraphWrapper.java
deleted file mode 100644
index 5533c9b..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/WatchableGraphWrapper.java
+++ /dev/null
@@ -1,290 +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.api.impl;
-
-import java.lang.ref.WeakReference;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.locks.ReadWriteLock;
-
-import org.apache.clerezza.api.BlankNodeOrIRI;
-import org.apache.clerezza.api.Graph;
-import org.apache.clerezza.api.ImmutableGraph;
-import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.RDFTerm;
-import org.apache.clerezza.api.Triple;
-import org.apache.clerezza.api.WatchableGraph;
-import org.apache.clerezza.api.event.AddEvent;
-import org.apache.clerezza.api.event.FilterTriple;
-import org.apache.clerezza.api.event.GraphEvent;
-import org.apache.clerezza.api.event.GraphListener;
-import org.apache.clerezza.api.event.RemoveEvent;
-
-/**
- *
- * @author developer
- */
-public class WatchableGraphWrapper implements WatchableGraph {
-    
-    final Graph wrapped;
-
-    public WatchableGraphWrapper(Graph wrapped) {
-        this.wrapped = wrapped;
-    }
-    
-       
-    //all listeners
-    private final Set<ListenerConfiguration> listenerConfigs = Collections.synchronizedSet(
-            new HashSet<ListenerConfiguration>());
-    private DelayedNotificator delayedNotificator = new DelayedNotificator();
-
-    @Override
-    public Iterator<Triple> iterator() {
-        return filter(null, null, null);
-    }
-
-    @Override
-    public boolean contains(Object o) {
-        if (!(o instanceof Triple)) {
-            return false;
-        }
-        Triple t = (Triple) o;
-        return filter(t.getSubject(), t.getPredicate(), t.getObject()).hasNext();
-    }
-
-    @Override
-    public Iterator<Triple> filter(BlankNodeOrIRI subject, IRI predicate,
-                                   RDFTerm object) {
-        final Iterator<Triple> baseIter = wrapped.filter(subject, predicate, object);
-        return new Iterator<Triple>() {
-
-            Triple currentTriple = null;
-
-            @Override
-            public boolean hasNext() {
-                return baseIter.hasNext();
-            }
-
-            @Override
-            public Triple next() {
-                currentTriple = baseIter.next();
-                return currentTriple;
-            }
-
-            @Override
-            public void remove() {
-                baseIter.remove();
-                dispatchEvent(new RemoveEvent(WatchableGraphWrapper.this, currentTriple));
-            }
-        };
-    }
-
-    @Override
-    public boolean add(Triple triple) {
-        boolean success = performAdd(triple);
-        if (success) {
-            dispatchEvent(new AddEvent(this, triple));
-        }
-        return success;
-    }
-
-    /**
-     * A subclass of <code>AbstractGraph</code> should override 
-     * this method instead of <code>add</code> for Graph event support to be
-     * added.
-     * 
-     * @param e The triple to be added to the triple collection
-     * @return
-     */
-    protected boolean performAdd(Triple e) {
-        return wrapped.add(e);
-    }
-
-    @Override
-    public boolean remove(Object o) {
-        Triple triple = (Triple) o;
-        boolean success = performRemove(triple);
-        if (success) {
-            dispatchEvent(new RemoveEvent(this, triple));
-        }
-        return success;
-    }
-
-    @Override
-    public boolean removeAll(Collection<?> c) {
-        boolean modified = false;
-        for (Iterator<? extends Object> it = c.iterator(); it.hasNext();) {
-            Object object = it.next();
-            if (remove(object)) {
-                modified = true;
-            }
-        }
-        return modified;
-    }
-
-    /**
-     * A subclass of <code>AbstractGraph</code> should override 
-     * this method instead of <code>remove</code> for ImmutableGraph event support to be
-     * added.
-     * 
-     * @param o The triple to be removed from the triple collection
-     * @return
-     */
-    protected boolean performRemove(Triple triple) {
-        Iterator<Triple> e = filter(null, null, null);
-        while (e.hasNext()) {
-            if (triple.equals(e.next())) {
-                e.remove();
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Dispatches a <code>GraphEvent</code> to all registered listeners for which
-     * the specified <code>Triple</code> matches the <code>FilterTriple</code>s
-     * of the listeners.
-     * 
-     * @param triple The Triple that was modified
-     * @param type The type of modification
-     */
-    protected void dispatchEvent(GraphEvent event) {
-        synchronized(listenerConfigs) {
-            Iterator<ListenerConfiguration> iter = listenerConfigs.iterator();
-            while (iter.hasNext()) {
-                ListenerConfiguration config = iter.next();
-                GraphListener registeredListener = config.getListener();
-                if (registeredListener == null) {
-                    iter.remove();
-                    continue;
-                }
-                if (config.getFilter().match(event.getTriple())) {
-                    delayedNotificator.sendEventToListener(registeredListener, event);
-                }
-            }
-        }
-    }
-
-    @Override
-    public void addGraphListener(GraphListener listener, FilterTriple filter) {
-        addGraphListener(listener, filter, 0);
-    }
-
-    @Override
-    public void addGraphListener(GraphListener listener, FilterTriple filter,
-            long delay) {
-        listenerConfigs.add(new ListenerConfiguration(listener, filter));
-        if (delay > 0) {
-            delayedNotificator.addDelayedListener(listener, delay);
-        }
-    }
-
-    @Override
-    public void removeGraphListener(GraphListener listener) {
-        synchronized(listenerConfigs) {
-            Iterator<ListenerConfiguration> iter = listenerConfigs.iterator();
-            while (iter.hasNext()) {
-                ListenerConfiguration listenerConfig = iter.next();
-                GraphListener registeredListener = listenerConfig.getListener();
-                if ((registeredListener == null) || (registeredListener.equals(listener))) {
-                    iter.remove();
-                }
-            }
-        }
-        delayedNotificator.removeDelayedListener(listener);
-    }
-
-    @Override
-    public ImmutableGraph getImmutableGraph() {
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public ReadWriteLock getLock() {
-        return wrapped.getLock();
-    }
-
-    @Override
-    public int size() {
-        return wrapped.size();
-    }
-
-    @Override
-    public boolean isEmpty() {
-        return wrapped.isEmpty();
-    }
-
-    @Override
-    public Object[] toArray() {
-        return wrapped.toArray();
-    }
-
-    @Override
-    public <T> T[] toArray(T[] a) {
-        return wrapped.toArray(a);
-    }
-
-    @Override
-    public boolean containsAll(Collection<?> c) {
-        return wrapped.containsAll(c);
-    }
-
-    @Override
-    public boolean addAll(Collection<? extends Triple> c) {
-        return wrapped.addAll(c);
-    }
-
-    @Override
-    public boolean retainAll(Collection<?> c) {
-        return wrapped.retainAll(c);
-    }
-
-    @Override
-    public void clear() {
-        wrapped.clear();
-    }
-
-    private static class ListenerConfiguration {
-
-        private WeakReference<GraphListener> listenerRef;
-        private FilterTriple filter;
-
-        private ListenerConfiguration(GraphListener listener, FilterTriple filter) {
-            this.listenerRef = new WeakReference<GraphListener>(listener);
-            this.filter = filter;
-        }
-
-        /**
-         * @return the listener
-         */
-        GraphListener getListener() {
-            GraphListener listener = listenerRef.get();
-            return listener;
-        }
-
-        /**
-         * @return the filter
-         */
-        FilterTriple getFilter() {
-            return filter;
-        }
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/AbstractGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/AbstractGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/AbstractGraph.java
new file mode 100644
index 0000000..b4e996e
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/AbstractGraph.java
@@ -0,0 +1,306 @@
+/*
+ * 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.api.impl.graph;
+
+import java.util.AbstractCollection;
+import java.util.Collection;
+import java.util.Iterator;
+
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.clerezza.api.Graph;
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.BlankNodeOrIRI;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+import org.apache.clerezza.api.ImmutableGraph;
+import org.apache.clerezza.api.impl.debug.ReentrantReadWriteLockTracker;
+
+/**
+ * An abstract implementation of <code>Graph</code> implementing
+ * <code>iterator</code> and <code>contains</code> calling <code>filter</code>.
+ *
+ * @author reto
+ */
+public abstract class AbstractGraph extends AbstractCollection<Triple>
+        implements Graph {
+
+    
+    private static final String DEBUG_MODE = "rdfLocksDebugging";
+    private final ReadWriteLock lock;
+
+    private final Lock readLock;
+    private final Lock writeLock;
+
+    /**
+     * Constructs a LocalbleMGraph for an Graph.
+     *
+     * @param providedMGraph a non-lockable graph
+     */
+    public AbstractGraph() {
+        {
+            String debugMode = System.getProperty(DEBUG_MODE);
+            if (debugMode != null && debugMode.toLowerCase().equals("true")) {
+                lock = new ReentrantReadWriteLockTracker();
+            } else {
+                lock = new ReentrantReadWriteLock();
+            }
+        }
+        readLock = lock.readLock();
+        writeLock = lock.writeLock();
+    }
+    
+    public AbstractGraph(final ReadWriteLock lock) {
+        this.lock = lock;
+        readLock = lock.readLock();
+        writeLock = lock.writeLock();
+    }
+
+    @Override
+    public ReadWriteLock getLock() {
+        return lock;
+    }
+
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        readLock.lock();
+        try {
+            return performGetImmutableGraph();
+        } finally {
+            readLock.unlock();
+        }
+    }
+    
+    public ImmutableGraph performGetImmutableGraph() {
+        return new SimpleImmutableGraph(this);
+    }
+
+    @Override
+    public Iterator<Triple> filter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        readLock.lock();
+        try {
+            return new LockingIterator(performFilter(subject, predicate, object), lock);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public int size() {
+        readLock.lock();
+        try {
+            return performSize();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean isEmpty() {
+        readLock.lock();
+        try {
+            return performIsEmpty();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    @SuppressWarnings("element-type-mismatch")
+    public boolean contains(Object o) {
+        readLock.lock();
+        try {
+            return performContains(o);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public Iterator<Triple> iterator() {
+        readLock.lock();
+        try {
+            return new LockingIterator(performIterator(), lock);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public Object[] toArray() {
+        readLock.lock();
+        try {
+            return performToArray();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public <T> T[] toArray(T[] a) {
+        readLock.lock();
+        try {
+            return performToArray(a);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+        readLock.lock();
+        try {
+            return performContainsAll(c);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean add(Triple e) {
+        writeLock.lock();
+        try {
+            return performAdd(e);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        writeLock.lock();
+        try {
+            return performRemove(o);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Triple> c) {
+        writeLock.lock();
+        try {
+            return performAddAll(c);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        writeLock.lock();
+        try {
+            return performRemoveAll(c);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        writeLock.lock();
+        try {
+            return performRetainAll(c);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public void clear() {
+        writeLock.lock();
+        try {
+            performClear();
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    
+    @Override
+    public boolean equals(Object obj) {
+        /*if (obj == null) {
+            return false;
+        }
+        if (obj == this) {
+            return true;
+        }
+        if (obj.getClass() != getClass()) {
+            return false;
+        }*/
+        return this == obj;
+    }
+
+
+    protected abstract Iterator<Triple> performFilter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+    protected abstract int performSize();
+
+    protected boolean performIsEmpty() {
+        return super.isEmpty();
+    }
+
+    protected Object[] performToArray() {
+        return super.toArray();
+    }
+
+    protected boolean performRemove(Object o) {
+        return super.remove(o);
+    }
+
+    protected boolean performAddAll(Collection<? extends Triple> c) {
+        return super.addAll(c);
+    }
+
+    protected boolean performRemoveAll(Collection<?> c) {
+        return super.removeAll(c);
+    }
+
+    protected boolean performRetainAll(Collection<?> c) {
+        return super.retainAll(c);
+    }
+
+    protected void performClear() {
+        super.clear();
+    }
+
+    protected boolean performContains(Object o) {
+        return super.contains(o);
+    }
+
+    protected Iterator<Triple> performIterator() {
+        return performFilter(null, null, null);
+    }
+
+    protected boolean performContainsAll(Collection<?> c) {
+        return super.containsAll(c);
+    }
+
+    protected <T> T[] performToArray(T[] a) {
+        return super.toArray(a);
+    }
+
+    protected boolean performAdd(Triple e) {
+        return super.add(e);
+    }
+
+ 
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/AbstractImmutableGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/AbstractImmutableGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/AbstractImmutableGraph.java
new file mode 100644
index 0000000..a9c35b6
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/AbstractImmutableGraph.java
@@ -0,0 +1,112 @@
+/*
+ * 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.api.impl.graph;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.clerezza.api.impl.graphmatching.GraphMatcher;
+import org.apache.clerezza.api.BlankNode;
+import org.apache.clerezza.api.ImmutableGraph;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+
+/**
+ * <code>AbstractGraph</code> is an abstract implementation of <code>ImmutableGraph</code> 
+ * implementing the <code>equals</code> and the <code>hashCode</code> methods.
+ * 
+ * @author reto
+ * 
+ */
+public abstract class AbstractImmutableGraph extends AbstractGraph
+        implements ImmutableGraph {
+
+    public final synchronized int hashCode() {
+        int result = 0;
+        for (Iterator<Triple> iter = iterator(); iter.hasNext();) {
+            result += getBlankNodeBlindHash(iter.next());
+        }
+        return result;
+    }
+
+    /**
+     * @param triple
+     * @return hash without BNode hashes
+     */
+    private int getBlankNodeBlindHash(Triple triple) {
+        int hash = triple.getPredicate().hashCode();
+        RDFTerm subject = triple.getSubject();
+
+        if (!(subject instanceof BlankNode)) {
+            hash ^= subject.hashCode() >> 1;
+        }
+        RDFTerm object = triple.getObject();
+        if (!(object instanceof BlankNode)) {
+            hash ^= object.hashCode() << 1;
+        }
+
+        return hash;
+    }
+
+    @Override
+    public boolean add(Triple e) {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Triple> c) {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+    }
+
+    @Override
+    public void clear() {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+    }
+    
+    
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        return this;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof ImmutableGraph)) {
+            return false;
+        }
+        if (hashCode() != obj.hashCode()) {
+            return false;
+        }
+        return GraphMatcher.getValidMapping(this, (ImmutableGraph) obj) != null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/DelayedNotificator.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/DelayedNotificator.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/DelayedNotificator.java
new file mode 100644
index 0000000..a3512e2
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/DelayedNotificator.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.api.impl.graph;
+
+import java.lang.ref.WeakReference;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.clerezza.api.event.GraphEvent;
+import org.apache.clerezza.api.event.GraphListener;
+
+
+/**
+ *
+ * @author reto
+ */
+class DelayedNotificator {
+
+    private static final Logger log = Logger.getLogger(DelayedNotificator.class.getName());
+    private static Timer timer = new Timer("Event delivery timer",true);
+
+    static class ListenerHolder {
+
+        long delay;
+        List<GraphEvent> events = null;
+        WeakReference<GraphListener> listenerRef;
+
+        public ListenerHolder(GraphListener listener, long delay) {
+            this.listenerRef = new WeakReference<GraphListener>(listener);
+            this.delay = delay;
+        }
+
+        private void registerEvent(GraphEvent event) {
+            synchronized (this) {
+                if (events == null) {
+                    events = new ArrayList<GraphEvent>();
+                    events.add(event);
+                    timer.schedule(new TimerTask() {
+
+                        @Override
+                        public void run() {
+                            List<GraphEvent> eventsLocal;
+                            synchronized (ListenerHolder.this) {
+                                eventsLocal = events;
+                                events = null;
+                            }
+                            GraphListener listener = listenerRef.get();
+                            if (listener == null) {
+                                log.fine("Ignoring garbage collected listener");
+                            } else {
+                                try {
+                                    listener.graphChanged(eventsLocal);
+                                } catch (Exception e) {
+                                    log.log(Level.WARNING, "Exception delivering ImmutableGraph event", e);
+                                }
+                            }
+                        }
+                    }, delay);
+                } else {
+                    events.add(event);
+                }
+            }
+        }
+    }
+    
+    private final Map<GraphListener, ListenerHolder> map = Collections.synchronizedMap(
+            new WeakHashMap<GraphListener, ListenerHolder>());
+
+    void addDelayedListener(GraphListener listener, long delay) {
+        map.put(listener, new ListenerHolder(listener, delay));
+    }
+
+    /**
+     * removes a Listener, this doesn't prevent the listenerRef from receiving
+     * events alreay scheduled.
+     *
+     * @param listenerRef
+     */
+    void removeDelayedListener(GraphListener listener) {
+        map.remove(listener);
+    }
+
+    /**
+     * if the listenerRef has not been registered as delayed listenerRef te events is
+     * forwarded synchroneously
+     * @param event
+     */
+    void sendEventToListener(GraphListener listener, GraphEvent event) {
+        ListenerHolder holder = map.get(listener);
+        if (holder == null) {
+            listener.graphChanged(Collections.singletonList(event));
+        } else {
+            holder.registerEvent(event);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/LockingIterator.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/LockingIterator.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/LockingIterator.java
new file mode 100644
index 0000000..4db0d85
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/LockingIterator.java
@@ -0,0 +1,73 @@
+/*
+ * 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.api.impl.graph;
+
+import java.util.Iterator;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import org.apache.clerezza.api.Triple;
+
+/**
+ * Wrapps an iterator<Triple> reading entering a read-lock on every invocation
+ * of hasNext and next
+ * @author reto
+ */
+class LockingIterator implements Iterator<Triple> {
+
+    private Iterator<Triple> base;
+    private Lock readLock;
+    private Lock writeLock;
+
+    public LockingIterator(Iterator<Triple> iterator, ReadWriteLock lock) {
+        base = iterator;
+        readLock = lock.readLock();
+        writeLock = lock.writeLock();
+    }
+
+    @Override
+    public boolean hasNext() {
+        readLock.lock();
+        try {
+            return base.hasNext();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public Triple next() {
+        readLock.lock();
+        try {
+            return base.next();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public void remove() {
+        writeLock.lock();
+        try {
+            base.remove();
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/PrivilegedGraphWrapper.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/PrivilegedGraphWrapper.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/PrivilegedGraphWrapper.java
new file mode 100644
index 0000000..ce682b0
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/PrivilegedGraphWrapper.java
@@ -0,0 +1,254 @@
+/*
+ * 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.api.impl.graph;
+
+import org.apache.clerezza.api.*;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.locks.ReadWriteLock;
+
+/**
+ * Calls the methods of the wrapped <code>Graph</code> as privileged
+ * code, because they may need permissions like writing to disk or accessing       
+ * network.
+ *
+ * @author mir
+ */
+public class PrivilegedGraphWrapper implements Graph {
+
+    private Graph graph;
+
+    public PrivilegedGraphWrapper(Graph Graph) {
+        this.graph = Graph;
+    }
+
+    @Override
+    public Iterator<Triple> filter(final BlankNodeOrIRI subject, final IRI predicate,
+            final RDFTerm object) {
+        return AccessController.doPrivileged(new PrivilegedAction<Iterator<Triple>>() {
+
+            @Override
+            public Iterator<Triple> run() {
+                return graph.filter(subject, predicate, object);
+            }
+        });
+    }
+
+    @Override
+    public int size() {
+        return AccessController.doPrivileged(new PrivilegedAction<Integer>() {
+
+            @Override
+            public Integer run() {
+                return graph.size();
+            }
+        });
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+
+            @Override
+            public Boolean run() {
+                return graph.isEmpty();
+            }
+        });
+    }
+
+    @Override
+    public boolean contains(final Object o) {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+
+            @Override
+            public Boolean run() {
+                return graph.contains(o);
+            }
+        });
+    }
+
+    @Override
+    public Iterator<Triple> iterator() {
+        return AccessController.doPrivileged(new PrivilegedAction<Iterator<Triple>>() {
+
+            @Override
+            public Iterator<Triple> run() {
+                return graph.iterator();
+            }
+        });
+    }
+
+    @Override
+    public Object[] toArray() {
+        return AccessController.doPrivileged(new PrivilegedAction<Object[]>() {
+
+            @Override
+            public Object[] run() {
+                return graph.toArray();
+            }
+        });
+    }
+
+    @Override
+    public <T> T[] toArray(final T[] a) {
+        return AccessController.doPrivileged(new PrivilegedAction<T[]>() {
+
+            @Override
+            public T[] run() {
+                return graph.toArray(a);
+            }
+        });
+    }
+
+    @Override
+    public boolean add(final Triple triple) {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+
+            @Override
+            public Boolean run() {
+                return graph.add(triple);
+            }
+        });
+    }
+
+    @Override
+    public boolean remove(final Object o) {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+
+            @Override
+            public Boolean run() {
+                return graph.remove(o);
+            }
+        });
+    }
+
+    @Override
+    public boolean containsAll(final Collection<?> c) {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+
+            @Override
+            public Boolean run() {
+                return graph.containsAll(c);
+            }
+        });
+    }
+
+    @Override
+    public boolean addAll(final Collection<? extends Triple> c) {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+
+            @Override
+            public Boolean run() {
+                return graph.addAll(c);
+            }
+        });
+    }
+
+    @Override
+    public boolean removeAll(final Collection<?> c) {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+
+            @Override
+            public Boolean run() {
+                return graph.removeAll(c);
+            }
+        });
+    }
+
+    @Override
+    public boolean retainAll(final Collection<?> c) {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+
+            @Override
+            public Boolean run() {
+                return graph.retainAll(c);
+            }
+        });
+    }
+
+    @Override
+    public void clear() {
+        AccessController.doPrivileged(new PrivilegedAction<Object>() {
+
+            @Override
+            public Object run() {
+                graph.clear();
+                return null;
+            }
+        });
+    }
+
+    @Override
+    public ReadWriteLock getLock() {
+        return graph.getLock();
+    }
+
+    private static class PriviledgedTripleIterator implements Iterator<Triple> {
+
+        private final Iterator<Triple> wrappedIterator;
+
+        public PriviledgedTripleIterator(Iterator<Triple> wrappedIterator) {
+            this.wrappedIterator = wrappedIterator;
+        }
+
+        @Override
+        public boolean hasNext() {
+            return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+
+                @Override
+                public Boolean run() {
+                    return wrappedIterator.hasNext();
+                }
+            });
+        }
+
+        @Override
+        public Triple next() {
+            return AccessController.doPrivileged(new PrivilegedAction<Triple>() {
+
+                @Override
+                public Triple run() {
+                    return wrappedIterator.next();
+                }
+            });
+        }
+
+        @Override
+        public void remove() {
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
+
+                @Override
+                public Object run() {
+                    wrappedIterator.remove();
+                    return null;
+                }
+            });
+        }
+    }
+    
+    
+
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        return new SimpleImmutableGraph(this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/PrivilegedImmuatbleGraphWrapper.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/PrivilegedImmuatbleGraphWrapper.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/PrivilegedImmuatbleGraphWrapper.java
new file mode 100644
index 0000000..f9367ac
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/PrivilegedImmuatbleGraphWrapper.java
@@ -0,0 +1,36 @@
+/*
+ * 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.api.impl.graph;
+
+import org.apache.clerezza.api.ImmutableGraph;
+
+/**
+ * Calls the methods of the wrapped <code>ImmutableGraph</code> as privileged
+ * code, because they may need permissions like writing to disk or accessing       
+ * network.
+ * 
+ * @author mir
+ */
+public class PrivilegedImmuatbleGraphWrapper extends PrivilegedGraphWrapper
+        implements ImmutableGraph {
+
+    public PrivilegedImmuatbleGraphWrapper(ImmutableGraph ImmutableGraph) {
+        super(ImmutableGraph);
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/ReadOnlyException.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/ReadOnlyException.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/ReadOnlyException.java
new file mode 100644
index 0000000..ea5456f
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/ReadOnlyException.java
@@ -0,0 +1,50 @@
+/*
+ * 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.api.impl.graph;
+
+import java.security.AccessControlException;
+
+/**
+ * is thrown on an attempt to add or remove triples to a 
+ * read-only mutable ImmutableGraph 
+ *
+ * @author tsuy
+ */
+public class ReadOnlyException extends AccessControlException {
+
+    private String action;
+
+    /**
+     * creates an exception indicating that the mutable ImmutableGraph is read-only
+     * 
+     * @param action
+     */
+    public ReadOnlyException(String action) {
+        super("read only mutable ImmutableGraph, not allowed to "+action);
+        this.action = action;
+    }
+
+    /**
+     * 
+     * @return the name of the action
+     */
+    public String getAction() {
+        return action;
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleGraph.java
new file mode 100644
index 0000000..0209c28
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleGraph.java
@@ -0,0 +1,206 @@
+/*
+ * 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.api.impl.graph;
+
+import org.apache.clerezza.api.*;
+
+import java.lang.ref.SoftReference;
+import java.util.*;
+
+/**
+ * For now this is a minimalistic implementation, without any indexes or other
+ * optimizations.
+ *
+ * @author reto
+ */
+public class SimpleGraph extends AbstractGraph {
+
+    final Set<Triple> triples;
+
+    private boolean checkConcurrency = false;
+
+    class SimpleIterator implements Iterator<Triple> {
+
+        private Iterator<Triple> listIter;
+        private boolean isValid = true;
+
+        public SimpleIterator(Iterator<Triple> listIter) {
+            this.listIter = listIter;
+        }
+        private Triple currentNext;
+
+        @Override
+        public boolean hasNext() {
+            checkValidity();
+            return listIter.hasNext();
+        }
+
+        @Override
+        public Triple next() {
+            checkValidity();
+            currentNext = listIter.next();
+            return currentNext;
+        }        
+
+        @Override
+        public void remove() {
+            checkValidity();
+            listIter.remove();
+            triples.remove(currentNext);            
+            invalidateIterators(this);            
+        }
+
+        private void checkValidity() throws ConcurrentModificationException {
+            if (checkConcurrency && !isValid) {
+                throw new ConcurrentModificationException();
+            }
+        }
+
+        private void invalidate() {
+            isValid = false;
+        }
+    }    
+    
+    private final Set<SoftReference<SimpleIterator>> iterators =
+            Collections.synchronizedSet(new HashSet<SoftReference<SimpleIterator>>());
+    
+    /**
+     * Creates an empty SimpleGraph
+     */
+    public SimpleGraph() {
+        triples = Collections.synchronizedSet(new HashSet<Triple>());
+    }
+
+    /**
+     * Creates a SimpleGraph using the passed iterator, the iterator 
+     * is consumed before the constructor returns
+     * 
+     * @param iterator
+     */
+    public SimpleGraph(Iterator<Triple> iterator) {
+        triples = new HashSet<Triple>();
+        while (iterator.hasNext()) {
+            Triple triple = iterator.next();
+            triples.add(triple);
+        }
+    }
+
+    /**
+     * Creates a SimpleGraph for the specified set of triples, 
+     * subsequent modification of baseSet do affect the created instance.
+     * 
+     * @param baseSet
+     */
+    public SimpleGraph(Set<Triple> baseSet) {
+        this.triples = baseSet;
+    }
+
+    /**
+     * Creates a SimpleGraph for the specified collection of triples,
+     * subsequent modification of baseSet do not affect the created instance.
+     *
+     * @param baseSet
+     */
+    public SimpleGraph(Collection<Triple> baseCollection) {
+        this.triples = new HashSet<Triple>(baseCollection);
+    }
+
+    @Override
+    public int performSize() {
+        return triples.size();
+    }
+
+    @Override
+    public Iterator<Triple> performFilter(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
+        final List<Triple> tripleList = new ArrayList<Triple>();
+        synchronized (triples) {
+            Iterator<Triple> baseIter = triples.iterator();
+            while (baseIter.hasNext()) {
+                Triple triple = baseIter.next();
+                if ((subject != null)
+                        && (!triple.getSubject().equals(subject))) {
+                    continue;
+                }
+                if ((predicate != null)
+                        && (!triple.getPredicate().equals(predicate))) {
+                    continue;
+                }
+                if ((object != null)
+                        && (!triple.getObject().equals(object))) {
+                    continue;
+                }
+                tripleList.add(triple);
+            }
+
+            final Iterator<Triple> listIter = tripleList.iterator();
+            SimpleIterator resultIter = new SimpleIterator(listIter);
+            if (checkConcurrency) {
+                iterators.add(new SoftReference<SimpleIterator>(resultIter));
+            }
+            return resultIter;
+        }
+    }
+
+
+    @Override
+    public boolean performAdd(Triple e) {
+        boolean modified = triples.add(e);
+        if (modified) {
+            invalidateIterators(null);
+        }
+        return modified;
+    }
+    
+    private void invalidateIterators(SimpleIterator caller) {
+        if (!checkConcurrency) {
+            return;
+        }
+        Set<SoftReference> oldReferences = new HashSet<SoftReference>();
+        synchronized(iterators) {
+            for (SoftReference<SimpleGraph.SimpleIterator> softReference : iterators) {
+                SimpleIterator simpleIterator = softReference.get();
+                if (simpleIterator == null) {
+                    oldReferences.add(softReference);
+                    continue;
+                }
+                if (simpleIterator != caller) {
+                    simpleIterator.invalidate();
+                }
+            }
+        }
+        iterators.removeAll(oldReferences);
+    }
+
+    /**
+     * Specifies whether or not to throw <code>ConcurrentModificationException</code>s,
+     * if this simple triple collection is modified concurrently. Concurrency
+     * check is set to false by default.
+     *
+     * @param bool Specifies whether or not to check concurrent modifications.
+     */
+    public void setCheckConcurrency(boolean bool) {
+        checkConcurrency = bool;
+    }
+    
+    
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        return new SimpleImmutableGraph(this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleImmutableGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleImmutableGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleImmutableGraph.java
new file mode 100644
index 0000000..46b95ad
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleImmutableGraph.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.api.impl.graph;
+
+import java.util.Iterator;
+
+import org.apache.clerezza.api.BlankNodeOrIRI;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+import org.apache.clerezza.api.Graph;
+import org.apache.clerezza.api.IRI;
+
+/**
+ *
+ * @author reto
+ */
+public class SimpleImmutableGraph extends AbstractImmutableGraph {
+
+    private Graph graph;
+    
+    /**
+     * Creates a ImmutableGraph with the triples in Graph
+     * 
+     * @param Graph the collection of triples this ImmutableGraph shall consist of
+     */
+    public SimpleImmutableGraph(Graph Graph) {
+        this.graph = new SimpleGraph(Graph.iterator());
+    }
+
+    /**
+     * Creates a ImmutableGraph with the triples in Graph.
+     *
+     * This construction allows to specify if the Graph might change
+     * in future. If GraphWillNeverChange is set to true it will
+     * assume that the collection never changes, in this case the collection
+     * isn't copied making things more efficient.
+     *
+     * @param Graph the collection of triples this ImmutableGraph shall consist of
+     * @param GraphWillNeverChange true if the caller promises Graph will never change
+     */
+    public SimpleImmutableGraph(Graph Graph, boolean GraphWillNeverChange) {
+        if (!GraphWillNeverChange) {
+            this.graph = new SimpleGraph(Graph.iterator());
+        } else {
+            this.graph = Graph;
+        }
+    }
+    
+    public SimpleImmutableGraph(Iterator<Triple> tripleIter) {
+        this.graph = new SimpleGraph(tripleIter);
+    }
+
+    @Override
+    public int performSize() {
+        return graph.size();
+    }
+
+    @Override
+    public Iterator<Triple> performFilter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        return graph.filter(subject, predicate, object);
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleMGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleMGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleMGraph.java
new file mode 100644
index 0000000..94cd03a
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/SimpleMGraph.java
@@ -0,0 +1,56 @@
+/*
+ * 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.api.impl.graph;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.clerezza.api.Graph;
+import org.apache.clerezza.api.Triple;
+
+/**
+ *
+ * @deprecated Use SimpleGraph
+ * @author reto
+ */
+@Deprecated
+public class SimpleMGraph extends SimpleGraph implements Graph {
+
+    /**
+     * Creates an empty SimpleMGraph
+     */
+    public SimpleMGraph() {
+    }
+
+    public SimpleMGraph(Set<Triple> baseSet) {
+        super(baseSet);
+    }
+
+    public SimpleMGraph(Collection<Triple> baseCollection) {
+        super(baseCollection);
+    }
+
+    public SimpleMGraph(Iterator<Triple> iterator) {
+        super(iterator);
+    }
+
+}
+
+    
\ No newline at end of file


[2/3] clerezza git commit: CLEREZZA-1026: Copy additional classes from rdf.core to api.impl and refactor api.impl

Posted by ha...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/WatchableGraphWrapper.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/WatchableGraphWrapper.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/WatchableGraphWrapper.java
new file mode 100644
index 0000000..c86156d
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/WatchableGraphWrapper.java
@@ -0,0 +1,276 @@
+/*
+ * 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.api.impl.graph;
+
+import org.apache.clerezza.api.*;
+import org.apache.clerezza.api.event.*;
+
+import java.lang.ref.WeakReference;
+import java.util.*;
+import java.util.concurrent.locks.ReadWriteLock;
+
+/**
+ *
+ * @author developer
+ */
+public class WatchableGraphWrapper implements WatchableGraph {
+    
+    final Graph wrapped;
+
+    public WatchableGraphWrapper(Graph wrapped) {
+        this.wrapped = wrapped;
+    }
+    
+       
+    //all listeners
+    private final Set<ListenerConfiguration> listenerConfigs = Collections.synchronizedSet(
+            new HashSet<ListenerConfiguration>());
+    private DelayedNotificator delayedNotificator = new DelayedNotificator();
+
+    @Override
+    public Iterator<Triple> iterator() {
+        return filter(null, null, null);
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        if (!(o instanceof Triple)) {
+            return false;
+        }
+        Triple t = (Triple) o;
+        return filter(t.getSubject(), t.getPredicate(), t.getObject()).hasNext();
+    }
+
+    @Override
+    public Iterator<Triple> filter(BlankNodeOrIRI subject, IRI predicate,
+                                   RDFTerm object) {
+        final Iterator<Triple> baseIter = wrapped.filter(subject, predicate, object);
+        return new Iterator<Triple>() {
+
+            Triple currentTriple = null;
+
+            @Override
+            public boolean hasNext() {
+                return baseIter.hasNext();
+            }
+
+            @Override
+            public Triple next() {
+                currentTriple = baseIter.next();
+                return currentTriple;
+            }
+
+            @Override
+            public void remove() {
+                baseIter.remove();
+                dispatchEvent(new RemoveEvent(WatchableGraphWrapper.this, currentTriple));
+            }
+        };
+    }
+
+    @Override
+    public boolean add(Triple triple) {
+        boolean success = performAdd(triple);
+        if (success) {
+            dispatchEvent(new AddEvent(this, triple));
+        }
+        return success;
+    }
+
+    /**
+     * A subclass of <code>AbstractGraph</code> should override 
+     * this method instead of <code>add</code> for Graph event support to be
+     * added.
+     * 
+     * @param e The triple to be added to the triple collection
+     * @return
+     */
+    protected boolean performAdd(Triple e) {
+        return wrapped.add(e);
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        Triple triple = (Triple) o;
+        boolean success = performRemove(triple);
+        if (success) {
+            dispatchEvent(new RemoveEvent(this, triple));
+        }
+        return success;
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        boolean modified = false;
+        for (Iterator<? extends Object> it = c.iterator(); it.hasNext();) {
+            Object object = it.next();
+            if (remove(object)) {
+                modified = true;
+            }
+        }
+        return modified;
+    }
+
+    /**
+     * A subclass of <code>AbstractGraph</code> should override 
+     * this method instead of <code>remove</code> for ImmutableGraph event support to be
+     * added.
+     * 
+     * @param o The triple to be removed from the triple collection
+     * @return
+     */
+    protected boolean performRemove(Triple triple) {
+        Iterator<Triple> e = filter(null, null, null);
+        while (e.hasNext()) {
+            if (triple.equals(e.next())) {
+                e.remove();
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Dispatches a <code>GraphEvent</code> to all registered listeners for which
+     * the specified <code>Triple</code> matches the <code>FilterTriple</code>s
+     * of the listeners.
+     * 
+     * @param triple The Triple that was modified
+     * @param type The type of modification
+     */
+    protected void dispatchEvent(GraphEvent event) {
+        synchronized(listenerConfigs) {
+            Iterator<ListenerConfiguration> iter = listenerConfigs.iterator();
+            while (iter.hasNext()) {
+                ListenerConfiguration config = iter.next();
+                GraphListener registeredListener = config.getListener();
+                if (registeredListener == null) {
+                    iter.remove();
+                    continue;
+                }
+                if (config.getFilter().match(event.getTriple())) {
+                    delayedNotificator.sendEventToListener(registeredListener, event);
+                }
+            }
+        }
+    }
+
+    @Override
+    public void addGraphListener(GraphListener listener, FilterTriple filter) {
+        addGraphListener(listener, filter, 0);
+    }
+
+    @Override
+    public void addGraphListener(GraphListener listener, FilterTriple filter,
+            long delay) {
+        listenerConfigs.add(new ListenerConfiguration(listener, filter));
+        if (delay > 0) {
+            delayedNotificator.addDelayedListener(listener, delay);
+        }
+    }
+
+    @Override
+    public void removeGraphListener(GraphListener listener) {
+        synchronized(listenerConfigs) {
+            Iterator<ListenerConfiguration> iter = listenerConfigs.iterator();
+            while (iter.hasNext()) {
+                ListenerConfiguration listenerConfig = iter.next();
+                GraphListener registeredListener = listenerConfig.getListener();
+                if ((registeredListener == null) || (registeredListener.equals(listener))) {
+                    iter.remove();
+                }
+            }
+        }
+        delayedNotificator.removeDelayedListener(listener);
+    }
+
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public ReadWriteLock getLock() {
+        return wrapped.getLock();
+    }
+
+    @Override
+    public int size() {
+        return wrapped.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return wrapped.isEmpty();
+    }
+
+    @Override
+    public Object[] toArray() {
+        return wrapped.toArray();
+    }
+
+    @Override
+    public <T> T[] toArray(T[] a) {
+        return wrapped.toArray(a);
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+        return wrapped.containsAll(c);
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Triple> c) {
+        return wrapped.addAll(c);
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        return wrapped.retainAll(c);
+    }
+
+    @Override
+    public void clear() {
+        wrapped.clear();
+    }
+
+    private static class ListenerConfiguration {
+
+        private WeakReference<GraphListener> listenerRef;
+        private FilterTriple filter;
+
+        private ListenerConfiguration(GraphListener listener, FilterTriple filter) {
+            this.listenerRef = new WeakReference<GraphListener>(listener);
+            this.filter = filter;
+        }
+
+        /**
+         * @return the listener
+         */
+        GraphListener getListener() {
+            GraphListener listener = listenerRef.get();
+            return listener;
+        }
+
+        /**
+         * @return the filter
+         */
+        FilterTriple getFilter() {
+            return filter;
+        }
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/WriteBlockedGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/WriteBlockedGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/WriteBlockedGraph.java
new file mode 100644
index 0000000..71fce87
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graph/WriteBlockedGraph.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.api.impl.graph;
+
+import org.apache.clerezza.api.*;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ *
+ * This is a wrapper object for <code>Graph</code>. If <code>SecurityManger</code> 
+ * is not <code>null</code> <code>TcManager</code> checks the <code>TcPermission</code>. 
+ * If read-only permissions are set this wrapper is used instead of <code>Graph</code> 
+ * and throws exceptions when add or remove methods are called.
+ *
+ * @author tsuy
+ */
+public class WriteBlockedGraph extends AbstractGraph
+        implements Graph {
+
+    private Graph triples;
+
+    public WriteBlockedGraph(Graph triples) {
+        this.triples = triples;
+    }
+
+    @Override
+    protected int performSize() {
+        return triples.size();
+    }
+
+    @Override
+    protected Iterator<Triple> performFilter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        final Iterator<Triple> baseIter = triples.filter(subject, predicate, object);
+        return new Iterator<Triple>() {
+            
+            @Override
+            public boolean hasNext() {
+                return baseIter.hasNext();
+            }
+
+            @Override
+            public Triple next() {
+                return baseIter.next();
+            }
+
+            @Override
+            public void remove() {
+                throw new ReadOnlyException("remove");
+            }
+
+            
+        };
+    }
+
+    @Override
+    public boolean add(Triple e) {
+        throw new ReadOnlyException("add");
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Triple> c) {
+        throw new ReadOnlyException("add all");
+    }
+
+    @Override
+    public void clear() {
+        throw new ReadOnlyException("clear");
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        throw new ReadOnlyException("remove");
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        throw new ReadOnlyException("remove all");
+    }
+    
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        throw new ReadOnlyException("retain all");
+    }
+
+    @Override
+    public Iterator iterator() {
+        return filter(null, null, null);
+    }
+    
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        return this.triples.getImmutableGraph();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcher.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcher.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcher.java
index 9180ae0..754e05d 100644
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcher.java
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcher.java
@@ -32,7 +32,7 @@ import org.apache.clerezza.api.Graph;
 import org.apache.clerezza.api.RDFTerm;
 import org.apache.clerezza.api.Triple;
 import org.apache.clerezza.api.impl.TripleImpl;
-import org.apache.clerezza.api.impl.simple.SimpleMGraph;
+import org.apache.clerezza.api.impl.graph.SimpleMGraph;
 
 /**
  * @author reto

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/AbstractLiteral.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/AbstractLiteral.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/AbstractLiteral.java
new file mode 100644
index 0000000..8444813
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/AbstractLiteral.java
@@ -0,0 +1,61 @@
+/*
+ * 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.api.impl.literal;
+
+import org.apache.clerezza.api.Literal;
+
+/**
+ *
+ * @author developer
+ */
+public abstract class AbstractLiteral implements Literal {
+
+    @Override
+    public int hashCode() {
+        int result = 0;
+        if (getLanguage() != null) {
+            result = getLanguage().hashCode();
+        }
+        result += getLexicalForm().hashCode();
+        result += getDataType().hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof Literal) {
+            Literal other = (Literal) obj;
+            
+            if (getLanguage() == null) {
+                if (other.getLanguage() != null) {
+                    return false;
+                }
+            } else {
+                if (!getLanguage().equals(other.getLanguage())) {
+                    return false;
+                }
+            }
+            boolean res = getDataType().equals(other.getDataType()) && getLexicalForm().equals(other.getLexicalForm());
+            return res;
+        } else {
+            return false;
+        }
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/InvalidLiteralTypeException.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/InvalidLiteralTypeException.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/InvalidLiteralTypeException.java
new file mode 100644
index 0000000..f4665db
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/InvalidLiteralTypeException.java
@@ -0,0 +1,40 @@
+/*
+ * 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.api.impl.literal;
+
+import org.apache.clerezza.api.IRI;
+
+/**
+ * Thrown when a literal is of the wrong type for conversion to a java-type
+ *
+ * @author reto
+ */
+public class InvalidLiteralTypeException extends RuntimeException {
+    
+    /**
+     * Constructs the exception to be thrown when a literal cannot be 
+     * converted to an instance of the specified class
+     *
+     * @param javaType the <code>Class</code> to convert to
+     * @param literalType the literalType which can't be converted
+     */
+    public InvalidLiteralTypeException(Class<?> javaType, IRI literalType) {
+        super("Cannot create a "+javaType+" from a literal of type "+literalType);
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/LiteralFactory.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/LiteralFactory.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/LiteralFactory.java
new file mode 100644
index 0000000..fc971bd
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/LiteralFactory.java
@@ -0,0 +1,83 @@
+/*
+ * 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.api.impl.literal;
+
+import org.apache.clerezza.api.Literal;
+
+/**
+ * This class provides methods to convert java objects to typed literals and
+ * vice versa. While the default implementation will provide literal objects
+ * storing the data's lexical form in memory, other implementations may
+ * create literal optimized for processing within the store.
+ *
+ * Note: this class uses the notion of "Convertor" (in the Exception naming), 
+ * but does not currently provide a mechanism to register such
+ * <code>Convertor</code>s. An implementation is said to provide
+ * <code>Convertor</code>s for the types it supports.
+ *
+ * @since 0.3
+ * @author reto
+ */
+public abstract class LiteralFactory {
+
+    private static LiteralFactory instance = new SimpleLiteralFactory();
+
+    /**
+     * Get a <code>LiteralFactory</code>. If this has not been set using
+     * setInstance it returns an instance of
+     * {@link org.apache.clerezza.model.impl.SimpleLiteralFactory}.
+     *
+     * @return a concrete <code>LiteralFactory</code>
+     */
+    public static LiteralFactory getInstance() {
+        return instance;
+    }
+
+    /**
+     * Set the instance returned by <code>getInstance</code>.
+     *
+     * @param instance the new default <code>LiteralFactory</code>
+     */
+    public static void setInstance(LiteralFactory instance) {
+        LiteralFactory.instance = instance;
+    }
+
+    /**
+     * Create a typed literal for the specified object
+     *
+     * @param value the value of the literal to be created
+     * @return a TypedLiteral representing the value
+     * @throws NoConvertorException thrown if <code>value</code> is of an invalid type
+     */
+    public abstract Literal createTypedLiteral(Object value)
+            throws NoConvertorException;
+
+    /**
+     * Converts a literal to an instance of the specified class
+     *
+     * @param <T>
+     * @param type the <code>Class</code> of the returned object
+     * @param literal the literal to be converted
+     * @return a java object representing the value of the literal
+     * @throws NoConvertorException thrown if <code>type</code> is unsupported
+     * @throws InvalidLiteralTypeException if the literal type doesn't match the requested java type
+     */
+    public abstract <T> T createObject(Class<T> type, Literal literal)
+            throws NoConvertorException, InvalidLiteralTypeException;
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/LiteralImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/LiteralImpl.java
new file mode 100644
index 0000000..7d86242
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/LiteralImpl.java
@@ -0,0 +1,82 @@
+/*
+ * 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.api.impl.literal;
+
+import java.io.Serializable;
+
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.Language;
+
+/**
+ *
+ * @author reto
+ */
+public class LiteralImpl extends AbstractLiteral implements  Serializable {
+    private String lexicalForm;
+    private IRI dataType;
+    private int hashCode;
+    private Language language;
+
+    /**
+     * @param lexicalForm 
+     * @param dataType 
+     * @param Language the language of this literal
+     */
+    public LiteralImpl(String lexicalForm, IRI dataType, Language language) {
+        this.lexicalForm = lexicalForm;
+        this.dataType = dataType;
+        this.language = language;
+        this.hashCode = super.hashCode();
+    }
+    
+    public IRI getDataType() {
+        return dataType;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.LiteralNode#getLexicalForm()
+     */
+    @Override
+    public String getLexicalForm() {
+        return lexicalForm;
+    }
+
+    @Override
+    public int hashCode() {
+        return hashCode;
+    }
+    
+
+    @Override
+    public String toString() {
+        StringBuffer result = new StringBuffer();
+        result.append('\"');
+        result.append(getLexicalForm());
+        result.append('\"');
+        result.append("^^");
+        result.append(getDataType());
+        return result.toString();
+    }
+
+    @Override
+    public Language getLanguage() {
+        return language;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/NoConvertorException.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/NoConvertorException.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/NoConvertorException.java
new file mode 100644
index 0000000..a462394
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/NoConvertorException.java
@@ -0,0 +1,41 @@
+/*
+ * 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.api.impl.literal;
+
+import java.lang.reflect.Type;
+
+/**
+ * This exception is thrown when no convertor is available to do a required
+ * java-object to literal or literal to java-object conversion.
+ *
+ * @since 0.3
+ * @author reto
+ */
+public class NoConvertorException extends RuntimeException {
+
+    /**
+     * Create an instance of <code>NoConvertorException</code>
+     * indicating that no convertor is available for the type.
+     *
+     * @param type the type for which no convertor is available
+     */
+    public NoConvertorException(Type type) {
+        super("No convertor available for type "+type);
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/PlainLiteralImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/PlainLiteralImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/PlainLiteralImpl.java
new file mode 100644
index 0000000..aeef1ea
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/PlainLiteralImpl.java
@@ -0,0 +1,80 @@
+/*
+ * 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.api.impl.literal;
+
+import java.io.Serializable;
+
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.Language;
+import org.apache.clerezza.api.Literal;
+
+/**
+ *
+ * @author reto
+ */
+public class PlainLiteralImpl extends AbstractLiteral implements Literal, Serializable {
+
+    private final String lexicalForm;
+    private final Language language;
+
+    public PlainLiteralImpl(String value) {
+        this(value, null);
+    }
+
+    public PlainLiteralImpl(String value, Language language) {
+        if (value == null) {
+            throw new IllegalArgumentException("The literal string cannot be null");
+        }
+        this.lexicalForm = value;
+        this.language = language;
+        if (language == null) {
+            dataType = XSD_STRING;
+        } else {
+            dataType = RDF_LANG_STRING;
+        }
+    }
+
+    @Override
+    public String getLexicalForm() {
+        return lexicalForm;
+    }
+
+    @Override
+    public Language getLanguage() {
+        return language;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder result = new StringBuilder();
+        result.append('\"').append(lexicalForm).append('\"');
+        if (language != null) {
+            result.append("@").append(language.toString());
+        }
+        return result.toString();
+    }
+
+    @Override
+    public IRI getDataType() {
+        return dataType;
+    }
+    private final IRI dataType;
+    private static final IRI XSD_STRING = new IRI("http://www.w3.org/2001/XMLSchema#string");
+    private static final IRI RDF_LANG_STRING = new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/SimpleLiteralFactory.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/SimpleLiteralFactory.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/SimpleLiteralFactory.java
new file mode 100644
index 0000000..9bbbb1b
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/SimpleLiteralFactory.java
@@ -0,0 +1,305 @@
+/*
+ * 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.api.impl.literal;
+
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.Literal;
+import org.apache.clerezza.api.impl.util.Base64;
+import org.apache.clerezza.api.impl.util.W3CDateFormat;
+
+import java.math.BigInteger;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.*;
+
+/**
+ * An implementation of literal factory currently supporting only
+ * byte[]/base64Binary and Java.util.Date/date
+ * 
+ * @author reto
+ */
+
+public class SimpleLiteralFactory extends LiteralFactory {
+
+    private static final String XSD = "http://www.w3.org/2001/XMLSchema#";
+    final private static IRI xsdInteger = xsd("integer");
+    final private static IRI xsdInt = xsd("int");
+    final private static IRI xsdShort = xsd("short");
+    final private static IRI xsdByte = xsd("byte");
+    final private static IRI xsdLong = xsd("long");
+    
+
+    final private static Set<IRI> decimalTypes = new HashSet<IRI>();
+
+    final private static Map<Class<?>, TypeConverter<?>> typeConverterMap = new HashMap<Class<?>, TypeConverter<?>>();
+    final static Class<? extends byte[]> byteArrayType;
+
+    static {
+        Collections.addAll(decimalTypes, xsdInteger, xsdInt, xsdByte, xsdShort, xsdLong );
+
+        byte[] byteArray = new byte[0];
+        byteArrayType = byteArray.getClass();
+        typeConverterMap.put(byteArrayType, new ByteArrayConverter());
+        typeConverterMap.put(Date.class, new DateConverter());
+        typeConverterMap.put(Boolean.class, new BooleanConverter());
+        typeConverterMap.put(String.class, new StringConverter());
+        typeConverterMap.put(Integer.class, new IntegerConverter());
+        typeConverterMap.put(BigInteger.class, new BigIntegerConverter());
+        typeConverterMap.put(Long.class, new LongConverter());
+        typeConverterMap.put(Double.class, new DoubleConverter());
+        typeConverterMap.put(Float.class, new FloatConverter());
+        typeConverterMap.put(IRI.class, new UriRefConverter());
+    }
+
+    final private static IRI xsdDouble =xsd("double");
+    final private static IRI xsdFloat =xsd("float");
+    final private static IRI xsdAnyURI =xsd("anyURI");
+
+    final private static IRI xsd(String name) {
+       return new IRI(XSD+name);
+    }
+
+    private static interface TypeConverter<T> {
+        Literal createLiteral(T value);
+        T createObject(Literal literal);        
+    }
+
+    private static class  ByteArrayConverter implements TypeConverter<byte[]> {
+
+        private static final IRI base64Uri =xsd("base64Binary");
+
+        @Override
+        public Literal createLiteral(byte[] value) {
+            return new TypedLiteralImpl(Base64.encode((byte[]) value), base64Uri);
+        }
+
+        @Override
+        public byte[] createObject(Literal literal) {
+            if (!literal.getDataType().equals(base64Uri)) {
+                throw new InvalidLiteralTypeException(byteArrayType, literal.getDataType());
+            }
+            return (byte[]) Base64.decode(literal.getLexicalForm());
+        }
+
+        
+    }
+    private static class DateConverter implements TypeConverter<Date> {
+
+        private static final IRI dateTimeUri =xsd("dateTime");
+        private static final DateFormat DATE_FORMAT = new W3CDateFormat();
+
+        @Override
+        public Literal createLiteral(Date value) {
+            return new TypedLiteralImpl(DATE_FORMAT.format(value), dateTimeUri);
+        }
+
+        @Override
+        public Date createObject(Literal literal) {
+            if (!literal.getDataType().equals(dateTimeUri)) {
+                throw new InvalidLiteralTypeException(Date.class, literal.getDataType());
+            }
+            try {
+                return DATE_FORMAT.parse(literal.getLexicalForm());
+            } catch (ParseException ex) {
+                throw new RuntimeException("Exception parsing literal as date", ex);
+            }
+        }
+
+
+    }
+
+    private static class BooleanConverter implements TypeConverter<Boolean> {
+
+        private static final IRI booleanUri =xsd("boolean");
+        public static final TypedLiteralImpl TRUE = new TypedLiteralImpl("true", booleanUri);
+        public static final TypedLiteralImpl FALSE = new TypedLiteralImpl("false", booleanUri);
+
+        @Override
+        public Literal createLiteral(Boolean value) {
+            if (value) return TRUE;
+            else return FALSE;
+        }
+
+        @Override
+        public Boolean createObject(Literal literal) {
+            if (literal == TRUE) return true;
+            else if (literal == FALSE) return false;
+            else if (!literal.getDataType().equals(booleanUri)) {
+                throw new InvalidLiteralTypeException(Boolean.class, literal.getDataType());
+            }
+            return Boolean.valueOf(literal.getLexicalForm());
+        }
+    }
+
+    private static class StringConverter implements TypeConverter<String> {
+
+        private static final IRI stringUri =xsd("string");
+
+        @Override
+        public Literal createLiteral(String value) {
+            return new TypedLiteralImpl(value, stringUri);
+        }
+
+        @Override
+        public String createObject(Literal literal) {
+            if (!literal.getDataType().equals(stringUri)) {
+                throw new InvalidLiteralTypeException(String.class, literal.getDataType());
+            }
+            return literal.getLexicalForm();
+        }
+    }
+
+    private static class IntegerConverter implements TypeConverter<Integer> {
+
+
+        @Override
+        public Literal createLiteral(Integer value) {
+            return new TypedLiteralImpl(value.toString(), xsdInt);
+        }
+
+        @Override
+        public Integer createObject(Literal literal) {
+            if (!decimalTypes.contains(literal.getDataType())) {
+                throw new InvalidLiteralTypeException(Integer.class, literal.getDataType());
+            }
+            return new Integer(literal.getLexicalForm());
+        }
+    }
+
+    private static class LongConverter implements TypeConverter<Long> {
+
+        
+
+        @Override
+        public Literal createLiteral(Long value) {
+            return new TypedLiteralImpl(value.toString(), xsdLong);
+        }
+
+        @Override
+        public Long createObject(Literal literal) {
+            if (!decimalTypes.contains(literal.getDataType())) {
+                throw new InvalidLiteralTypeException(Long.class, literal.getDataType());
+            }
+            return new Long(literal.getLexicalForm());
+        }
+    }
+
+
+    private static class FloatConverter implements TypeConverter<Float> {
+
+        @Override
+        public Literal createLiteral(Float value) {
+            return new TypedLiteralImpl(value.toString(), xsdFloat);
+        }
+
+        @Override
+        public Float createObject(Literal literal) {
+            if (!literal.getDataType().equals(xsdFloat)) {
+                throw new InvalidLiteralTypeException(Float.class, literal.getDataType());
+            }
+            return Float.valueOf(literal.getLexicalForm());
+        }
+    }
+    
+    private static class DoubleConverter implements TypeConverter<Double> {
+
+
+
+        @Override
+        public Literal createLiteral(Double value) {
+            return new TypedLiteralImpl(value.toString(), xsdDouble);
+        }
+
+        @Override
+        public Double createObject(Literal literal) {
+            if (!literal.getDataType().equals(xsdDouble)) {
+                throw new InvalidLiteralTypeException(Double.class, literal.getDataType());
+            }
+            return new Double(literal.getLexicalForm());
+        }
+    }
+
+    private static class BigIntegerConverter implements TypeConverter<BigInteger> {
+
+
+
+        @Override
+        public Literal createLiteral(BigInteger value) {
+            return new TypedLiteralImpl(value.toString(), xsdInteger);
+        }
+
+        @Override
+        public BigInteger createObject(Literal literal) {
+            if (!literal.getDataType().equals(xsdInteger)) {
+                throw new InvalidLiteralTypeException(Double.class, literal.getDataType());
+            }
+            return new BigInteger(literal.getLexicalForm());
+        }
+    }
+    
+    private static class UriRefConverter implements TypeConverter<IRI> {
+
+
+
+        @Override
+        public Literal createLiteral(IRI value) {
+            return new TypedLiteralImpl(value.getUnicodeString(), xsdAnyURI);
+        }
+
+        @Override
+        public IRI createObject(Literal literal) {
+            if (!literal.getDataType().equals(xsdAnyURI)) {
+                throw new InvalidLiteralTypeException(IRI.class, literal.getDataType());
+            }
+            return new IRI(literal.getLexicalForm());
+        }
+    }
+
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Literal createTypedLiteral(Object value) throws NoConvertorException {
+        TypeConverter converter = getConverterFor(value.getClass());
+        return converter.createLiteral(value);
+    }
+
+    
+    
+    @Override
+    public <T> T createObject(Class<T> type, Literal literal)
+            throws NoConvertorException, InvalidLiteralTypeException {
+        final TypeConverter<T> converter = getConverterFor(type);
+        return converter.createObject(literal);
+        
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> TypeConverter<T> getConverterFor(Class<T> type) throws NoConvertorException {
+        TypeConverter<T> convertor = (TypeConverter<T>) typeConverterMap.get(type);
+        if (convertor != null) {
+            return convertor;
+        }
+        for (Map.Entry<Class<?>, TypeConverter<?>> converterEntry : typeConverterMap.entrySet()) {
+            if (type.isAssignableFrom(converterEntry.getKey())) {
+                return (TypeConverter<T>) converterEntry.getValue();
+            }
+        }
+        throw new NoConvertorException(type);
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/TypedLiteralImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/TypedLiteralImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/TypedLiteralImpl.java
new file mode 100644
index 0000000..8b029d2
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/literal/TypedLiteralImpl.java
@@ -0,0 +1,79 @@
+/*
+ * 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.api.impl.literal;
+
+import java.io.Serializable;
+
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.Language;
+
+/**
+ *
+ * @author reto
+ */
+public class TypedLiteralImpl extends AbstractLiteral implements  Serializable {
+    private String lexicalForm;
+    private IRI dataType;
+    private int hashCode;
+
+    /**
+     * @param lexicalForm 
+     * @param dataType 
+     */
+    public TypedLiteralImpl(String lexicalForm, IRI dataType) {
+        this.lexicalForm = lexicalForm;
+        this.dataType = dataType;
+        this.hashCode = super.hashCode();
+    }
+    
+    public IRI getDataType() {
+        return dataType;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.LiteralNode#getLexicalForm()
+     */
+    @Override
+    public String getLexicalForm() {
+        return lexicalForm;
+    }
+
+    @Override
+    public int hashCode() {
+        return hashCode;
+    }
+    
+
+    @Override
+    public String toString() {
+        StringBuffer result = new StringBuffer();
+        result.append('\"');
+        result.append(getLexicalForm());
+        result.append('\"');
+        result.append("^^");
+        result.append(getDataType());
+        return result.toString();
+    }
+
+    @Override
+    public Language getLanguage() {
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/package-info.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/package-info.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/package-info.java
index 6a35ba4..80652e5 100644
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/package-info.java
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/package-info.java
@@ -15,7 +15,4 @@
  * limitations under the License.
  */
 
-/**
- * Common RDF API Implementation utilities.
- */
 package org.apache.clerezza.api.impl;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleGraph.java
deleted file mode 100644
index 7220532..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleGraph.java
+++ /dev/null
@@ -1,219 +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.api.impl.simple;
-
-import org.apache.clerezza.api.IRI;
-import org.apache.clerezza.api.impl.AbstractGraph;
-
-import java.lang.ref.SoftReference;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.ConcurrentModificationException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.clerezza.api.BlankNodeOrIRI;
-import org.apache.clerezza.api.ImmutableGraph;
-import org.apache.clerezza.api.RDFTerm;
-import org.apache.clerezza.api.Triple;
-
-/**
- * For now this is a minimalistic implementation, without any indexes or other
- * optimizations.
- *
- * @author reto
- */
-public class SimpleGraph extends AbstractGraph {
-
-    final Set<Triple> triples;
-
-    private boolean checkConcurrency = false;
-
-    class SimpleIterator implements Iterator<Triple> {
-
-        private Iterator<Triple> listIter;
-        private boolean isValid = true;
-
-        public SimpleIterator(Iterator<Triple> listIter) {
-            this.listIter = listIter;
-        }
-        private Triple currentNext;
-
-        @Override
-        public boolean hasNext() {
-            checkValidity();
-            return listIter.hasNext();
-        }
-
-        @Override
-        public Triple next() {
-            checkValidity();
-            currentNext = listIter.next();
-            return currentNext;
-        }        
-
-        @Override
-        public void remove() {
-            checkValidity();
-            listIter.remove();
-            triples.remove(currentNext);            
-            invalidateIterators(this);            
-        }
-
-        private void checkValidity() throws ConcurrentModificationException {
-            if (checkConcurrency && !isValid) {
-                throw new ConcurrentModificationException();
-            }
-        }
-
-        private void invalidate() {
-            isValid = false;
-        }
-    }    
-    
-    private final Set<SoftReference<SimpleIterator>> iterators =
-            Collections.synchronizedSet(new HashSet<SoftReference<SimpleIterator>>());
-    
-    /**
-     * Creates an empty SimpleGraph
-     */
-    public SimpleGraph() {
-        triples = Collections.synchronizedSet(new HashSet<Triple>());
-    }
-
-    /**
-     * Creates a SimpleGraph using the passed iterator, the iterator 
-     * is consumed before the constructor returns
-     * 
-     * @param iterator
-     */
-    public SimpleGraph(Iterator<Triple> iterator) {
-        triples = new HashSet<Triple>();
-        while (iterator.hasNext()) {
-            Triple triple = iterator.next();
-            triples.add(triple);
-        }
-    }
-
-    /**
-     * Creates a SimpleGraph for the specified set of triples, 
-     * subsequent modification of baseSet do affect the created instance.
-     * 
-     * @param baseSet
-     */
-    public SimpleGraph(Set<Triple> baseSet) {
-        this.triples = baseSet;
-    }
-
-    /**
-     * Creates a SimpleGraph for the specified collection of triples,
-     * subsequent modification of baseSet do not affect the created instance.
-     *
-     * @param baseSet
-     */
-    public SimpleGraph(Collection<Triple> baseCollection) {
-        this.triples = new HashSet<Triple>(baseCollection);
-    }
-
-    @Override
-    public int performSize() {
-        return triples.size();
-    }
-
-    @Override
-    public Iterator<Triple> performFilter(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
-        final List<Triple> tripleList = new ArrayList<Triple>();
-        synchronized (triples) {
-            Iterator<Triple> baseIter = triples.iterator();
-            while (baseIter.hasNext()) {
-                Triple triple = baseIter.next();
-                if ((subject != null)
-                        && (!triple.getSubject().equals(subject))) {
-                    continue;
-                }
-                if ((predicate != null)
-                        && (!triple.getPredicate().equals(predicate))) {
-                    continue;
-                }
-                if ((object != null)
-                        && (!triple.getObject().equals(object))) {
-                    continue;
-                }
-                tripleList.add(triple);
-            }
-
-            final Iterator<Triple> listIter = tripleList.iterator();
-            SimpleIterator resultIter = new SimpleIterator(listIter);
-            if (checkConcurrency) {
-                iterators.add(new SoftReference<SimpleIterator>(resultIter));
-            }
-            return resultIter;
-        }
-    }
-
-
-    @Override
-    public boolean performAdd(Triple e) {
-        boolean modified = triples.add(e);
-        if (modified) {
-            invalidateIterators(null);
-        }
-        return modified;
-    }
-    
-    private void invalidateIterators(SimpleIterator caller) {
-        if (!checkConcurrency) {
-            return;
-        }
-        Set<SoftReference> oldReferences = new HashSet<SoftReference>();
-        synchronized(iterators) {
-            for (SoftReference<SimpleGraph.SimpleIterator> softReference : iterators) {
-                SimpleIterator simpleIterator = softReference.get();
-                if (simpleIterator == null) {
-                    oldReferences.add(softReference);
-                    continue;
-                }
-                if (simpleIterator != caller) {
-                    simpleIterator.invalidate();
-                }
-            }
-        }
-        iterators.removeAll(oldReferences);
-    }
-
-    /**
-     * Specifies whether or not to throw <code>ConcurrentModificationException</code>s,
-     * if this simple triple collection is modified concurrently. Concurrency
-     * check is set to false by default.
-     *
-     * @param bool Specifies whether or not to check concurrent modifications.
-     */
-    public void setCheckConcurrency(boolean bool) {
-        checkConcurrency = bool;
-    }
-    
-    
-    @Override
-    public ImmutableGraph getImmutableGraph() {
-        return new SimpleImmutableGraph(this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleImmutableGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleImmutableGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleImmutableGraph.java
deleted file mode 100644
index d48fe5c..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleImmutableGraph.java
+++ /dev/null
@@ -1,80 +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.api.impl.simple;
-
-import org.apache.clerezza.api.impl.AbstractImmutableGraph;
-
-import java.util.Iterator;
-
-import org.apache.clerezza.api.BlankNodeOrIRI;
-import org.apache.clerezza.api.RDFTerm;
-import org.apache.clerezza.api.Triple;
-import org.apache.clerezza.api.Graph;
-import org.apache.clerezza.api.IRI;
-
-/**
- *
- * @author reto
- */
-public class SimpleImmutableGraph extends AbstractImmutableGraph {
-
-    private Graph graph;
-    
-    /**
-     * Creates a ImmutableGraph with the triples in Graph
-     * 
-     * @param Graph the collection of triples this ImmutableGraph shall consist of
-     */
-    public SimpleImmutableGraph(Graph Graph) {
-        this.graph = new SimpleGraph(Graph.iterator());
-    }
-
-    /**
-     * Creates a ImmutableGraph with the triples in Graph.
-     *
-     * This construction allows to specify if the Graph might change
-     * in future. If GraphWillNeverChange is set to true it will
-     * assume that the collection never changes, in this case the collection
-     * isn't copied making things more efficient.
-     *
-     * @param Graph the collection of triples this ImmutableGraph shall consist of
-     * @param GraphWillNeverChange true if the caller promises Graph will never change
-     */
-    public SimpleImmutableGraph(Graph Graph, boolean GraphWillNeverChange) {
-        if (!GraphWillNeverChange) {
-            this.graph = new SimpleGraph(Graph.iterator());
-        } else {
-            this.graph = Graph;
-        }
-    }
-    
-    public SimpleImmutableGraph(Iterator<Triple> tripleIter) {
-        this.graph = new SimpleGraph(tripleIter);
-    }
-
-    @Override
-    public int performSize() {
-        return graph.size();
-    }
-
-    @Override
-    public Iterator<Triple> performFilter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-        return graph.filter(subject, predicate, object);
-    }
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleMGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleMGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleMGraph.java
deleted file mode 100644
index da961c2..0000000
--- a/api.impl/src/main/java/org/apache/clerezza/api/impl/simple/SimpleMGraph.java
+++ /dev/null
@@ -1,56 +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.api.impl.simple;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.clerezza.api.Graph;
-import org.apache.clerezza.api.Triple;
-
-/**
- *
- * @deprecated Use SimpleGraph
- * @author reto
- */
-@Deprecated
-public class SimpleMGraph extends SimpleGraph implements Graph {
-
-    /**
-     * Creates an empty SimpleMGraph
-     */
-    public SimpleMGraph() {
-    }
-
-    public SimpleMGraph(Set<Triple> baseSet) {
-        super(baseSet);
-    }
-
-    public SimpleMGraph(Collection<Triple> baseCollection) {
-        super(baseCollection);
-    }
-
-    public SimpleMGraph(Iterator<Triple> iterator) {
-        super(iterator);
-    }
-
-}
-
-    
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/util/Base64.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/util/Base64.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/util/Base64.java
new file mode 100644
index 0000000..28607eb
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/util/Base64.java
@@ -0,0 +1,120 @@
+/*
+ * Taken from the book:
+ * Jonathan Knudsen, "Java Cryptography", O'Reilly Media, Inc., 1998
+ */
+package org.apache.clerezza.api.impl.util;
+/*
+ *
+ * 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.
+ *
+*/
+
+
+public class Base64 {
+
+    public static String encode(byte[] raw) {
+        StringBuffer encoded = new StringBuffer();
+        for (int i = 0; i < raw.length; i += 3) {
+            encoded.append(encodeBlock(raw, i));
+        }
+        return encoded.toString();
+    }
+
+    protected static char[] encodeBlock(byte[] raw, int offset) {
+        int block = 0;
+        int slack = raw.length - offset - 1;
+        int end = (slack >= 2) ? 2 : slack;
+        for (int i = 0; i <= end; i++) {
+            byte b = raw[offset + i];
+            int neuter = (b < 0) ? b + 256 : b;
+            block += neuter << (8 * (2 - i));
+        }
+        char[] base64 = new char[4];
+        for (int i = 0; i < 4; i++) {
+            int sixbit = (block >>> (6 * (3 - i))) & 0x3f;
+            base64[i] = getChar(sixbit);
+        }
+        if (slack < 1) {
+            base64[2] = '=';
+        }
+        if (slack < 2) {
+            base64[3] = '=';
+        }
+        return base64;
+    }
+
+    protected static char getChar(int sixBit) {
+        if (sixBit >= 0 && sixBit <= 25) {
+            return (char) ('A' + sixBit);
+        }
+        if (sixBit >= 26 && sixBit <= 51) {
+            return (char) ('a' + (sixBit - 26));
+        }
+        if (sixBit >= 52 && sixBit <= 61) {
+            return (char) ('0' + (sixBit - 52));
+        }
+        if (sixBit == 62) {
+            return '+';
+        }
+        if (sixBit == 63) {
+            return '/';
+        }
+        return '?';
+    }
+
+    public static byte[] decode(String base64) {
+        int pad = 0;
+        for (int i = base64.length() - 1; base64.charAt(i) == '='; i--) {
+            pad++;
+        }
+        int length = base64.length() * 6 / 8 - pad;
+        byte[] raw = new byte[length];
+        int rawIndex = 0;
+        for (int i = 0; i < base64.length(); i += 4) {
+            int block = (getValue(base64.charAt(i)) << 18) + (getValue(base64.charAt(i + 1)) << 12) + (getValue(base64.charAt(i + 2)) << 6) + (getValue(base64.charAt(i + 3)));
+            for (int j = 0; j < 3 && rawIndex + j < raw.length; j++) {
+                raw[rawIndex + j] = (byte) ((block >> (8 * (2 - j))) & 0xff);
+            }
+            rawIndex += 3;
+        }
+        return raw;
+    }
+
+    protected static int getValue(char c) {
+        if (c >= 'A' && c <= 'Z') {
+            return c - 'A';
+        }
+        if (c >= 'a' && c <= 'z') {
+            return c - 'a' + 26;
+        }
+        if (c >= '0' && c <= '9') {
+            return c - '0' + 52;
+        }
+        if (c == '+') {
+            return 62;
+        }
+        if (c == '/') {
+            return 63;
+        }
+        if (c == '=') {
+            return 0;
+        }
+        return -1;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/829e5fa5/api.impl/src/main/java/org/apache/clerezza/api/impl/util/W3CDateFormat.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/util/W3CDateFormat.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/util/W3CDateFormat.java
new file mode 100644
index 0000000..a337064
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/util/W3CDateFormat.java
@@ -0,0 +1,196 @@
+//taken from GVS MillisDateFormat.java, modified to support different precision
+
+/*
+ (c) Copyright 2005, 2006, Hewlett-Packard Development Company, LP
+ [See end of file]
+ $Id: W3CDateFormat.java,v 1.6 2007/05/07 18:45:22 rebach Exp $
+ */
+package org.apache.clerezza.api.impl.util;
+/*
+ *
+ * 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.text.DateFormat;
+import java.text.FieldPosition;
+import java.text.ParsePosition;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
+
+/**
+ * @author reto implements http://www.w3.org/TR/NOTE-datetime with the
+ *         limitation that it expects exactly a three digits decimal fraction of
+ *         seconds. if a time zone designator other than 'Z' is present it must
+ *         contain a column
+ */
+public class W3CDateFormat extends DateFormat {
+    /**
+     * An instance of this class
+     */
+    public static final W3CDateFormat instance = new W3CDateFormat();
+
+    private static final SimpleDateFormat dateFormatWithMillis = new SimpleDateFormat(
+            "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+    private static final SimpleDateFormat dateFormatNoMillis = new SimpleDateFormat(
+            "yyyy-MM-dd'T'HH:mm:ssZ");
+
+    private static final long serialVersionUID = 3258407344076372025L;
+
+    private static final TimeZone utcTZ = new SimpleTimeZone(0, "UTC");
+
+    static {
+        dateFormatWithMillis.setTimeZone(utcTZ);
+        dateFormatNoMillis.setTimeZone(utcTZ);
+    }
+
+    @Override
+    public void setTimeZone(TimeZone zone) {
+        super.setTimeZone(zone);
+    }
+
+
+    /**
+     * @see java.text.DateFormat#format(java.util.Date, java.lang.StringBuffer,
+     *      java.text.FieldPosition)
+     */
+    @Override
+    public StringBuffer format(Date date, StringBuffer toAppendTo,
+            FieldPosition fieldPosition) {
+
+        final DateFormat dateFormat = (date.getTime() % 1000) == 0 ?
+            dateFormatNoMillis : dateFormatWithMillis;
+        String string = dateFormat.format(date);
+        if (string.endsWith("0000")) {
+            StringBuffer result = new StringBuffer(string.substring(0, string.length()-5));
+            result.append('Z');
+            return result;
+        } else {
+            StringBuffer result = new StringBuffer(string);
+            result.insert(string.length() - 2, ':');
+            return result;
+        }
+    }
+
+    /**
+     * @see java.text.DateFormat#parse(java.lang.String,
+     *      java.text.ParsePosition)
+     */
+    public Date parse(String dateString, ParsePosition parsePos) {
+
+        int position = parsePos.getIndex();
+
+        int y1 = dateString.charAt(position++) - '0';
+        int y2 = dateString.charAt(position++) - '0';
+        int y3 = dateString.charAt(position++) - '0';
+        int y4 = dateString.charAt(position++) - '0';
+        int year = 1000 * y1 + 100 * y2 + 10 * y3 + y4;
+        position++; // skip '-'
+        int m1 = dateString.charAt(position++) - '0';
+        int m2 = dateString.charAt(position++) - '0';
+        int month = 10 * m1 + m2;
+        position++; // skip '-'
+        int d1 = dateString.charAt(position++) - '0';
+        int d2 = dateString.charAt(position++) - '0';
+        int day = 10 * d1 + d2;
+        position++; // skip 'T'
+        int h1 = dateString.charAt(position++) - '0';
+        int h2 = dateString.charAt(position++) - '0';
+        int hour = 10 * h1 + h2;
+        position++; // skip ':'
+        int min1 = dateString.charAt(position++) - '0';
+        int min2 = dateString.charAt(position++) - '0';
+        int minutes = 10 * min1 + min2;
+        position++; // skip ':'
+        int s1 = dateString.charAt(position++) - '0';
+        int s2 = dateString.charAt(position++) - '0';
+        int secs = 10 * s1 + s2;
+        Calendar resultCalendar = new GregorianCalendar(year, month - 1, day,
+                hour, minutes, secs);
+        resultCalendar.setTimeZone(utcTZ);
+        char afterSecChar = dateString.charAt(position++);
+        int msecs = 0;
+        char tzd1;
+        if (afterSecChar == '.') {
+            int startPos = position;
+            //read decimal part, this is till there is a 'Z', a '+' or a '-'
+            char nextChar = dateString.charAt(position++);
+            while ((nextChar != 'Z') && (nextChar != '-') && (nextChar != '+')) {
+                msecs += (nextChar - '0')*Math.pow(10, 3+startPos-position);
+                nextChar = dateString.charAt(position++);
+            }
+            tzd1 = nextChar;
+        } else {
+            tzd1 = afterSecChar;
+        }
+        long timeInMillis = resultCalendar.getTimeInMillis() + msecs;
+        if (tzd1 != 'Z') {
+            int htz1 = dateString.charAt(position++) - '0';
+            int htz2 = dateString.charAt(position++) - '0';
+            int hourtz = 10 * htz1 + htz2;
+            position++; // skip ':'
+            int mintz1 = dateString.charAt(position++) - '0';
+            int mintz2 = dateString.charAt(position++) - '0';
+            int minutestz = 10 * mintz1 + mintz2;
+            int offSetInMillis = (hourtz * 60 + minutestz) * 60000;
+            if (tzd1 == '+') {
+                timeInMillis -= offSetInMillis;
+            } else {
+                timeInMillis += offSetInMillis;
+            }
+        }
+        parsePos.setIndex(position);
+        return new Date(timeInMillis);
+
+    }
+}
+
+/*
+ * (c) Copyright 2005, 2006 Hewlett-Packard Development Company, LP All rights
+ * reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+