You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2012/08/07 13:07:28 UTC

svn commit: r1370175 [1/2] - in /incubator/stanbol/trunk/ontologymanager: ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/ ontonet/src/main/java/org/ap...

Author: alexdma
Date: Tue Aug  7 11:07:27 2012
New Revision: 1370175

URL: http://svn.apache.org/viewvc?rev=1370175&view=rev
Log:
* Public keys are now of type OWLOntologyID, String is deprecated and so are related methods (though they will still be around for a progressive phase-out) (STANBOL-305)
* Added unit tests for ontology reconciliation, incl. anonymous and versioned ontologies (STANBOL-426, STANBOL-524)
* Added unifying type OriginOrInputSource in order to avoid excessive method overloads. I want this to be VERY temporary, and go back to using just OntologyInputSource once I allow input source that skip creating ontology objects (what origins are now).
* Delegated more methods to the OntologyNetworkMultiplexer (XXX this is very likely going to become an OSGi component).
* First stub of stored ontology HTML page with only metalevel information instead of the Manchester Syntax.
* Fixed a bug that caused scopes to still use the old namespaces when exporting core space imports (STANBOL-681)

Added:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OriginOrInputSource.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyReconciliation.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/id/
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/id/named-1.owl
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/id/named-2.owl
    incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/util/OntologyStatsResource.java
Removed:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologySpaceEvent.java
Modified:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManager.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologyInputSource.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/Origin.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyNetworkMultiplexer.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyProvider.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScopeFactory.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologySpaceFactory.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionEvent.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/MGraphNetworkMultiplexer.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/OntologyScopeImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestClerezzaProvider.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyNetworkPersistence.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/session/TestSessions.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java
    incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java
    incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java
    incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/static/style/ontonet.css
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource/index.ftl
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource/ontology.ftl
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource/webview.ftl

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManager.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManager.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManager.java Tue Aug  7 11:07:27 2012
@@ -18,7 +18,7 @@ package org.apache.stanbol.ontologymanag
 
 import java.io.File;
 
-import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OriginOrInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScopeFactory;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpaceFactory;
@@ -31,7 +31,7 @@ import org.apache.stanbol.ontologymanage
  * <br>
  * Note that since this object is both a {@link ScopeRegistry} and an {@link OntologyScopeFactory}, the call
  * to {@link ScopeRegistry#registerScope(OntologyScope)} or its overloads after
- * {@link OntologyScopeFactory#createOntologyScope(String, OntologyInputSource...)} is unnecessary, as the
+ * {@link OntologyScopeFactory#createOntologyScope(String, OriginOrInputSource...)} is unnecessary, as the
  * ONManager automatically registers newly created scopes.
  * 
  * @author alexdma, anuzzolese

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java Tue Aug  7 11:07:27 2012
@@ -19,9 +19,8 @@ package org.apache.stanbol.ontologymanag
 import java.util.Set;
 
 import org.apache.stanbol.ontologymanager.ontonet.api.NamedArtifact;
-import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSourceHandler;
-import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OriginOrInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
 import org.semanticweb.owlapi.model.IRI;
 import org.semanticweb.owlapi.model.OWLOntologyID;
@@ -48,20 +47,7 @@ public interface OntologyCollector exten
      *            the ontology to be added
      * @return the key that can be used for accessing the stored ontology directly
      */
-    String addOntology(OntologyInputSource<?> ontologySource);
-
-    /**
-     * Tells this ontology collector to manage the ontology referenced by <tt>origin</tt>. This method will
-     * try to <i>avoid</i> processing the ontology content whenever possible. For the example, if
-     * <tt>origin</tt> is an {@link Origin} that wraps an {@link OWLOntologyID}, it will assumed the wrapperd
-     * reference to be a public key for an already stored ontology.
-     * 
-     * TODO make this method return the public key as an {@link OWLOntologyID}.
-     * 
-     * @param origin
-     *            the origin of the ontology to be added.
-     */
-    void addOntology(Origin<?> origin);
+    OWLOntologyID addOntology(OriginOrInputSource ontology);
 
     /**
      * Returns the ontologies managed by this ontology space. This is a shortcut method for iterating

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java Tue Aug  7 11:07:27 2012
@@ -34,6 +34,17 @@ public abstract class AbstractGenericInp
 
     protected O rootOntology = null;
 
+    @Override
+    public OntologyInputSource<?> asInputSource() {
+        return this;
+    }
+
+    @Override
+    public Origin<?> asOrigin() {
+        throw new UnsupportedOperationException("Unsupported conversion from " + getClass() + " to "
+                                                + Origin.class);
+    }
+
     /**
      * This method is used to remind developers to bind a physical reference to the
      * {@link OntologyInputSource} if intending to do so.
@@ -88,6 +99,16 @@ public abstract class AbstractGenericInp
     }
 
     @Override
+    public boolean isInputSource() {
+        return true;
+    }
+
+    @Override
+    public boolean isOrigin() {
+        return false;
+    }
+
+    @Override
     public abstract String toString();
 
 }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologyInputSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologyInputSource.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologyInputSource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologyInputSource.java Tue Aug  7 11:07:27 2012
@@ -36,7 +36,7 @@ import java.util.Set;
  * @author alexdma
  * 
  */
-public interface OntologyInputSource<O> {
+public interface OntologyInputSource<O> extends OriginOrInputSource {
 
     /**
      * Gets the ontology network resulting from the transitive closure of import statements on the root

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/Origin.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/Origin.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/Origin.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/Origin.java Tue Aug  7 11:07:27 2012
@@ -35,7 +35,7 @@ import org.semanticweb.owlapi.model.OWLO
  * @param <R>
  *            the resource reference.
  */
-public class Origin<R> {
+public class Origin<R> implements OriginOrInputSource {
 
     /**
      * Creates a new Origin for a resource that can be retrieved by dereferencing the given IRI as an URL.
@@ -90,6 +90,17 @@ public class Origin<R> {
     }
 
     @Override
+    public OntologyInputSource<?> asInputSource() {
+        throw new UnsupportedOperationException("Unsupported conversion from " + getClass() + " to "
+                                                + OntologyInputSource.class);
+    }
+
+    @Override
+    public Origin<?> asOrigin() {
+        return this;
+    }
+
+    @Override
     public boolean equals(Object arg0) {
         if (arg0 == null) return false;
         if (!(arg0 instanceof Origin<?>)) return false;
@@ -106,6 +117,16 @@ public class Origin<R> {
     }
 
     @Override
+    public boolean isInputSource() {
+        return false;
+    }
+
+    @Override
+    public boolean isOrigin() {
+        return true;
+    }
+
+    @Override
     public String toString() {
         return "Origin(" + ref.toString() + ")";
     }

Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OriginOrInputSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OriginOrInputSource.java?rev=1370175&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OriginOrInputSource.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OriginOrInputSource.java Tue Aug  7 11:07:27 2012
@@ -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.stanbol.ontologymanager.ontonet.api.io;
+
+/**
+ * Placeholder type for unifying {@link Origin} and {@link OntologyInputSource} in order to use them in
+ * functions with varargs.
+ * 
+ * @author alexdma
+ * 
+ */
+public interface OriginOrInputSource {
+
+    Origin<?> asOrigin();
+
+    OntologyInputSource<?> asInputSource();
+
+    boolean isInputSource();
+
+    boolean isOrigin();
+
+}

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyNetworkMultiplexer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyNetworkMultiplexer.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyNetworkMultiplexer.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyNetworkMultiplexer.java Tue Aug  7 11:07:27 2012
@@ -18,7 +18,9 @@ package org.apache.stanbol.ontologymanag
 
 import java.util.Set;
 
+import org.apache.stanbol.ontologymanager.ontonet.api.collector.OntologyCollector;
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.OntologyCollectorListener;
+import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionListener;
 import org.semanticweb.owlapi.model.OWLOntologyID;
 
 /**
@@ -28,7 +30,25 @@ import org.semanticweb.owlapi.model.OWLO
  * @author alexdma.
  * 
  */
-public interface OntologyNetworkMultiplexer extends OntologyCollectorListener {
+public interface OntologyNetworkMultiplexer extends OntologyCollectorListener, SessionListener {
+
+    /**
+     * Not just the IDs because spaces and sessions can share identifiers.
+     * 
+     * @param publicKey
+     * @return
+     */
+    Set<OntologyCollector> getHandles(OWLOntologyID publicKey);
+
+    /**
+     * An utility method that computes the public key of an ontology given a canonical string form. The result
+     * also depends on the stored ontologies, hence the inclusion of this non-static method with this class.
+     * 
+     * @param stringForm
+     *            the string form of the public key.
+     * @return the public key.
+     */
+    OWLOntologyID getPublicKey(String stringForm);
 
     /**
      * Returns the public keys of all the stored ontologies it is aware of.
@@ -47,14 +67,4 @@ public interface OntologyNetworkMultiple
      */
     int getSize(OWLOntologyID publicKey);
 
-    /**
-     * An utility method that computes the public key of an ontology given a canonical string form. The result
-     * also depends on the stored ontologies, hence the inclusion of this non-static method with this class.
-     * 
-     * @param stringForm
-     *            the string form of the public key.
-     * @return the public key.
-     */
-    OWLOntologyID getPublicKey(String stringForm);
-
 }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyProvider.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyProvider.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyProvider.java Tue Aug  7 11:07:27 2012
@@ -64,8 +64,6 @@ public interface OntologyProvider<S> {
      */
     public String RESOLVE_IMPORTS = "org.apache.stanbol.ontologymanager.ontonet.resolveImports";
 
-    String getGraphPrefix();
-
     /**
      * Gets the policy adopted by this provider whenever an import statement is found in an ontology <i>that
      * has already been loaded</i> (e.g. when exporting it). It does <b>not</b> influence how the system
@@ -79,8 +77,10 @@ public interface OntologyProvider<S> {
      * Gets a string that can be used to directly access the ontology whose logical identifier is
      * <tt>ontologyIRI</tt>.
      * 
-     * @deprecated
-     * 
+     * @deprecated public keys are now of type {@link OWLOntologyID} and should match ontologyIri, or
+     *             derivative versioned IDs, whenever possible.
+     * @see #listVersions(IRI)
+     * @see #listAliases(OWLOntologyID)
      * @param ontologyIri
      *            the logical identifier of the ontology.
      * @return the public key (note that it might be different from the graph name).
@@ -91,7 +91,11 @@ public interface OntologyProvider<S> {
      * Gets a string that can be used to directly access the ontology whose logical identifier is
      * <tt>ontologyId</tt>.
      * 
-     * @deprecated
+     * @deprecated public keys are now of type {@link OWLOntologyID} and should match ontologyId. To obtain
+     *             alternate public keys (aliases) or versioned public keys, see
+     *             {@link #listAliases(OWLOntologyID)} and {@link #listVersions(IRI)} respectively.
+     * @see #listVersions(IRI)
+     * @see #listAliases(OWLOntologyID)
      * 
      * @param ontologyId
      *            the logical identifier of the ontology.
@@ -115,13 +119,23 @@ public interface OntologyProvider<S> {
     @Deprecated
     OntologyNetworkConfiguration getOntologyNetworkConfiguration();
 
+    /**
+     * XXX This method is temporary until {@link OntologyNetworkMultiplexer} becomes an OSGi component.
+     * 
+     * @return
+     */
     OntologyNetworkMultiplexer getOntologyNetworkDescriptor();
 
     /**
      * Gets the key of the ontology with the supplied ontology ID. Note that both ontoloeyIRI and versionIRI
      * (if present) must match, otherwise it will return null.
      * 
-     * @deprecated
+     * @deprecated public keys are now of type {@link OWLOntologyID} and should match ontologyId. To obtain
+     *             alternate public keys (aliases) or versioned public keys, see
+     *             {@link #listAliases(OWLOntologyID)} and {@link #listVersions(IRI)} respectively.
+     * @see #listVersions(IRI)
+     * @see #listAliases(OWLOntologyID)
+     * 
      * @param ontologyId
      * @return
      */
@@ -130,6 +144,8 @@ public interface OntologyProvider<S> {
     /**
      * Gets the set of all the strings that can be used to access the ontologies stored by this provider.
      * 
+     * @deprecated Please use {@link #listOntologies()} instead.
+     * 
      * @return the ontology key set.
      */
     Set<OWLOntologyID> getPublicKeys();
@@ -251,15 +267,43 @@ public interface OntologyProvider<S> {
      * Implementations are typically faster than calling {@link #getStoredOntology(IRI, Class)} and checking
      * if the returned value is not null.
      * 
-     * @param id
+     * @param publicKey
      *            the ontology id. If there is both an ontology IRI and a version IRI, both must match the
      *            ontology provider's records in order to return true. Otherwise, it will return true iff
      *            <i>any</i> match with the ontology IIR is found, no matter its version IRI.
      * @return true iff an ontology with the supplied id is in the provider's store.
      */
-    boolean hasOntology(OWLOntologyID id);
+    boolean hasOntology(OWLOntologyID publicKey);
+
+    /**
+     * Returns all the alternate public keys of the ontology identified by the supplied public key. These
+     * could include, for example, the physical URLs they were, or can be, retrieved from. The supplied public
+     * key is not included in the returned set, and it needs not be the primary key. It can be an alias
+     * itself, in whih case the primary key will be included in the results.
+     * 
+     * @param publicKey
+     *            the public key of the ontology. It could be an alias itself.
+     * @return the matching versions of stored ontologies.
+     */
+    Set<OWLOntologyID> listAliases(OWLOntologyID publicKey);
+
+    /**
+     * Returns the public keys of all the ontologies stored by this provider. Only primary keys are returned:
+     * aliases are not included.
+     * 
+     * @return all the ontology public keys.
+     */
+    Set<OWLOntologyID> listOntologies();
 
-    public Set<OWLOntologyID> listOntologies();
+    /**
+     * Returns all the public keys of the ontologies whose ontology IRI matches the one supplied,a nd which
+     * differ by version IRI. Only primary keys are returned: aliases are not included.
+     * 
+     * @param ontologyIri
+     *            the ontology IRI to match
+     * @return the matching versions of stored ontologies.
+     */
+    Set<OWLOntologyID> listVersions(IRI ontologyIri);
 
     /**
      * Retrieves an ontology by reading its content from a data stream and stores it using the storage system
@@ -285,8 +329,10 @@ public interface OntologyProvider<S> {
      * @throws UnsupportedFormatException
      *             if no parsers are able to parse the supplied format (or the actual file format).
      */
-    String loadInStore(InputStream data, String formatIdentifier, boolean force, Origin<?>... references) throws IOException,
-                                                                                                         UnsupportedFormatException;
+    OWLOntologyID loadInStore(InputStream data,
+                              String formatIdentifier,
+                              boolean force,
+                              Origin<?>... references) throws IOException, UnsupportedFormatException;
 
     /**
      * Retrieves an ontology physically located at <code>location</code> (unless mapped otherwise by the
@@ -312,7 +358,7 @@ public interface OntologyProvider<S> {
      * @throws UnsupportedFormatException
      *             if no parsers are able to parse the supplied format (or the actual file format).
      */
-    String loadInStore(IRI location, String formatIdentifier, boolean force, Origin<?>... references) throws IOException;
+    OWLOntologyID loadInStore(IRI location, String formatIdentifier, boolean force, Origin<?>... references) throws IOException;
 
     /**
      * Stores an ontology that has already been loaded into an object. If the object is of a non-native yet
@@ -327,7 +373,7 @@ public interface OntologyProvider<S> {
      *            set on offline mode, this method will fail.
      * @return
      */
-    String loadInStore(Object ontology, boolean force, Origin<?>... references);
+    OWLOntologyID loadInStore(Object ontology, boolean force, Origin<?>... references);
 
     /**
      * Removes the ontology identified by the supplied public key.
@@ -338,8 +384,6 @@ public interface OntologyProvider<S> {
      */
     boolean removeOntology(OWLOntologyID publicKey);
 
-    void setGraphPrefix(String prefix);
-
     /**
      * Sets the policy adopted by this provider whenever an import statement is found in an ontology <i>that
      * has already been loaded</i> (e.g. when exporting it). It does <b>not</b> influence how the system
@@ -351,15 +395,19 @@ public interface OntologyProvider<S> {
     void setImportManagementPolicy(ImportManagementPolicy policy);
 
     /**
-     * Will not be checked by dereferencing
-     * 
-     * If the key does not exist in the provider, or if locator is already bound to a different key, an
-     * {@link IllegalArgumentException} will be thrown.
-     * 
+     * Tells this ontology provider that a stored ontology whose public key is <tt>publicKey</tt> can be (or
+     * was) retrieved by dereferencing <tt>locator</tt>. If <tt>publicKey</tt>does not exist in the provider,
+     * or if <tt>locator</tt> is already bound to an incompatible key, an {@link IllegalArgumentException}
+     * will be thrown.
      * 
      * @param locator
-     * @param key
+     *            a physical location for this ontology.
+     * @param publicKey
+     *            the public key of the stored ontology.
      */
+    void setLocatorMapping(IRI locator, OWLOntologyID publicKey);
+
+    @Deprecated
     void setLocatorMapping(IRI locator, String key);
 
 }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScopeFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScopeFactory.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScopeFactory.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScopeFactory.java Tue Aug  7 11:07:27 2012
@@ -17,8 +17,7 @@
 package org.apache.stanbol.ontologymanager.ontonet.api.scope;
 
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.DuplicateIDException;
-import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
-import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OriginOrInputSource;
 
 /**
  * An ontology scope factory is responsible for the creation of new ontology scopes from supplied ontology
@@ -45,9 +44,5 @@ public interface OntologyScopeFactory ex
      *             if an ontology scope with the given identifier is already <i>registered</i>. The exception
      *             is not thrown if another scope with the same ID has been created but not registered.
      */
-    OntologyScope createOntologyScope(String scopeID, OntologyInputSource<?>... coreSources) throws DuplicateIDException;
-
-    OntologyScope createOntologyScope(String scopeID, Origin<?>... coreOrigins) throws DuplicateIDException;
-    
-    OntologyScope createOntologyScope(String scopeID)throws DuplicateIDException;
+    OntologyScope createOntologyScope(String scopeID, OriginOrInputSource... coreOntologies) throws DuplicateIDException;
 }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologySpaceFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologySpaceFactory.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologySpaceFactory.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologySpaceFactory.java Tue Aug  7 11:07:27 2012
@@ -17,8 +17,7 @@
 package org.apache.stanbol.ontologymanager.ontonet.api.scope;
 
 import org.apache.stanbol.ontologymanager.ontonet.api.NamedArtifact;
-import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
-import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OriginOrInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpace.SpaceType;
 
 /**
@@ -32,8 +31,6 @@ import org.apache.stanbol.ontologymanage
  */
 public interface OntologySpaceFactory extends NamedArtifact {
 
-    CoreOntologySpace createCoreOntologySpace(String scopeId);
-
     /**
      * Creates and sets up a default core ontology space. Equivalent to calling
      * <code>createOntologySpace(IRI, SpaceTypes.CORE, OntologyInputSource...)</code>.
@@ -45,11 +42,7 @@ public interface OntologySpaceFactory ex
      *            the sources of the optional ontologies to be immediately loaded upon space creation.
      * @return the generated ontology space.
      */
-    CoreOntologySpace createCoreOntologySpace(String scopeId, OntologyInputSource<?>... coreSources);
-
-    CoreOntologySpace createCoreOntologySpace(String scopeId, Origin<?>... coreOrigins);
-
-    CustomOntologySpace createCustomOntologySpace(String scopeId);
+    CoreOntologySpace createCoreOntologySpace(String scopeId, OriginOrInputSource... coreOntologies);
 
     /**
      * Creates and sets up a default custom ontology space. Equivalent to calling
@@ -62,11 +55,7 @@ public interface OntologySpaceFactory ex
      *            the sources of the optional ontologies to be immediately loaded upon space creation.
      * @return the generated ontology space.
      */
-    CustomOntologySpace createCustomOntologySpace(String scopeId, OntologyInputSource<?>... customSources);
-
-    CustomOntologySpace createCustomOntologySpace(String scopeId, Origin<?>... customOrigins);
-
-    OntologySpace createOntologySpace(String scopeId, SpaceType type);
+    CustomOntologySpace createCustomOntologySpace(String scopeId, OriginOrInputSource... customOntologies);
 
     /**
      * Creates an ontology space of the specified type.
@@ -80,10 +69,6 @@ public interface OntologySpaceFactory ex
      *            the sources of the optional ontologies to be immediately loaded upon space creation.
      * @return the generated ontology space.
      */
-    OntologySpace createOntologySpace(String scopeId,
-                                      SpaceType type,
-                                      OntologyInputSource<?>... ontologySources);
-
-    OntologySpace createOntologySpace(String scopeId, SpaceType type, Origin<?>... origins);
+    OntologySpace createOntologySpace(String scopeId, SpaceType type, OriginOrInputSource... ontologySources);
 
 }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionEvent.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionEvent.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionEvent.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionEvent.java Tue Aug  7 11:07:27 2012
@@ -46,9 +46,11 @@ public class SessionEvent {
      * @param session
      *            the KReS session affected by this event
      */
-    public SessionEvent(Session session, OperationType operationType) throws Exception {
-        if (operationType == null) throw new Exception("No operation type specified for this session event.");
-        if (session == null) throw new Exception("No KReS session specified for this session event.");
+    public SessionEvent(Session session, OperationType operationType) {
+        if (operationType == null) throw new IllegalArgumentException(
+                "No operation type specified for this session event.");
+        if (session == null) throw new IllegalArgumentException(
+                "No session specified for this session event.");
         this.operationType = operationType;
         this.affectedSession = session;
     }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java Tue Aug  7 11:07:27 2012
@@ -46,6 +46,7 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.ontonet.api.io.BlankOntologySource;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OriginOrInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologyIRISource;
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.CustomOntologySpace;
@@ -405,34 +406,13 @@ public class ONManagerImpl extends Scope
     }
 
     @Override
-    public OntologyScope createOntologyScope(String scopeID) throws DuplicateIDException {
+    public OntologyScope createOntologyScope(String scopeID, OriginOrInputSource... coreOntologies) throws DuplicateIDException {
         if (this.containsScope(scopeID)) throw new DuplicateIDException(scopeID,
                 "Scope registry already contains ontology scope with ID " + scopeID);
         IRI prefix = IRI.create(getOntologyNetworkNamespace() + scopeRegistryId + "/");
         // Scope constructor also creates core and custom spaces
-        OntologyScope scope = new OntologyScopeImpl(scopeID, prefix, getOntologySpaceFactory());
-        configureScope(scope);
-        return scope;
-    }
-
-    @Override
-    public OntologyScope createOntologyScope(String scopeID, OntologyInputSource<?>... coreSources) throws DuplicateIDException {
-        if (this.containsScope(scopeID)) throw new DuplicateIDException(scopeID,
-                "Scope registry already contains ontology scope with ID " + scopeID);
-        IRI prefix = IRI.create(getOntologyNetworkNamespace() + scopeRegistryId + "/");
-        // Scope constructor also creates core and custom spaces
-        OntologyScope scope = new OntologyScopeImpl(scopeID, prefix, getOntologySpaceFactory(), coreSources);
-        configureScope(scope);
-        return scope;
-    }
-
-    @Override
-    public OntologyScope createOntologyScope(String scopeID, Origin<?>... coreOrigins) throws DuplicateIDException {
-        if (this.containsScope(scopeID)) throw new DuplicateIDException(scopeID,
-                "Scope registry already contains ontology scope with ID " + scopeID);
-        IRI prefix = IRI.create(getOntologyNetworkNamespace() + scopeRegistryId + "/");
-        // Scope constructor also creates core and custom spaces
-        OntologyScope scope = new OntologyScopeImpl(scopeID, prefix, getOntologySpaceFactory(), coreOrigins);
+        OntologyScope scope = new OntologyScopeImpl(scopeID, prefix, getOntologySpaceFactory(),
+                coreOntologies);
         configureScope(scope);
         return scope;
     }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java Tue Aug  7 11:07:27 2012
@@ -25,7 +25,6 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
-import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.apache.clerezza.rdf.core.Graph;
@@ -40,7 +39,6 @@ import org.apache.clerezza.rdf.core.impl
 import org.apache.clerezza.rdf.core.impl.TripleImpl;
 import org.apache.clerezza.rdf.ontologies.OWL;
 import org.apache.clerezza.rdf.ontologies.RDF;
-import org.apache.stanbol.commons.owl.util.OWLUtils;
 import org.apache.stanbol.commons.owl.util.URIUtils;
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.Lockable;
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.MissingOntologyException;
@@ -52,6 +50,7 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSourceHandler;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OriginOrInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologyIRISource;
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OWLExportable;
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
@@ -128,7 +127,16 @@ public abstract class AbstractOntologyCo
     }
 
     @Override
-    public synchronized String addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException {
+    public OWLOntologyID addOntology(OriginOrInputSource ontology) {
+        if (ontology.isInputSource()) return addOntology(ontology.asInputSource());
+        if (ontology.isOrigin()) {
+            addOntology(ontology.asOrigin());
+            return null;
+        }
+        return null;
+    }
+
+    private synchronized OWLOntologyID addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException {
 
         long before = System.currentTimeMillis();
 
@@ -142,7 +150,7 @@ public abstract class AbstractOntologyCo
         Object o = ontologySource.getRootOntology();
 
         // Now for the actual storage. We pass the ontology object directly.
-        String key = null;
+        OWLOntologyID key = null;
         // // FIXME restore ownership management, but maybe not by directly setting the versionIRI
         // if (ontologyProvider.hasOntology(id.getOntologyIRI())) if (o instanceof MGraph)
         // claimOwnership((MGraph) o);
@@ -156,46 +164,10 @@ public abstract class AbstractOntologyCo
          * Actually we are not interested in knowing the key here (ontology collectors are not concerned with
          * them), but knowing it is non-null and non-empty indicates the operation was successful.
          */
-        if (key != null && !key.isEmpty()) {
-            if (ontologySource.hasOrigin() && ontologySource.getOrigin().getReference() instanceof IRI) ontologyProvider
-                    .setLocatorMapping((IRI) ontologySource.getOrigin().getReference(), key);
-
-            /*
-             * Used for mappings.
-             */
-            OWLOntologyID id;
-            if (o instanceof TripleCollection) {
-                id = OWLUtils.guessOntologyIdentifier((TripleCollection) o);
-            } else if (o instanceof OWLOntology) {
-                id = OWLUtils.guessOntologyIdentifier((OWLOntology) o);
-            } else throw new UnsupportedOperationException(
-                    "This ontology collector implementation cannot handle " + o.getClass().getCanonicalName()
-                            + " objects.");
-
-            // Null id? use the origin trick
-            if (id == null) {
-
-                if (ontologySource.hasOrigin()) {
-                    Origin<?> origin = ontologySource.getOrigin();
-                    Object reff = origin.getReference();
-                    if (reff instanceof IRI) id = new OWLOntologyID((IRI) reff); // No version IRI here
-                    else if (reff instanceof UriRef) id = new OWLOntologyID(IRI.create(((UriRef) reff)
-                            .getUnicodeString()));
-                    else {
-                        log.warn("Entering deprecated code block. Should not happen.");
-                        log.warn("Key : {}", key);
-                        id = ontologyProvider.getOntologyId(key);
-                    }
-
-                } else {
-                    log.warn("Entering deprecated code block. Should not happen.");
-                    log.warn("Key : {}", key);
-                    id = ontologyProvider.getOntologyId(key);
-                }
-            }
+        if (key != null) {
 
             // add to index
-            managedOntologies.add(id);
+            managedOntologies.add(key);
             // // Always add sanitized version
             // managedOntologies.add(id.getVersionIRI() == null ? new OWLOntologyID(URIUtils.sanitizeID(id
             // .getOntologyIRI())) : new OWLOntologyID(URIUtils.sanitizeID(id.getOntologyIRI()),
@@ -203,13 +175,12 @@ public abstract class AbstractOntologyCo
             // Note that imported ontologies are not considered as managed! TODO should we change this?
             log.debug("Add ontology completed in {} ms.", (System.currentTimeMillis() - before));
             // fire the event
-            fireOntologyAdded(id);
+            fireOntologyAdded(key);
         }
         return key;
     }
 
-    @Override
-    public synchronized void addOntology(Origin<?> origin) throws UnmodifiableOntologyCollectorException {
+    private synchronized void addOntology(Origin<?> origin) throws UnmodifiableOntologyCollectorException {
         if (origin == null) throw new IllegalArgumentException("Origin cannot be null.");
         Object ref = origin.getReference();
         if (ref instanceof IRI) try {

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java Tue Aug  7 11:07:27 2012
@@ -96,7 +96,6 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.ScopeEventListener;
 import org.apache.stanbol.ontologymanager.ontonet.api.session.Session;
 import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionEvent;
-import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionEvent.OperationType;
 import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionListener;
 import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
 import org.osgi.service.component.ComponentContext;
@@ -167,6 +166,15 @@ public class ClerezzaOntologyProvider im
             }
         }
 
+        void addAlias(OWLOntologyID subject, OWLOntologyID object) {
+            // For now add both owl:sameAs statements
+            UriRef suben = buildResource(subject), oben = buildResource(object);
+            synchronized (graph) {
+                graph.add(new TripleImpl(suben, OWL.sameAs, oben));
+                graph.add(new TripleImpl(oben, OWL.sameAs, suben));
+            }
+        }
+
         void addMapping(OWLOntologyID ontologyReference, UriRef graphName) {
             if (ontologyReference == null || ontologyReference.isAnonymous()) throw new IllegalArgumentException(
                     "An anonymous ontology cannot be mapped. A non-anonymous ontology ID must be forged in these cases.");
@@ -179,10 +187,12 @@ public class ClerezzaOntologyProvider im
             tHasOiri = new TripleImpl(entry, HAS_ONTOLOGY_IRI, new UriRef(ontologyIRI.toString()));
             if (versionIri != null) tHasViri = new TripleImpl(entry, HAS_VERSION_IRI, new UriRef(
                     versionIri.toString()));
-            graph.add(tType);
-            graph.add(tMaps);
-            if (tHasViri != null) graph.add(tHasViri);
-            graph.add(tHasOiri);
+            synchronized (graph) {
+                graph.add(tType);
+                graph.add(tMaps);
+                if (tHasViri != null) graph.add(tHasViri);
+                graph.add(tHasOiri);
+            }
         }
 
         OWLOntologyID buildPublicKey(final UriRef resource) {
@@ -212,31 +222,95 @@ public class ClerezzaOntologyProvider im
          * @param ontologyReference
          * @return
          */
-        UriRef buildResource(OWLOntologyID ontologyReference) {
+        UriRef buildResource(OWLOntologyID publicKey) {
+
+            // // The UriRef is of the form ontologyIRI[:::versionIRI] (TODO use something less conventional?)
+            // IRI ontologyIRI = publicKey.getOntologyIRI(), versionIri = publicKey
+            // .getVersionIRI();
+            // UriRef entry = new UriRef(URIUtils.sanitize(ontologyIRI).toString()
+            // + ((versionIri == null) ? "" : (":::" + URIUtils.sanitize(versionIri)
+            // .toString())));
+            // System.out.println("Returning "+entry);
+            // return entry;
+
+            TripleCollection meta = getMetaGraph(TripleCollection.class);
+            if (publicKey == null) throw new IllegalArgumentException(
+                    "Cannot build a UriRef resource on a null public key!");
             // The UriRef is of the form ontologyIRI[:::versionIRI] (TODO use something less conventional?)
-            IRI ontologyIRI = ontologyReference.getOntologyIRI(), versionIri = ontologyReference
-                    .getVersionIRI();
-            UriRef entry = new UriRef(URIUtils.sanitize(ontologyIRI).toString()
-                                      + ((versionIri == null) ? "" : (":::" + URIUtils.sanitize(versionIri)
-                                              .toString())));
-            return entry;
-        }
+            // XXX should versionIRI also include the version IRI set by owners? Currently not
 
-        UriRef getMapping(OWLOntologyID ontologyReference) {
-            UriRef res = buildResource(ontologyReference);
-            // Logical mappings first.
-            Iterator<Triple> it = graph.filter(res, new UriRef(Vocabulary.MAPS_TO_GRAPH), null);
-            while (it.hasNext()) {
-                Resource obj = it.next().getObject();
-                if (obj instanceof UriRef) return (UriRef) obj;
+            // Remember not to sanitize logical identifiers.
+            IRI ontologyIri = publicKey.getOntologyIRI(), versionIri = publicKey.getVersionIRI();
+            if (ontologyIri == null) throw new IllegalArgumentException(
+                    "Cannot build a UriRef resource on an anonymous public key!");
+
+            log.debug("Searching for a meta graph entry for public key:");
+            log.debug(" -- {}", publicKey);
+            UriRef match = null;
+            for (Iterator<Triple> it = meta
+                    .filter(null, HAS_ONTOLOGY_IRI, new UriRef(ontologyIri.toString())); it.hasNext();) {
+                Resource subj = it.next().getSubject();
+                log.debug(" -- Ontology IRI match found. Scanning");
+                log.debug(" -- Resource : {}", subj);
+                if (!(subj instanceof UriRef)) {
+                    log.debug(" ---- (uncomparable: skipping...)");
+                    continue;
+                }
+                if (versionIri != null) {
+                    // Must find matching versionIRI
+                    if (meta.contains(new TripleImpl((UriRef) subj, HAS_VERSION_IRI, new UriRef(versionIri
+                            .toString())))) {
+                        log.debug(" ---- Version IRI match!");
+                        match = (UriRef) subj;
+                        break; // Found
+                    } else {
+                        log.debug(" ---- Expected version IRI match not found.");
+                        continue; // There could be another with the right versionIRI.
+                    }
+
+                } else {
+                    // Must find unversioned resource
+                    if (meta.filter((UriRef) subj, HAS_VERSION_IRI, null).hasNext()) {
+                        log.debug(" ---- Unexpected version IRI found. Skipping.");
+                        continue;
+                    } else {
+                        log.debug(" ---- Unversioned match!");
+                        match = (UriRef) subj;
+                        break; // Found
+                    }
+                }
             }
-            Literal litloc = LiteralFactory.getInstance().createTypedLiteral(
-                new UriRef(res.getUnicodeString()));
-            // Logical mappings failed, try physical mappings.
-            it = graph.filter(null, new UriRef(Vocabulary.RETRIEVED_FROM), litloc);
-            while (it.hasNext()) {
-                Resource obj = it.next().getSubject();
-                if (obj instanceof UriRef) return (UriRef) obj;
+            log.debug("Matching UriRef in graph : {}", match);
+            if (match == null) {
+                return new UriRef(OntologyUtils.encode(publicKey));
+            } else {
+                return match;
+            }
+        }
+
+        UriRef getMapping(OWLOntologyID reference) {
+            // UriRef res = buildResource(reference);
+
+            Set<UriRef> aliases = new HashSet<UriRef>();
+            aliases.add(buildResource(reference));
+            for (OWLOntologyID alias : listAliases(reference))
+                aliases.add(buildResource(alias));
+
+            for (UriRef alias : aliases) {
+                // Logical mappings first.
+                Iterator<Triple> it = graph.filter(alias, new UriRef(Vocabulary.MAPS_TO_GRAPH), null);
+                while (it.hasNext()) {
+                    Resource obj = it.next().getObject();
+                    if (obj instanceof UriRef) return (UriRef) obj;
+                }
+                Literal litloc = LiteralFactory.getInstance().createTypedLiteral(
+                    new UriRef(alias.getUnicodeString()));
+                // Logical mappings failed, try physical mappings.
+                it = graph.filter(null, new UriRef(Vocabulary.RETRIEVED_FROM), litloc);
+                while (it.hasNext()) {
+                    Resource obj = it.next().getSubject();
+                    if (obj instanceof UriRef) return (UriRef) obj;
+                }
             }
             return null;
         }
@@ -246,21 +320,39 @@ public class ClerezzaOntologyProvider im
             Iterator<Triple> it = graph.filter(null, new UriRef(Vocabulary.MAPS_TO_GRAPH), graphName);
             while (it.hasNext()) {
                 Resource obj = it.next().getSubject();
-                if (obj instanceof UriRef) return new OWLOntologyID(IRI.create(((UriRef) obj)
-                        .getUnicodeString()));
+                if (obj instanceof UriRef) return buildPublicKey((UriRef) obj);
             }
             Literal litloc = LiteralFactory.getInstance().createTypedLiteral(
                 new UriRef(graphName.getUnicodeString()));
             // Logical mappings failed, try physical mappings.
             it = graph.filter(null, new UriRef(Vocabulary.RETRIEVED_FROM), litloc);
             while (it.hasNext()) {
-                Resource obj = it.next().getSubject();
-                if (obj instanceof UriRef) return new OWLOntologyID(IRI.create(((UriRef) obj)
-                        .getUnicodeString()));
+                Resource subj = it.next().getSubject();
+                if (subj instanceof UriRef) return buildPublicKey((UriRef) subj);
+
             }
             return null;
         }
 
+        Set<OWLOntologyID> getVersions(IRI ontologyIri) {
+            if (ontologyIri == null) throw new IllegalArgumentException("Cannot get versions for a null IRI.");
+            Set<OWLOntologyID> keys = new HashSet<OWLOntologyID>();
+            UriRef iri = new UriRef(ontologyIri.toString());
+            // Exclude aliases.
+            for (Iterator<Triple> it = graph.filter(null, HAS_ONTOLOGY_IRI, iri); it.hasNext();) {
+                Resource sub = it.next().getSubject();
+                if (sub instanceof UriRef) keys.add(buildPublicKey((UriRef) sub));
+            }
+            // Also check for physical locations
+            Literal litloc = LiteralFactory.getInstance().createTypedLiteral(iri);
+            for (Iterator<Triple> it = graph.filter(null, new UriRef(Vocabulary.RETRIEVED_FROM), litloc); it
+                    .hasNext();) {
+                Resource sub = it.next().getSubject();
+                if (sub instanceof UriRef) keys.add(buildPublicKey((UriRef) sub));
+            }
+            return keys;
+        }
+
         void mapLocator(IRI locator, UriRef graphName) {
             if (graphName == null) throw new IllegalArgumentException("A null graph name is not allowed.");
             // Null locator is a legal argument, will remove all locator mappings from the supplied graph
@@ -494,7 +586,7 @@ public class ClerezzaOntologyProvider im
 
         // Get the graph and explore its imports
         TripleCollection graph // store.getTriples(importing);
-        = getStoredOntology(getPublicKey(importing), MGraph.class, false);
+        = getStoredOntology(/* getPublicKey */(importing), MGraph.class, false);
         Iterator<Triple> it = graph.filter(null, RDF.type, OWL.Ontology);
         if (!it.hasNext()) return;
         Iterator<Triple> it2 = graph.filter(it.next().getSubject(), OWL.imports, null);
@@ -517,8 +609,21 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
-    public String getGraphPrefix() {
-        return prefix;
+    public Set<OWLOntologyID> listAliases(OWLOntologyID publicKey) {
+        if (publicKey == null || publicKey.getOntologyIRI() == null) throw new IllegalArgumentException(
+                "Cannot locate aliases for null or anonymous public keys.");
+        Set<OWLOntologyID> aliases = new HashSet<OWLOntologyID>();
+        TripleCollection meta = getMetaGraph(TripleCollection.class);
+        UriRef ont = keymap.buildResource(publicKey);
+        for (Iterator<Triple> it = meta.filter(ont, OWL.sameAs, null); it.hasNext();) {
+            Resource r = it.next().getObject();
+            if (r instanceof UriRef) aliases.add(keymap.buildPublicKey((UriRef) r));
+        }
+        for (Iterator<Triple> it = meta.filter(null, OWL.sameAs, ont); it.hasNext();) {
+            Resource r = it.next().getSubject();
+            if (r instanceof UriRef) aliases.add(keymap.buildPublicKey((UriRef) r));
+        }
+        return aliases;
     }
 
     @Override
@@ -539,23 +644,20 @@ public class ClerezzaOntologyProvider im
         return new UriRef(_NS_STANBOL_INTERNAL + OntologyScope.shortName + "/" + scopeId);
     }
 
-    private UriRef getIRIforSession(Session session) {
-        // Use the Stanbol-internal namespace, so that the whole configuration can be ported.
-        return new UriRef(_NS_STANBOL_INTERNAL + Session.shortName + "/" + session.getID());
-    }
-
     private UriRef getIRIforSpace(OntologySpace space) {
         // Use the Stanbol-internal namespace, so that the whole configuration can be ported.
         return new UriRef(_NS_STANBOL_INTERNAL + OntologySpace.shortName + "/" + space.getID());
     }
 
     @Override
+    @Deprecated
     public String getKey(IRI ontologyIri) {
         // ontologyIri = URIUtils.sanitizeID(ontologyIri);
         return getPublicKey(new OWLOntologyID(ontologyIri));
     }
 
     @Override
+    @Deprecated
     public String getKey(OWLOntologyID ontologyId) {
         return getPublicKey(ontologyId);
     }
@@ -569,6 +671,7 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
+    @Deprecated
     public OWLOntologyID getOntologyId(String storageKey) {
         return keymap.getReverseMapping(new UriRef(storageKey));
     }
@@ -741,6 +844,7 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
+    @Deprecated
     public String getPublicKey(OWLOntologyID ontologyId) {
         UriRef ur = keymap.getMapping(ontologyId);
         log.debug("key for {} is {}", ontologyId, ur);
@@ -748,6 +852,7 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
+    @Deprecated
     public Set<OWLOntologyID> getPublicKeys() {
         return descriptor.getPublicKeys();
     }
@@ -758,12 +863,14 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
+    @Deprecated
     public <O> O getStoredOntology(IRI reference, Class<O> returnType) {
         // reference = URIUtils.sanitizeID(reference);
         return getStoredOntology(new OWLOntologyID(reference), returnType);
     }
 
     @Override
+    @Deprecated
     public <O> O getStoredOntology(IRI reference, Class<O> returnType, boolean merge) {
         // reference = URIUtils.sanitizeID(reference);
         return getStoredOntology(new OWLOntologyID(reference), returnType, merge);
@@ -776,7 +883,8 @@ public class ClerezzaOntologyProvider im
 
     @Override
     public <O> O getStoredOntology(OWLOntologyID reference, Class<O> returnType, boolean merge) {
-        String key = getKey(reference);
+        String key = /* getKey(reference); */
+        keymap.getMapping(reference).getUnicodeString();
         if (key == null || key.isEmpty()) {
             log.warn("No key found for IRI {}", reference);
             return null;
@@ -784,6 +892,7 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
+    @Deprecated
     public <O> O getStoredOntology(String key, Class<O> returnType) {
         return getStoredOntology(key, returnType, false);
     }
@@ -793,6 +902,7 @@ public class ClerezzaOntologyProvider im
      */
     @SuppressWarnings("unchecked")
     @Override
+    @Deprecated
     public <O> O getStoredOntology(String identifier, Class<O> returnType, boolean forceMerge) {
         if (identifier == null || identifier.isEmpty()) throw new IllegalArgumentException(
                 "Identifier cannot be null or empty.");
@@ -836,6 +946,7 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
+    @Deprecated
     public boolean hasOntology(IRI ontologyIri) {
         // ontologyIri = URIUtils.sanitizeID(ontologyIri);
         return hasOntology(new OWLOntologyID(ontologyIri));
@@ -864,10 +975,10 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
-    public String loadInStore(InputStream data,
-                              String formatIdentifier,
-                              boolean force,
-                              Origin<?>... references) {
+    public OWLOntologyID loadInStore(InputStream data,
+                                     String formatIdentifier,
+                                     boolean force,
+                                     Origin<?>... references) {
         if (data == null) throw new IllegalArgumentException("No data to load ontologies from.");
         if (formatIdentifier == null || formatIdentifier.trim().isEmpty()) throw new IllegalArgumentException(
                 "A non-null, non-blank format identifier is required for parsing the data stream.");
@@ -880,10 +991,10 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
-    public String loadInStore(final IRI ontologyIri,
-                              String formatIdentifier,
-                              boolean force,
-                              Origin<?>... references) throws IOException {
+    public OWLOntologyID loadInStore(final IRI ontologyIri,
+                                     String formatIdentifier,
+                                     boolean force,
+                                     Origin<?>... references) throws IOException {
         log.debug("Loading {}", ontologyIri);
         if (ontologyIri == null) throw new IllegalArgumentException("Ontology IRI cannot be null.");
 
@@ -925,7 +1036,7 @@ public class ClerezzaOntologyProvider im
                      * formats again. Also, we provide the ontologyIRI as the preferred key, since we already
                      * know it.
                      */
-                    String key = loadInStore(is, currentFormat, force, Origin.create(ontologyIri));
+                    OWLOntologyID key = loadInStore(is, currentFormat, force, Origin.create(ontologyIri));
                     // If parsing failed, an exception will be thrown before getting here, so no risk.
                     // if (key != null && !key.isEmpty()) setLocatorMapping(ontologyIri, key);
                     return key;
@@ -945,7 +1056,7 @@ public class ClerezzaOntologyProvider im
     }
 
     @Override
-    public String loadInStore(Object ontology, final boolean force, Origin<?>... origins) {
+    public OWLOntologyID loadInStore(Object ontology, final boolean force, Origin<?>... origins) {
 
         if (ontology == null) throw new IllegalArgumentException("No ontology supplied.");
         long before = System.currentTimeMillis();
@@ -961,13 +1072,11 @@ public class ClerezzaOntologyProvider im
                 "This ontology provider can only accept objects assignable to " + TripleCollection.class
                         + " or " + OWLOntology.class);
 
-        // Force is ignored for the content, but the imports?
+        // XXX Force is ignored for the content, but the imports?
 
-        // FIXME Profile this method. Are we getting rid of rdfData after adding its triples?
-
-        String iri = null;
-        OWLOntologyID realId = OWLUtils.guessOntologyIdentifier(rdfData); // used for public and storage key.
-        if (realId == null) {
+        // TODO Profile this method. Are we getting rid of rdfData after adding its triples?
+        OWLOntologyID publicKey = OWLUtils.guessOntologyIdentifier(rdfData);
+        if (publicKey == null) {
             IRI z;
             if (origins.length > 0 && origins[0] != null) {
                 Object reff = origins[0].getReference();
@@ -975,29 +1084,9 @@ public class ClerezzaOntologyProvider im
                 else if (reff instanceof UriRef) z = IRI.create(((UriRef) reff).getUnicodeString());
                 else z = IRI.create(getClass().getCanonicalName() + "-time:" + System.currentTimeMillis());
             } else z = IRI.create(getClass().getCanonicalName() + "-time:" + System.currentTimeMillis());
-            realId = new OWLOntologyID(z);
+            publicKey = new OWLOntologyID(z);
         }
 
-        if (realId != null) {
-            if (realId.getOntologyIRI() != null) iri = realId.getOntologyIRI().toString();
-            if (realId.getVersionIRI() != null) iri += ":::" + realId.getVersionIRI().toString();
-        }
-
-        // s will become the graph name
-        String s = (iri.startsWith(prefix + "::")) ? "" : (prefix + "::");
-        // while (s.endsWith("#"))
-        // s = s.substring(0, s.length() - 1);
-        // ontologyIri = URIUtils.sanitizeID(ontologyIri);
-        s += iri;
-        // if (s.endsWith("#")) s = s.substring(0, s.length() - 1);
-        /*
-         * rdfData should be an in-memory graph, so we shouldn't have a problem creating one with the
-         * TcProvider and adding triples there, so that the in-memory graph is garbage-collected.
-         * 
-         * TODO this occupies twice as much space, which should not be necessary if the provider is the same
-         * as the one used by the input source.
-         */
-
         // Check if it is possible to avoid reloading the ontology content from its source.
         boolean mustLoad = true;
         if (!force) {
@@ -1028,6 +1117,16 @@ public class ClerezzaOntologyProvider im
 
         // The policy here is to avoid copying the triples from a graph already in the store.
         // FIXME not a good policy for graphs that change
+        String iri = null;
+        if (publicKey.getOntologyIRI() != null) iri = publicKey.getOntologyIRI().toString();
+        if (publicKey.getVersionIRI() != null) iri += ":::" + publicKey.getVersionIRI().toString();
+        // s will become the graph name
+        String s = (iri.startsWith(prefix + "::")) ? "" : (prefix + "::");
+        // while (s.endsWith("#"))
+        // s = s.substring(0, s.length() - 1);
+        // ontologyIri = URIUtils.sanitizeID(ontologyIri);
+        s += iri;
+        // if (s.endsWith("#")) s = s.substring(0, s.length() - 1);
         UriRef uriref;
         if (mustLoad) {
             uriref = new UriRef(URIUtils.sanitize(s));
@@ -1054,10 +1153,10 @@ public class ClerezzaOntologyProvider im
         // Now do the mappings
         String mappedIds = "";
         // Discard unconventional ontology IDs with only the version IRI
-        if (realId != null && realId.getOntologyIRI() != null) {
+        if (publicKey != null && publicKey.getOntologyIRI() != null) {
             // Versioned or not, the real ID mapping is always added
-            keymap.setMapping(realId, uriref);
-            mappedIds += realId;
+            keymap.setMapping(publicKey, uriref);
+            mappedIds += publicKey;
             /*
              * TODO not sure I should always map the unversioned ID as a key too?
              */
@@ -1069,7 +1168,7 @@ public class ClerezzaOntologyProvider im
             // mappedIds += realId;
             // }
             // }
-            Triple t = new TripleImpl(keymap.buildResource(realId),
+            Triple t = new TripleImpl(keymap.buildResource(publicKey),
                     org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.SIZE_IN_TRIPLES, LiteralFactory
                             .getInstance().createTypedLiteral(Integer.valueOf(rdfData.size())));
             getMetaGraph(MGraph.class).add(t);
@@ -1084,21 +1183,18 @@ public class ClerezzaOntologyProvider im
          * TODO how safe is this if there was a mapping earlier?
          */
 
-        if (origins.length > 0 && origins[0] != null) {
-            Object reff = origins[0].getReference();
-            if (reff instanceof IRI) {
-                OWLOntologyID unv = new OWLOntologyID((IRI) reff);
-                if (!unv.equals(realId)) {
-                    keymap.setMapping(unv, uriref);
-                    mappedIds += " , " + unv;
-                    getMetaGraph(MGraph.class).add(
-                        new TripleImpl(keymap.buildResource(unv),
-                                org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.SIZE_IN_TRIPLES,
-                                LiteralFactory.getInstance().createTypedLiteral(
-                                    Integer.valueOf(rdfData.size()))));
+        for (Origin<?> origin : origins)
+            if (origin != null) {
+                Object reff = origin.getReference();
+                if (reff instanceof IRI) {
+                    OWLOntologyID physical = new OWLOntologyID((IRI) reff);
+                    if (!physical.equals(publicKey)) {
+                        // keymap.setMapping(physical, uriref);
+                        keymap.addAlias(publicKey, physical);
+                        mappedIds += " , " + physical;
+                    }
                 }
             }
-        }
 
         // Do this AFTER registering the ontology, otherwise import cycles will cause infinite loops.
         if (resolveImports) {
@@ -1135,16 +1231,21 @@ public class ClerezzaOntologyProvider im
         log.debug("--- {}", mappedIds);
         if (graph != null) log.debug("--- ({} triples)", graph.size());
         log.debug("--- stored with key");
-        log.debug("--- {}", URIUtils.sanitize(s));
+        log.debug("--- {}", publicKey);
+        // log.debug("--- {}", URIUtils.sanitize(s));
         log.debug("Time: {} ms", (System.currentTimeMillis() - before));
-        return URIUtils.sanitize(s);
-
+        // return URIUtils.sanitize(s);
+        return publicKey;
     }
 
     @Override
     public boolean removeOntology(OWLOntologyID publicKey) {
         throw new UnsupportedOperationException(
                 "Not implemented yet. Must implement dependency management support first.");
+        /*
+         * The operation will have to: (1) refuse to comply if there is at least one handle; (2) clear all
+         * aliases; (3) delete the graph;
+         */
     }
 
     @Override
@@ -1152,14 +1253,8 @@ public class ClerezzaOntologyProvider im
 
     @Override
     public void scopeAppended(Session session, String scopeId) {
-        final TripleCollection meta = store.getTriples(new UriRef(metaGraphId));
-        final UriRef sessionur = getIRIforSession(session), scopeur = getIRIforScope(scopeId);
-        if (sessionur == null || scopeur == null) throw new IllegalArgumentException(
-                "UriRefs for scope and session cannot be null.");
-        if (meta instanceof MGraph) synchronized (meta) {
-            meta.add(new TripleImpl(sessionur, HAS_APPENDED, scopeur));
-            meta.add(new TripleImpl(scopeur, APPENDED_TO, sessionur));
-        }
+        // TODO Auto-generated method stub
+
     }
 
     @Override
@@ -1170,15 +1265,8 @@ public class ClerezzaOntologyProvider im
 
     @Override
     public void scopeDetached(Session session, String scopeId) {
-        final TripleCollection meta = store.getTriples(new UriRef(metaGraphId));
-        final UriRef sessionur = getIRIforSession(session), scopeur = getIRIforScope(scopeId);
-        if (sessionur == null || scopeur == null) throw new IllegalArgumentException(
-                "UriRefs for scope and session cannot be null.");
-        if (meta instanceof MGraph) synchronized (meta) {
-            // TripleImpl implements equals() and hashCode() ...
-            meta.remove(new TripleImpl(sessionur, HAS_APPENDED, scopeur));
-            meta.remove(new TripleImpl(scopeur, APPENDED_TO, sessionur));
-        }
+        // TODO Auto-generated method stub
+
     }
 
     @Override
@@ -1193,19 +1281,30 @@ public class ClerezzaOntologyProvider im
 
     @Override
     public void sessionChanged(SessionEvent event) {
-        if (event.getOperationType() == OperationType.CREATE) {
-            updateSessionRegistration(event.getSession());
-        } else if (event.getOperationType() == OperationType.KILL) {
-            updateSessionUnregistration(event.getSession());
+        Session s = event.getSession();
+        switch (event.getOperationType()) {
+            case CREATE:
+                break;
+            case KILL:
+                // In the current implementation it is not GC'ed yet, but it might be in the future
+                if (s != null) for (OWLOntologyID publicKey : s.listManagedOntologies()) {
+                    // Set<OntologyCollector> handles = descriptor.getHandles(publicKey);
+                    // if (handles.isEmpty()) throw new IllegalStateException(
+                    // "No handles on an ontology apparently managed by session " + s);
+                    // else if (handles.size() == 1) {
+                    // OntologyCollector handle = handles.iterator().next();
+                    // if (handle != s) throw new IllegalStateException(
+                    // "Unexpected single handle differs from " + s);
+                    // }
+                    // removeOntology(publicKey);
+                }
+                break;
+            default:
+                break;
         }
     }
 
     @Override
-    public void setGraphPrefix(String prefix) {
-        this.prefix = prefix;
-    }
-
-    @Override
     public void setImportManagementPolicy(ImportManagementPolicy policy) {
         if (policy == null) throw new IllegalArgumentException("Import management policy cannot be null.");
         importPolicyString = policy.toString();
@@ -1225,6 +1324,14 @@ public class ClerezzaOntologyProvider im
         keymap.mapLocator(locator, new UriRef(key));
     }
 
+    @Override
+    public void setLocatorMapping(IRI locator, OWLOntologyID publicKey) {
+        if (publicKey == null || publicKey.isAnonymous()) throw new IllegalArgumentException(
+                "key must be non-null and non-anonymous.");
+        log.info("Setting {} as the resource locator for ontology {}", locator, publicKey);
+        keymap.addAlias(new OWLOntologyID(locator), publicKey);
+    }
+
     /**
      * 
      * @param graphName
@@ -1235,14 +1342,14 @@ public class ClerezzaOntologyProvider im
      */
     protected OWLOntology toOWLOntology(UriRef graphName, boolean forceMerge) throws OWLOntologyCreationException {
 
+        log.debug("Exporting graph to OWLOntology");
+        log.debug(" -- Graph name : {}", graphName);
         OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
         // Never try to import
         mgr.addIRIMapper(new PhonyIRIMapper(Collections.<IRI> emptySet()));
 
         Set<OWLOntologyID> loaded = new HashSet<OWLOntologyID>();
-
         TripleCollection graph = store.getTriples(graphName);
-
         UriRef ontologyId = null;
 
         // Get the id of this ontology.
@@ -1253,6 +1360,7 @@ public class ClerezzaOntologyProvider im
         }
         List<OWLOntologyID> revImps = new Stack<OWLOntologyID>();
         List<OWLOntologyID> lvl1 = new Stack<OWLOntologyID>();
+
         fillImportsReverse(keymap.getReverseMapping(graphName), revImps, lvl1);
 
         // If not set to merge (either by policy of by force), adopt the set import policy.
@@ -1409,50 +1517,9 @@ public class ClerezzaOntologyProvider im
         }
     }
 
-    private void updateSessionRegistration(Session session) {
-        final TripleCollection meta = store.getTriples(new UriRef(metaGraphId));
-        final UriRef sesur = getIRIforSession(session);
-        // If this method was called after a session rebuild, the following will have little to no effect.
-        synchronized (meta) {
-            // The only essential triple to add is typing
-            meta.add(new TripleImpl(sesur, RDF.type, SESSION));
-        }
-        log.debug("Ontology collector information triples added for session \"{}\".", sesur);
-    }
-
-    private void updateSessionUnregistration(Session session) {
-        long before = System.currentTimeMillis();
-        boolean removable = false, conflict = false;
-        final TripleCollection meta = store.getTriples(new UriRef(metaGraphId));
-        final UriRef sessionur = getIRIforSession(session);
-        Set<Triple> removeUs = new HashSet<Triple>();
-        for (Iterator<Triple> it = meta.filter(sessionur, null, null); it.hasNext();) {
-            Triple t = it.next();
-            if (RDF.type.equals(t.getPredicate())) {
-                if (SESSION.equals(t.getObject())) removable = true;
-                else conflict = true;
-            }
-            removeUs.add(t);
-        }
-        if (!removable) {
-            log.error("Cannot write session deregistration to persistence:");
-            log.error("-- resource {}", sessionur);
-            log.error("-- is not typed as a {} in the meta-graph.", SESSION);
-        } else if (conflict) {
-            log.error("Conflict upon session deregistration:");
-            log.error("-- resource {}", sessionur);
-            log.error("-- has incompatible types in the meta-graph.");
-        } else {
-            log.debug("Removing all triples for session \"{}\".", session.getID());
-            Iterator<Triple> it;
-            for (it = meta.filter(null, null, sessionur); it.hasNext();)
-                removeUs.add(it.next());
-            for (it = meta.filter(sessionur, null, null); it.hasNext();)
-                removeUs.add(it.next());
-            meta.removeAll(removeUs);
-            log.debug("Done; removed {} triples in {} ms.", removeUs.size(), System.currentTimeMillis()
-                                                                             - before);
-        }
+    @Override
+    public Set<OWLOntologyID> listVersions(IRI ontologyIri) {
+        return keymap.getVersions(ontologyIri);
     }
 
 }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/MGraphNetworkMultiplexer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/MGraphNetworkMultiplexer.java?rev=1370175&r1=1370174&r2=1370175&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/MGraphNetworkMultiplexer.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/MGraphNetworkMultiplexer.java Tue Aug  7 11:07:27 2012
@@ -16,11 +16,14 @@
  */
 package org.apache.stanbol.ontologymanager.ontonet.impl.clerezza;
 
+import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.APPENDED_TO;
 import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.ENTRY;
+import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.HAS_APPENDED;
 import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.HAS_ONTOLOGY_IRI;
 import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.HAS_VERSION_IRI;
 import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.IS_MANAGED_BY;
 import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.MANAGES;
+import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.SESSION;
 import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.SIZE_IN_TRIPLES;
 import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary._NS_STANBOL_INTERNAL;
 
@@ -40,6 +43,7 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpace;
 import org.apache.stanbol.ontologymanager.ontonet.api.session.Session;
+import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionEvent;
 import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
 import org.semanticweb.owlapi.model.IRI;
 import org.semanticweb.owlapi.model.OWLOntologyID;
@@ -169,6 +173,23 @@ public class MGraphNetworkMultiplexer im
 
     }
 
+    private UriRef getIRIforScope(String scopeId) {
+        // Use the Stanbol-internal namespace, so that the whole configuration can be ported.
+        return new UriRef(_NS_STANBOL_INTERNAL + OntologyScope.shortName + "/" + scopeId);
+    }
+
+    private UriRef getIRIforSession(Session session) {
+        // Use the Stanbol-internal namespace, so that the whole configuration can be ported.
+        return new UriRef(_NS_STANBOL_INTERNAL + Session.shortName + "/" + session.getID());
+    }
+
+    @Override
+    public OWLOntologyID getPublicKey(String stringForm) {
+        if (stringForm == null || stringForm.trim().isEmpty()) throw new IllegalArgumentException(
+                "String form must not be null or empty.");
+        return buildPublicKey(new UriRef(stringForm));
+    }
+
     @Override
     public Set<OWLOntologyID> getPublicKeys() {
         Set<OWLOntologyID> result = new HashSet<OWLOntologyID>();
@@ -306,10 +327,89 @@ public class MGraphNetworkMultiplexer im
     }
 
     @Override
-    public OWLOntologyID getPublicKey(String stringForm) {
-        if (stringForm == null || stringForm.trim().isEmpty()) throw new IllegalArgumentException(
-                "String form must not be null or empty.");
-        return buildPublicKey(new UriRef(stringForm));
+    public void scopeAppended(Session session, String scopeId) {
+        final UriRef sessionur = getIRIforSession(session), scopeur = getIRIforScope(scopeId);
+        if (sessionur == null || scopeur == null) throw new IllegalArgumentException(
+                "UriRefs for scope and session cannot be null.");
+        if (meta instanceof MGraph) synchronized (meta) {
+            meta.add(new TripleImpl(sessionur, HAS_APPENDED, scopeur));
+            meta.add(new TripleImpl(scopeur, APPENDED_TO, sessionur));
+        }
+    }
+
+    @Override
+    public void scopeDetached(Session session, String scopeId) {
+        final UriRef sessionur = getIRIforSession(session), scopeur = getIRIforScope(scopeId);
+        if (sessionur == null || scopeur == null) throw new IllegalArgumentException(
+                "UriRefs for scope and session cannot be null.");
+        if (meta instanceof MGraph) synchronized (meta) {
+            // TripleImpl implements equals() and hashCode() ...
+            meta.remove(new TripleImpl(sessionur, HAS_APPENDED, scopeur));
+            meta.remove(new TripleImpl(scopeur, APPENDED_TO, sessionur));
+        }
+    }
+
+    @Override
+    public void sessionChanged(SessionEvent event) {
+        switch (event.getOperationType()) {
+            case CREATE:
+                updateSessionRegistration(event.getSession());
+                break;
+            case KILL:
+                updateSessionUnregistration(event.getSession());
+                break;
+            default:
+                break;
+        }
+    }
+
+    private void updateSessionRegistration(Session session) {
+        final UriRef sesur = getIRIforSession(session);
+        // If this method was called after a session rebuild, the following will have little to no effect.
+        synchronized (meta) {
+            // The only essential triple to add is typing
+            meta.add(new TripleImpl(sesur, RDF.type, SESSION));
+        }
+        log.debug("Ontology collector information triples added for session \"{}\".", sesur);
+    }
+
+    private void updateSessionUnregistration(Session session) {
+        long before = System.currentTimeMillis();
+        boolean removable = false, conflict = false;
+        final UriRef sessionur = getIRIforSession(session);
+        Set<Triple> removeUs = new HashSet<Triple>();
+        for (Iterator<Triple> it = meta.filter(sessionur, null, null); it.hasNext();) {
+            Triple t = it.next();
+            if (RDF.type.equals(t.getPredicate())) {
+                if (SESSION.equals(t.getObject())) removable = true;
+                else conflict = true;
+            }
+            removeUs.add(t);
+        }
+        if (!removable) {
+            log.error("Cannot write session deregistration to persistence:");
+            log.error("-- resource {}", sessionur);
+            log.error("-- is not typed as a {} in the meta-graph.", SESSION);
+        } else if (conflict) {
+            log.error("Conflict upon session deregistration:");
+            log.error("-- resource {}", sessionur);
+            log.error("-- has incompatible types in the meta-graph.");
+        } else {
+            log.debug("Removing all triples for session \"{}\".", session.getID());
+            Iterator<Triple> it;
+            for (it = meta.filter(null, null, sessionur); it.hasNext();)
+                removeUs.add(it.next());
+            for (it = meta.filter(sessionur, null, null); it.hasNext();)
+                removeUs.add(it.next());
+            meta.removeAll(removeUs);
+            log.debug("Done; removed {} triples in {} ms.", removeUs.size(), System.currentTimeMillis()
+                                                                             - before);
+        }
+    }
+
+    @Override
+    public Set<OntologyCollector> getHandles(OWLOntologyID publicKey) {
+        throw new UnsupportedOperationException("Not implemented yet.");
     }
 
 }