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:30 UTC

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

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