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 2011/08/04 13:07:34 UTC

svn commit: r1153847 - in /incubator/stanbol/trunk: ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/ ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ ontologymanager...

Author: alexdma
Date: Thu Aug  4 11:07:32 2011
New Revision: 1153847

URL: http://svn.apache.org/viewvc?rev=1153847&view=rev
Log:
- Removed unused/deprecated methods for root ontology management. Because of its new role, OntologySpace#getTopOntology() is now asOWLONtology(). (STANBOL-304)
- Verifies that no ontology named after the space ID can be added to or removed from the ontology space itself. (STANBOL-304)
- Utility methods for using physical ontology IRIs when loading anonymous ontologies in scopes. (STANBOL-305)

Added:
    incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/OWLUtils.java
Modified:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologySpace.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/AbstractOntologySpaceImpl.java
    incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java
    incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeOntologyResource.java
    incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/URIUtils.java

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologySpace.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologySpace.java?rev=1153847&r1=1153846&r2=1153847&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologySpace.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologySpace.java Thu Aug  4 11:07:32 2011
@@ -42,6 +42,13 @@ public interface OntologySpace {
 
     void addOntologySpaceListener(OntologySpaceListener listener);
 
+    /**
+     * Returns the ontology that serves as a root module for this ontology space.
+     * 
+     * @return the OWL form of this ontology space.
+     */
+    OWLOntology asOWLOntology();
+
     void clearOntologySpaceListeners();
 
     boolean containsOntology(IRI ontologyIri);
@@ -84,13 +91,6 @@ public interface OntologySpace {
     Collection<OntologySpaceListener> getOntologyScopeListeners();
 
     /**
-     * Returns the ontology that serves as a root module for this ontology space.
-     * 
-     * @return the root module of the ontology space
-     */
-    OWLOntology getTopOntology();
-
-    /**
      * Determines if the ontology identified by the supplied <i>logical</i> IRI has been loaded in this space.<br>
      * <br>
      * Note that ontologies are not identified by physical IRI here. There's no need to ask KReS for

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java?rev=1153847&r1=1153846&r2=1153847&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java Thu Aug  4 11:07:32 2011
@@ -1,19 +1,19 @@
 /*
-* 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.
-*/
+ * 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.impl.io;
 
 import java.util.Dictionary;
@@ -46,175 +46,161 @@ import com.hp.hpl.jena.util.FileManager;
 import org.apache.stanbol.ontologymanager.ontonet.impl.ontology.NoSuchStoreException;
 import org.apache.stanbol.owl.transformation.JenaToClerezzaConverter;
 import org.apache.stanbol.owl.transformation.JenaToOwlConvert;
+import org.apache.stanbol.owl.util.OWLUtils;
 
 public class ClerezzaOntologyStorage {
 
-	private static Logger log = LoggerFactory.getLogger(ClerezzaOntologyStorage.class);
-	
-	public static final String URI = "http://ontologydesignpatterns.org/ont/iks/oxml.owl";
-	
-	TcManager tcManager;
-	
-	WeightedTcProvider weightedTcProvider;
-	
-	/**
-	 * This default constructor is <b>only</b> intended to be used by the OSGI
-	 * environment with Service Component Runtime support.
-	 * <p>
-	 * DO NOT USE to manually create instances - the ClerezzaStorage instances
-	 * do need to be configured! YOU NEED TO USE
-	 * {@link #ClerezzaStorage(TcManager, WeightedTcProvider, OntologyStoreProvider)}
-	 * or its overloads, to parse the configuration and then initialise the rule
-	 * store if running outside a OSGI environment.
-	 */
-	protected ClerezzaOntologyStorage() {
-
-	}
-	
-	/**
-	 * Basic constructor to be used if outside of an OSGi environment. Invokes
-	 * default constructor.
-	 * 
-	 * @param tcManager
-	 * @param wtcProvider
-	 * @param osProvider
-	 */
-	public ClerezzaOntologyStorage(TcManager tcManager, WeightedTcProvider wtcProvider) {
-		this();
-		this.tcManager = tcManager;
-		this.weightedTcProvider = wtcProvider;
-		activate(new Hashtable<String, Object>());
-	}
+    private static Logger log = LoggerFactory.getLogger(ClerezzaOntologyStorage.class);
 
-	@SuppressWarnings("unchecked")
+    public static final String URI = "http://ontologydesignpatterns.org/ont/iks/oxml.owl";
+
+    TcManager tcManager;
+
+    WeightedTcProvider weightedTcProvider;
+
+    /**
+     * This default constructor is <b>only</b> intended to be used by the OSGI environment with Service
+     * Component Runtime support.
+     * <p>
+     * DO NOT USE to manually create instances - the ClerezzaStorage instances do need to be configured! YOU
+     * NEED TO USE {@link #ClerezzaStorage(TcManager, WeightedTcProvider, OntologyStoreProvider)} or its
+     * overloads, to parse the configuration and then initialise the rule store if running outside a OSGI
+     * environment.
+     */
+    protected ClerezzaOntologyStorage() {
+
+    }
+
+    /**
+     * Basic constructor to be used if outside of an OSGi environment. Invokes default constructor.
+     * 
+     * @param tcManager
+     * @param wtcProvider
+     * @param osProvider
+     */
+    public ClerezzaOntologyStorage(TcManager tcManager, WeightedTcProvider wtcProvider) {
+        this();
+        this.tcManager = tcManager;
+        this.weightedTcProvider = wtcProvider;
+        activate(new Hashtable<String,Object>());
+    }
+
+    @SuppressWarnings("unchecked")
     protected void activate(ComponentContext context) {
-		log.info("in " + ClerezzaOntologyStorage.class + " activate with context "
-				+ context);
-		if (context == null) {
-			throw new IllegalStateException("No valid" + ComponentContext.class
-					+ " parsed in activate!");
-		}
-		activate((Dictionary<String, Object>) context.getProperties());
-	}
-
-	protected void activate(Dictionary<String, Object> configuration) {
-
-	}
-
-	public void clear() {
-		// TODO Auto-generated method stub
-	}
-
-	protected void deactivate(ComponentContext context) {
-		log.info("in " + ClerezzaOntologyStorage.class + " deactivate with context "
-				+ context);
-		tcManager = null;
-		weightedTcProvider = null;
-	}
-
-	public void delete(IRI ontologyId) {
-		// TODO Auto-generated method stub
-	}
-
-	public void deleteAll(Set<IRI> ontologyIds) {
-		// TODO Auto-generated method stub
-	}
-
-	public OWLOntology getGraph(IRI ontologyID) throws NoSuchStoreException {
-		OWLOntology ontology = null;
-
-		if (tcManager != null) {
-			MGraph mGraph = tcManager.getMGraph(new UriRef(ontologyID
-					.toString()));
-			JenaToOwlConvert jowl = new JenaToOwlConvert();
-			OntModel ontModel = ModelFactory.createOntologyModel(
-					OntModelSpec.OWL_DL_MEM, FileManager.get().loadModel(
-					    URI));
-			ontModel.add(JenaToClerezzaConverter
-					.clerezzaMGraphToJenaModel(mGraph));
-			ontology = jowl.ModelJenaToOwlConvert(ontModel, "RDF/XML");
-			// ontology =
-			// OWLAPIToClerezzaConverter.clerezzaMGraphToOWLOntology(mGraph);
-
-		} else {
-			throw new NoSuchStoreException(
-					"No store registered or activated in the environment.");
-		}
-		return ontology;
-	}
-
-	public Set<IRI> listGraphs() {
-
-		Set<IRI> iris = null;
-		Set<UriRef> uriRefs = tcManager.listTripleCollections();
-		if (uriRefs != null) {
-			iris = new HashSet<IRI>();
-			for (UriRef uriRef : uriRefs) {
-				iris.add(IRI.create(uriRef.toString()));
-			}
-		}
-		return iris;
-
-	}
-
-	public OWLOntology load(IRI ontologyId) {
-		MGraph triples = TcManager.getInstance().getMGraph(
-				new UriRef(ontologyId.toString()));
-		Model om = JenaToClerezzaConverter.clerezzaMGraphToJenaModel(triples);
-		JenaToOwlConvert converter = new JenaToOwlConvert();
-		return converter.ModelJenaToOwlConvert(om, "RDF/XML");
-	}
-	
-	public OWLOntology sparqlConstruct(String sparql, String datasetURI) {
-		
-		Query query;
-		
-		MGraph mGraph = new SimpleMGraph();
-		try {
-			query = QueryParser.getInstance().parse(sparql);
-			
-			UriRef datasetUriRef = new UriRef(datasetURI);
-			MGraph dataset = weightedTcProvider.getMGraph(datasetUriRef);
-			
-			mGraph.addAll((SimpleGraph) tcManager.executeSparqlQuery(query,
-					dataset));
-			
-		} catch (ParseException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-		Model om = JenaToClerezzaConverter.clerezzaMGraphToJenaModel(mGraph);
-		JenaToOwlConvert converter = new JenaToOwlConvert();
-		return converter.ModelJenaToOwlConvert(om, "RDF/XML");
-	}
-
-	public void store(OWLOntology o) {
-		
-		JenaToOwlConvert converter = new JenaToOwlConvert();
-		OntModel om = converter.ModelOwlToJenaConvert(o, "RDF/XML");
-		MGraph mg = JenaToClerezzaConverter.jenaModelToClerezzaMGraph(om);
-		// MGraph mg = OWLAPIToClerezzaConverter.owlOntologyToClerezzaMGraph(o);
-		MGraph mg2 = null;
-UriRef ref = new UriRef(o.getOntologyID()
-    .getOntologyIRI().toString());
-		try {
-		mg2 = tcManager.createMGraph(ref);
-		} catch (EntityAlreadyExistsException ex) {
-		    log.info("Entity "+ref+" already exists in store. Replacing...");
-		    mg2 = tcManager.getMGraph(ref);
-		}
-		
-		mg2.addAll(mg);
-	}
-	
-	public void store(OWLOntology o, IRI ontologyID) {
-			
-		JenaToOwlConvert converter = new JenaToOwlConvert();
-		OntModel om = converter.ModelOwlToJenaConvert(o, "RDF/XML");
-		MGraph mg = JenaToClerezzaConverter.jenaModelToClerezzaMGraph(om);
-		// MGraph mg = OWLAPIToClerezzaConverter.owlOntologyToClerezzaMGraph(o);
-		MGraph mg2 = tcManager.createMGraph(new UriRef(ontologyID.toString()));
-		mg2.addAll(mg);
-	}
+        log.info("in " + ClerezzaOntologyStorage.class + " activate with context " + context);
+        if (context == null) {
+            throw new IllegalStateException("No valid" + ComponentContext.class + " parsed in activate!");
+        }
+        activate((Dictionary<String,Object>) context.getProperties());
+    }
+
+    protected void activate(Dictionary<String,Object> configuration) {
+
+    }
+
+    public void clear() {
+        // TODO Auto-generated method stub
+    }
+
+    protected void deactivate(ComponentContext context) {
+        log.info("in " + ClerezzaOntologyStorage.class + " deactivate with context " + context);
+        tcManager = null;
+        weightedTcProvider = null;
+    }
+
+    public void delete(IRI ontologyId) {
+        // TODO Auto-generated method stub
+    }
+
+    public void deleteAll(Set<IRI> ontologyIds) {
+        // TODO Auto-generated method stub
+    }
+
+    public OWLOntology getGraph(IRI ontologyID) throws NoSuchStoreException {
+        OWLOntology ontology = null;
+
+        if (tcManager != null) {
+            MGraph mGraph = tcManager.getMGraph(new UriRef(ontologyID.toString()));
+            JenaToOwlConvert jowl = new JenaToOwlConvert();
+            OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, FileManager.get()
+                    .loadModel(URI));
+            ontModel.add(JenaToClerezzaConverter.clerezzaMGraphToJenaModel(mGraph));
+            ontology = jowl.ModelJenaToOwlConvert(ontModel, "RDF/XML");
+            // ontology =
+            // OWLAPIToClerezzaConverter.clerezzaMGraphToOWLOntology(mGraph);
+
+        } else {
+            throw new NoSuchStoreException("No store registered or activated in the environment.");
+        }
+        return ontology;
+    }
+
+    public Set<IRI> listGraphs() {
+
+        Set<IRI> iris = null;
+        Set<UriRef> uriRefs = tcManager.listTripleCollections();
+        if (uriRefs != null) {
+            iris = new HashSet<IRI>();
+            for (UriRef uriRef : uriRefs) {
+                iris.add(IRI.create(uriRef.toString()));
+            }
+        }
+        return iris;
+
+    }
+
+    public OWLOntology load(IRI ontologyId) {
+        MGraph triples = TcManager.getInstance().getMGraph(new UriRef(ontologyId.toString()));
+        Model om = JenaToClerezzaConverter.clerezzaMGraphToJenaModel(triples);
+        JenaToOwlConvert converter = new JenaToOwlConvert();
+        return converter.ModelJenaToOwlConvert(om, "RDF/XML");
+    }
+
+    public OWLOntology sparqlConstruct(String sparql, String datasetURI) {
+
+        Query query;
+        MGraph mGraph = new SimpleMGraph();
+        try {
+            query = QueryParser.getInstance().parse(sparql);
+            UriRef datasetUriRef = new UriRef(datasetURI);
+            MGraph dataset = weightedTcProvider.getMGraph(datasetUriRef);
+            mGraph.addAll((SimpleGraph) tcManager.executeSparqlQuery(query, dataset));
+        } catch (ParseException e) {
+            log.error("Unable to execute SPARQL. ", e);
+        }
+
+        Model om = JenaToClerezzaConverter.clerezzaMGraphToJenaModel(mGraph);
+        JenaToOwlConvert converter = new JenaToOwlConvert();
+
+        return converter.ModelJenaToOwlConvert(om, "RDF/XML");
+    }
+
+    public void store(OWLOntology o) {
+
+        JenaToOwlConvert converter = new JenaToOwlConvert();
+        OntModel om = converter.ModelOwlToJenaConvert(o, "RDF/XML");
+        MGraph mg = JenaToClerezzaConverter.jenaModelToClerezzaMGraph(om);
+        // MGraph mg = OWLAPIToClerezzaConverter.owlOntologyToClerezzaMGraph(o);
+        MGraph mg2 = null;
+        IRI iri = OWLUtils.getIdentifyingIRI(o);
+        UriRef ref = new UriRef(iri.toString());
+        try {
+            mg2 = tcManager.createMGraph(ref);
+        } catch (EntityAlreadyExistsException ex) {
+            log.info("Entity " + ref + " already exists in store. Replacing...");
+            mg2 = tcManager.getMGraph(ref);
+        }
+
+        mg2.addAll(mg);
+    }
+
+    public void store(OWLOntology o, IRI ontologyID) {
+
+        JenaToOwlConvert converter = new JenaToOwlConvert();
+        OntModel om = converter.ModelOwlToJenaConvert(o, "RDF/XML");
+        MGraph mg = JenaToClerezzaConverter.jenaModelToClerezzaMGraph(om);
+        // MGraph mg = OWLAPIToClerezzaConverter.owlOntologyToClerezzaMGraph(o);
+        MGraph mg2 = tcManager.createMGraph(new UriRef(ontologyID.toString()));
+        mg2.addAll(mg);
+    }
 }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/AbstractOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/AbstractOntologySpaceImpl.java?rev=1153847&r1=1153846&r2=1153847&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/AbstractOntologySpaceImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/AbstractOntologySpaceImpl.java Thu Aug  4 11:07:32 2011
@@ -25,7 +25,6 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
-import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologySource;
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.MissingOntologyException;
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpace;
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpaceListener;
@@ -34,13 +33,9 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SpaceType;
 import org.apache.stanbol.ontologymanager.ontonet.api.ontology.UnmodifiableOntologySpaceException;
 import org.apache.stanbol.ontologymanager.ontonet.impl.io.ClerezzaOntologyStorage;
-import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
-import org.apache.stanbol.ontologymanager.ontonet.impl.util.StringUtils;
+import org.apache.stanbol.owl.util.OWLUtils;
 import org.apache.stanbol.owl.util.URIUtils;
 import org.semanticweb.owlapi.apibinding.OWLManager;
-import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
-import org.semanticweb.owlapi.io.StringDocumentSource;
-import org.semanticweb.owlapi.io.StringDocumentTarget;
 import org.semanticweb.owlapi.model.AddImport;
 import org.semanticweb.owlapi.model.IRI;
 import org.semanticweb.owlapi.model.OWLDataFactory;
@@ -48,9 +43,7 @@ import org.semanticweb.owlapi.model.OWLO
 import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
 import org.semanticweb.owlapi.model.OWLOntologyChange;
 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
-import org.semanticweb.owlapi.model.OWLOntologyID;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
-import org.semanticweb.owlapi.model.OWLOntologyStorageException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -61,10 +54,6 @@ import org.slf4j.LoggerFactory;
  * <br>
  * NOTE: By default, an ontology space is NOT write-locked. Developers need to set the <code>locked</code>
  * variable to true to make the space read-only.
- * 
- * 
- * @author alessandro
- * 
  */
 public abstract class AbstractOntologySpaceImpl implements OntologySpace {
 
@@ -80,25 +69,24 @@ public abstract class AbstractOntologySp
     protected Logger log = LoggerFactory.getLogger(getClass());
 
     /**
+     * The identifier of the ontologies directly managed by this space (i.e. that were directly added to this
+     * space, hence not including those just pulled in via import statements).
+     */
+    protected Set<OWLOntology> managedOntologies;
+
+    /**
      * Each ontology space comes with its OWL ontology manager. By default, it is not available to the outside
      * world, unless subclasses implement methods to return it.
      */
     protected OWLOntologyManager ontologyManager;
 
-    protected ClerezzaOntologyStorage storage;
-
     protected IRI parentID = null;
 
-    /**
-     * The identifier of the ontologies directly managed by this space (i.e. that were directly added to this
-     * space, hence not including those just pulled in via import statements).
-     */
-    protected Set<OWLOntology> managedOntologies;
+    protected boolean silent = false;
 
-    @Deprecated
-    protected OWLOntology rootOntology = null;
+    protected ClerezzaOntologyStorage storage;
 
-    protected boolean silent = false;
+    protected SpaceType type;
 
     protected AbstractOntologySpaceImpl(IRI spaceID, SpaceType type, ClerezzaOntologyStorage storage) {
         this(spaceID, type, storage, OWLManager.createOWLOntologyManager());
@@ -118,61 +106,26 @@ public abstract class AbstractOntologySp
                                         SpaceType type,
                                         ClerezzaOntologyStorage storage,
                                         OWLOntologyManager ontologyManager) {
-
-        // this.parentID = parentID;
-        // SUFFIX = type.getIRISuffix();
-
-        // // FIXME: ensure that this is not null
-        // OntologyScope parentScope = ONManager.get().getScopeRegistry()
-        // .getScope(parentID);
-        //
-        // if (parentScope != null && parentScope instanceof OntologySpaceListener)
-        // this.addOntologySpaceListener((OntologySpaceListener) parentScope);
-        this.storage = storage;
-
         this._id = spaceID;
+        this.type = type;
+        this.storage = storage;
         if (ontologyManager != null) this.ontologyManager = ontologyManager;
         else this.ontologyManager = OWLManager.createOWLOntologyManager();
 
         this.managedOntologies = new HashSet<OWLOntology>();
     }
 
-    /**
-     * TODO: manage import statements
-     * 
-     * TODO 2 : manage anonymous ontologies.
-     */
     @Override
     public synchronized void addOntology(OntologyInputSource ontologySource) throws UnmodifiableOntologySpaceException {
-
         if (locked) throw new UnmodifiableOntologySpaceException(this);
-
-        // if (getTopOntology() == null) {
-        // log.warn("Root ontology for ontology space {} was found to be null. This should not happen.",
-        // this.getID());
-        // // If no top ontology has been set, we must create one first.
-        // IRI rootIri = null;
-        // try {
-        // rootIri = IRI.create(StringUtils.stripIRITerminator(this.getID()) + "/root.owl");
-        // OntologyInputSource src = new RootOntologySource(ontologyManager.createOntology(rootIri),
-        // null);
-        // // Don't bother about the ontology to be added right now.
-        // setTopOntology(src, false);
-        // } catch (OWLOntologyCreationException e) {
-        // log.error(
-        // "Exception caught when creating top ontology " + rootIri + " for space " + this.getID()
-        // + ".", e);
-        // // No point in continuing if we can't even create the root...
-        // return;
-        // }
-        // }
-
-        // Now add the new ontology.
+        // Avoid adding the space top ontology itself.
         if (ontologySource != null && ontologySource.hasRootOntology()) {
+            OWLOntology o = ontologySource.getRootOntology();
+            if (!o.isAnonymous() && getID().equals(o.getOntologyID().getOntologyIRI())) throw new IllegalArgumentException(
+                    "Cannot add a space's own ontology to itself.");
+            else performAdd(ontologySource);
             // Remember that this method also fires the event
-            performAdd(ontologySource);
         }
-
     }
 
     @Override
@@ -181,6 +134,56 @@ public abstract class AbstractOntologySp
     }
 
     @Override
+    public OWLOntology asOWLOntology() {
+        OWLOntology root;
+        try {
+            root = ontologyManager.createOntology(_id);
+        } catch (OWLOntologyAlreadyExistsException e) {
+            ontologyManager.removeOntology(ontologyManager.getOntology(_id));
+            try {
+                root = ontologyManager.createOntology(_id);
+            } catch (OWLOntologyAlreadyExistsException e1) {
+                root = ontologyManager.getOntology(_id);
+            } catch (OWLOntologyCreationException e1) {
+                log.error("Failed to assemble root ontology for scope " + _id, e);
+                root = null;
+            }
+        } catch (OWLOntologyCreationException e) {
+            log.error("Failed to assemble root ontology for scope " + _id, e);
+            root = null;
+        }
+
+        // Add the import declarations for directly managed ontologies.
+        if (root != null) {
+            List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>();
+            OWLDataFactory df = ontologyManager.getOWLDataFactory();
+            for (OWLOntology o : getOntologies(false)) {
+                if (o == null) continue;
+
+                String base = URIUtils.upOne(getID()) + "/";
+
+                IRI ontologyIri;
+
+                if (o.isAnonymous()) try {
+                    ontologyIri = ontologyManager.getOntologyDocumentIRI(o);
+                } catch (Exception ex) {
+                    ontologyIri = o.getOWLOntologyManager().getOntologyDocumentIRI(o);
+                }
+                else {
+                    ontologyIri = o.getOntologyID().getDefaultDocumentIRI();
+                }
+
+                IRI physIRI = IRI.create(base + ontologyIri);
+
+                changes.add(new AddImport(root, df.getOWLImportsDeclaration(physIRI)));
+            }
+            ontologyManager.applyChanges(changes);
+        }
+        // return rootOntology;
+        return root;
+    }
+
+    @Override
     public void clearOntologySpaceListeners() {
         listeners.clear();
     }
@@ -198,7 +201,7 @@ public abstract class AbstractOntologySp
      */
     protected void fireOntologyAdded(IRI ontologyIri) {
         for (OntologySpaceListener listener : listeners)
-            listener.onOntologyAdded(this.getID(), ontologyIri);
+            listener.onOntologyAdded(_id, ontologyIri);
     }
 
     /**
@@ -209,7 +212,7 @@ public abstract class AbstractOntologySp
      */
     protected void fireOntologyRemoved(IRI ontologyIri) {
         for (OntologySpaceListener listener : listeners)
-            listener.onOntologyRemoved(this.getID(), ontologyIri);
+            listener.onOntologyRemoved(_id, ontologyIri);
     }
 
     @Override
@@ -240,56 +243,6 @@ public abstract class AbstractOntologySp
     }
 
     @Override
-    public OWLOntology getTopOntology() {
-        OWLOntology root;
-        try {
-            root = ontologyManager.createOntology(_id);
-        } catch (OWLOntologyAlreadyExistsException e) {
-            ontologyManager.removeOntology(ontologyManager.getOntology(_id));
-            try {
-                root = ontologyManager.createOntology(_id);
-            } catch (OWLOntologyAlreadyExistsException e1) {
-                root = ontologyManager.getOntology(_id);
-            } catch (OWLOntologyCreationException e1) {
-                log.error("Failed to assemble root ontology for scope " + _id, e);
-                root = null;
-            }
-        } catch (OWLOntologyCreationException e) {
-            log.error("Failed to assemble root ontology for scope " + _id, e);
-            root = null;
-        }
-
-        // Add the import declarations for directly managed ontologies.
-        if (root != null) {
-            List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>();
-            OWLDataFactory df = ontologyManager.getOWLDataFactory();
-            for (OWLOntology o : getOntologies(false)) {
-                if (o == null) continue;
-
-                String base = URIUtils.upOne(getID()) + "/";
-
-                IRI ontologyIri;
-
-                if (o.isAnonymous()) try {
-                    ontologyIri = ontologyManager.getOntologyDocumentIRI(o);
-                } catch (Exception ex) {
-                    ontologyIri = o.getOWLOntologyManager().getOntologyDocumentIRI(o);
-                }
-                else {
-                    ontologyIri = o.getOntologyID().getDefaultDocumentIRI();
-                }
-
-                IRI physIRI = IRI.create(base + ontologyIri);
-
-                changes.add(new AddImport(root, df.getOWLImportsDeclaration(physIRI)));
-            }
-            ontologyManager.applyChanges(changes);
-        }
-        // return rootOntology;
-        return root;
-    }
-
-    @Override
     public boolean hasOntology(IRI ontologyIri) {
         return this.getOntology(ontologyIri) != null;
     }
@@ -305,25 +258,20 @@ public abstract class AbstractOntologySp
     }
 
     private void performAdd(OntologyInputSource ontSrc) {
+
         OWLOntology ontology = ontSrc.getRootOntology();
-        OWLOntologyID id = ontology.getOntologyID();
 
         // Should not modify the child ontology in any way.
         // TODO implement transaction control.
-        // OntologyUtils.appendOntology(new RootOntologySource(getTopOntology(), null), ontSrc,
-        // ontologyManager);
-
-        // See to it that the ontology is copied to this manager
-        reload(ontology, ontologyManager, true, false);
-
-        OWLOntology newOnt = ontologyManager.getOntology(id);
+        // See to it that the ontology is copied to this manager.
+        OWLOntology newOnt = reload(ontology, ontologyManager, true, false);
         managedOntologies.add(newOnt);
 
         try {
             // Store the top ontology
             if (!(this instanceof SessionOntologySpace)) {
-                if (storage == null) log.warn("No ontology storage found. Ontology "
-                                              + ontology.getOntologyID() + " will be stored in-memory only.");
+                if (storage == null) log.warn(
+                    "No ontology storage found. Ontology {} will be stored in-memory only.", ontology);
                 else {
                     // storage = new ClerezzaOntologyStorage(tcManager, wtcProvider)
                     storage.store(ontology);
@@ -334,97 +282,9 @@ public abstract class AbstractOntologySp
             log.warn("An error occurred while storing ontology " + ontology
                      + " . Ontology management will be volatile.", ex);
         }
-        fireOntologyAdded(id.getOntologyIRI());
-    }
-
-    private void performAddOld(OntologyInputSource ontSrc) {
-        OWLOntology ontology = ontSrc.getRootOntology();
-        OWLOntologyID id = ontology.getOntologyID();
-
-        // Should not modify the child ontology in any way.
-        // TODO implement transaction control.
-        OntologyUtils.appendOntology(new RootOntologySource(getTopOntology(), null), ontSrc, ontologyManager);
 
-        // StringDocumentTarget tgt = new StringDocumentTarget();
-        // try {
-        // ontologyManager.saveOntology(ontology, new RDFXMLOntologyFormat(), tgt);
-        // } catch (OWLOntologyStorageException e) {
-        // log.error("KReS : [FATAL] Failed to store ontology " + id + " in memory.", e);
-        // return;
-        // }
-        reload(ontology, ontologyManager, true, false);
-
-        // try {
-        // ontologyManager.removeOntology(ontology);
-        //
-        // // FIXME : this is not memory-efficient.
-        // Set<OWLOntology> closure = ontology.getOWLOntologyManager().getImportsClosure(ontology);
-        // ontologyManager.createOntology(ontology.getOntologyID().getOntologyIRI(), closure);
-        // // FIXME : this on the other hand is neither time-efficient nor network-safe
-        // // ontologyManager
-        // // .loadOntologyFromOntologyDocument(new StringDocumentSource(
-        // // tgt.toString()));
-        // } catch (OWLOntologyAlreadyExistsException e) {
-        // // Could happen if we supplied an ontology manager that already
-        // // knows this ontology. Nothing to do then.
-        // log.warn("KReS : [NONFATAL] Tried to copy ontology " + id + " to existing one.");
-        // } catch (OWLOntologyCreationException e) {
-        // log.error("Unexpected exception caught while copying ontology " + id + " across managers", e);
-        // return;
-        // }
+        fireOntologyAdded(OWLUtils.getIdentifyingIRI(ontology));
 
-        try {
-            // Store the top ontology
-            if (!(this instanceof SessionOntologySpace)) {
-                if (storage == null) log.warn("No ontology storage found. Ontology "
-                                              + ontology.getOntologyID() + " will be stored in-memory only.");
-                else {
-                    // storage = new ClerezzaOntologyStorage(tcManager, wtcProvider)
-                    storage.store(ontology);
-                }
-            }
-            // ONManager.get().getOntologyStore().load(rootOntology.getOntologyID().getOntologyIRI());
-        } catch (Exception ex) {
-            log.warn("An error occurred while storing ontology " + ontology
-                     + " . Ontology management will be volatile.", ex);
-        }
-        fireOntologyAdded(id.getOntologyIRI());
-    }
-
-    /**
-     * TODO 1 : optimize addition/removal <br>
-     * TODO 2 : set import statements
-     */
-    @Override
-    public synchronized void removeOntology(OntologyInputSource src) throws OntologySpaceModificationException {
-        if (locked) throw new UnmodifiableOntologySpaceException(this);
-        else {
-            // TODO : find a way to remove anonymous ontologies.
-            OWLOntology o = src.getRootOntology();
-            IRI logicalID = null, physicalIRI = null;
-            try {
-                logicalID = o.getOntologyID().getOntologyIRI();
-                physicalIRI = src.getPhysicalIRI();
-                if (physicalIRI == null) if (isSilentMissingOntologyHandling()) return;
-                else throw new MissingOntologyException(this, null);
-                if (logicalID == null) logicalID = physicalIRI;
-            } catch (RuntimeException ex) {
-                if (isSilentMissingOntologyHandling()) return;
-                else throw new MissingOntologyException(this, null);
-            }
-            // if (o.equals(getTopOntology()))
-            // // setTopOntology(null, false);
-            // throw new IrremovableOntologyException(this, logicalID);
-            try {
-                // OWLImportsDeclaration imp = ontologyManager.getOWLDataFactory().getOWLImportsDeclaration(
-                // physicalIRI);
-                // ontologyManager.applyChange(new RemoveImport(getTopOntology(), imp));
-                ontologyManager.removeOntology(o);
-                fireOntologyRemoved(logicalID);
-            } catch (RuntimeException ex) {
-                throw new OntologySpaceModificationException(this, ex);
-            }
-        }
     }
 
     /**
@@ -444,19 +304,29 @@ public abstract class AbstractOntologySp
      *            after <code>ontology</code>. This parameter has virtually no effect if
      *            <code>withClosure</code> is set to false.
      */
-    protected void reload(OWLOntology ontology, OWLOntologyManager mgr, boolean withClosure, boolean merge) {
+    protected OWLOntology reload(OWLOntology ontology,
+                                 OWLOntologyManager mgr,
+                                 boolean withClosure,
+                                 boolean merge) {
         if (ontology == null) throw new IllegalArgumentException("ontology cannot be null");
         if (ontology.getOWLOntologyManager() == ontologyManager) {
             log.warn("Ontology {} is already managed by the supplied OWLOntologyManager. Skipping copy.",
                 ontology);
-            return;
+            return ontology;
         }
+
+        OWLOntology root = null;
+
+        IRI location = ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology);
+        IRI idd = OWLUtils.getIdentifyingIRI(ontology);
         if (mgr == null) mgr = ontologyManager;
         Set<OWLOntology> closure = withClosure ? ontology.getOWLOntologyManager().getImportsClosure(ontology)
                 : Collections.singleton(ontology);
         mgr.removeOntology(ontology);
         if (merge) try {
-            mgr.createOntology(ontology.getOntologyID().getOntologyIRI(), closure);
+            root = mgr.createOntology(idd, closure);
+            mgr.setOntologyDocumentIRI(root, location);
+            return root;
         } catch (OWLOntologyCreationException e1) {
             log.error("Unexpected exception caught while copying ontology " + ontology.getOntologyID()
                       + " across managers", e1);
@@ -464,17 +334,22 @@ public abstract class AbstractOntologySp
         else {
 
             for (OWLOntology o : closure) {
-                OWLOntologyID id = o.getOntologyID();
-                if (mgr.contains(id)) {
-                    mgr.removeOntology(mgr.getOntology(id));
+                IRI id2 = OWLUtils.getIdentifyingIRI(o);
+                // OWLOntologyID id = o.getOntologyID();
+                if (mgr.contains(id2)) {
+                    mgr.removeOntology(mgr.getOntology(id2));
                 }
                 try {
-                    mgr.createOntology(id.getOntologyIRI(), Collections.singleton(o));
+                    OWLOntology o1 = mgr.createOntology(id2, Collections.singleton(o));
+                    mgr.setOntologyDocumentIRI(o1, location);
+                    if (idd.equals(id2)) root = o1;
                 } catch (OWLOntologyAlreadyExistsException e) {
                     if (o.getOWLOntologyManager() != mgr) {
                         mgr.removeOntology(o);
                         try {
-                            mgr.createOntology(id.getOntologyIRI(), Collections.singleton(o));
+                            OWLOntology o1 = mgr.createOntology(id2, Collections.singleton(o));
+                            mgr.setOntologyDocumentIRI(o1, location);
+                            if (idd.equals(id2)) root = o1;
                         } catch (OWLOntologyCreationException e1) {
                             log.error(
                                 "Unexpected exception caught while copying ontology "
@@ -483,111 +358,60 @@ public abstract class AbstractOntologySp
                     }
 
                 } catch (OWLOntologyCreationException e) {
-                    log.warn("Failed to re-create ontology {} for ontology space {} . Continuing...", id,
+                    log.warn("Failed to re-create ontology {} for ontology space {} . Continuing...", id2,
                         getID());
                 }
             }
+            return root;
         }
-
-    }
-
-    @Override
-    public void removeOntologySpaceListener(OntologySpaceListener listener) {
-        listeners.remove(listener);
-    }
-
-    @Override
-    public void setSilentMissingOntologyHandling(boolean silent) {
-        this.silent = silent;
+        return root;
     }
 
     /**
-     * TODO 1 : Attention: the ontology from <code>ontologySource</code> is NOT added to the ontology manager!
+     * TODO 1 : optimize addition/removal <br>
+     * TODO 2 : set import statements
      */
-    @Deprecated
-    public synchronized void setTopOntology(OntologyInputSource ontologySource, boolean createParent) throws UnmodifiableOntologySpaceException {
-
-        // TODO : implement or avoid passing of OWLOntology objects across managers
-
-        // Clear the ontology manager
-        for (OWLOntology o : ontologyManager.getOntologies()) {
-            ontologyManager.removeOntology(o);
-            fireOntologyRemoved(o.getOntologyID().getOntologyIRI());
-        }
+    @Override
+    public synchronized void removeOntology(OntologyInputSource src) throws OntologySpaceModificationException {
+        if (locked) throw new UnmodifiableOntologySpaceException(this);
 
-        OWLOntologyID id = new OWLOntologyID(IRI.create(StringUtils.stripIRITerminator(_id) + "/root.owl"));
-        OWLOntology ontology = null;
-        if (ontologySource != null) {
-            ontology = ontologySource.getRootOntology();
+        if (src != null && src.hasRootOntology()) {
+            OWLOntology o = src.getRootOntology();
+            if (!o.isAnonymous() && getID().equals(o.getOntologyID().getOntologyIRI())) throw new IllegalArgumentException(
+                    "Cannot remove a space's own ontology form.");
         }
 
-        // Placeholder for the parent ontology (can be either the space root or the supplied ontology).
-        OWLOntology oParent = null;
-
-        // If set to create a parent ontology or this one is anonymous, create the parent
-        if (createParent || ontology == null || ontology.isAnonymous()) {
-
-            try {
-                oParent = ontologyManager.createOntology(id);
-            } catch (OWLOntologyAlreadyExistsException e) {
-                // Should not happen since the manager was cleared, but anyway.
-                oParent = ontologyManager.getOntology(id);
-            } catch (OWLOntologyCreationException e) {
-                log.error("KReS :: Failed to copy ontology " + ontology.getOntologyID()
-                          + " across ontology managers.", e);
-            }
-        } else {
-            // If we don't have to create a parent, set the original ontology to be the parent.
-            oParent = ontology;
-        }
-
-        if (ontologySource != null) try {
-
-            // Append the supplied ontology to the parent.
-            oParent = OntologyUtils.appendOntology(new RootOntologySource(oParent, null), ontologySource,
-                ontologyManager);
-
-            // Save and reload it to make sure the whole import closure is
-            // loaded in memory.
-            StringDocumentTarget tgt = new StringDocumentTarget();
-            ontologyManager.saveOntology(oParent, new RDFXMLOntologyFormat(), tgt);
-            ontologyManager.removeOntology(oParent);
-            ontologyManager.loadOntologyFromOntologyDocument(new StringDocumentSource(tgt.toString()));
-
-            // // FIXME why doesnt this work?
-            // // ontologyManager.removeOntology(oParent);
-            // reload(oParent, ontologyManager, true, false);
-
-        } catch (OWLOntologyAlreadyExistsException e) {
-            log.warn("Tried to copy ontology " + id + " to existing one.", e);
-        } catch (OWLOntologyCreationException e) {
-            log.error("Failed to create ontology " + id, e);
-        } catch (OWLOntologyStorageException e) {
-            // Shouldn't be a problem to save it in memory as RDF/XML...
-            log.error("In-memory store failed for ontology " + id, e);
+        // TODO : find a way to remove anonymous ontologies.
+        OWLOntology o = src.getRootOntology();
+        IRI logicalID = null, physicalIRI = null;
+        try {
+            logicalID = o.getOntologyID().getOntologyIRI();
+            physicalIRI = src.getPhysicalIRI();
+            if (physicalIRI == null) if (isSilentMissingOntologyHandling()) return;
+            else throw new MissingOntologyException(this, null);
+            if (logicalID == null) logicalID = physicalIRI;
+        } catch (RuntimeException ex) {
+            if (isSilentMissingOntologyHandling()) return;
+            else throw new MissingOntologyException(this, null);
         }
 
-        // Assign the ontology and fire the corresponding event.
-        rootOntology = oParent != null ? oParent : ontology;
-
         try {
-
-            // Store the top ontology
-            if (!(this instanceof SessionOntologySpace)) {
-                if (storage == null) log.error("KReS :: [NONFATAL] no ontology storage found. Ontology "
-                                               + rootOntology.getOntologyID()
-                                               + " will be stored in-memory only.");
-                else {
-                    storage.store(rootOntology);
-                }
-            }
-        } catch (Exception ex) {
-            log.error("KReS :: [NONFATAL] An error occurred while storing root ontology " + rootOntology
-                      + " . Ontology management will be volatile!", ex);
+            ontologyManager.removeOntology(o);
+            fireOntologyRemoved(logicalID);
+        } catch (RuntimeException ex) {
+            throw new OntologySpaceModificationException(this, ex);
         }
 
-        fireOntologyAdded(rootOntology.getOntologyID().getOntologyIRI());
+    }
 
+    @Override
+    public void removeOntologySpaceListener(OntologySpaceListener listener) {
+        listeners.remove(listener);
+    }
+
+    @Override
+    public void setSilentMissingOntologyHandling(boolean silent) {
+        this.silent = silent;
     }
 
 }

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java?rev=1153847&r1=1153846&r2=1153847&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java Thu Aug  4 11:07:32 2011
@@ -164,8 +164,8 @@ public class TestOntologyRegistry {
         // OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader()));
         space.addOntology(ontologySource);
         // FIXME : no longer use the top ontology?
-        assertTrue(space.getTopOntology() != null);
-        assertTrue(space.getOntologies(true).contains(space.getTopOntology()));
+        assertTrue(space.asOWLOntology() != null);
+        assertTrue(space.getOntologies(true).contains(space.asOWLOntology()));
     }
 
     /**
@@ -177,7 +177,7 @@ public class TestOntologyRegistry {
         // The input source instantiation automatically loads the entire content of a registry, no need to
         // test loading methods individually.
         scope = onm.getOntologyScopeFactory().createOntologyScope(scopeIri, ontologySource);
-        assertTrue(scope != null && scope.getCoreSpace().getTopOntology() != null);
+        assertTrue(scope != null && scope.getCoreSpace().asOWLOntology() != null);
     }
 
     /**
@@ -190,7 +190,7 @@ public class TestOntologyRegistry {
         // The input source instantiation automatically loads the entire content of a registry, no need to
         // test loading methods individually.
         space = onm.getOntologySpaceFactory().createCoreOntologySpace(scopeIri, ontologySource);
-        assertTrue(space != null && space.getTopOntology() != null);
+        assertTrue(space != null && space.asOWLOntology() != null);
     }
 
 }

Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeOntologyResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeOntologyResource.java?rev=1153847&r1=1153846&r2=1153847&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeOntologyResource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeOntologyResource.java Thu Aug  4 11:07:32 2011
@@ -123,11 +123,11 @@ public class ONMScopeOntologyResource ex
 
             // First of all, it could be a simple request for the space root!
             if (ontiri.equals(scope.getCoreSpace().getID())) {
-                return Response.ok(scope.getCoreSpace().getTopOntology()).build();
+                return Response.ok(scope.getCoreSpace().asOWLOntology()).build();
             } else if (ontiri.equals(scope.getCustomSpace().getID())) {
-                return Response.ok(scope.getCustomSpace().getTopOntology()).build();
+                return Response.ok(scope.getCustomSpace().asOWLOntology()).build();
             } else if (scope.getSessionSpace(ontiri) != null) {
-                return Response.ok(scope.getSessionSpace(ontiri).getTopOntology()).build();
+                return Response.ok(scope.getSessionSpace(ontiri).asOWLOntology()).build();
             }
 
             /*

Added: incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/OWLUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/OWLUtils.java?rev=1153847&view=auto
==============================================================================
--- incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/OWLUtils.java (added)
+++ incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/OWLUtils.java Thu Aug  4 11:07:32 2011
@@ -0,0 +1,42 @@
+/*
+ * 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.owl.util;
+
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+
+/**
+ * A set of utility methods for the manipulation of OWL API objects.
+ */
+public class OWLUtils {
+
+    /**
+     * If the ontology is named, this method will return its logical ID, otherwise it will return the location
+     * it was retrieved from (which is still unique).
+     * 
+     * @param o
+     * @return
+     */
+    public static IRI getIdentifyingIRI(OWLOntology o) {
+        if (o.isAnonymous()) {
+            return o.getOWLOntologyManager().getOntologyDocumentIRI(o);
+        } else {
+            return o.getOntologyID().getOntologyIRI();
+        }
+    }
+
+}

Modified: incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/URIUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/URIUtils.java?rev=1153847&r1=1153846&r2=1153847&view=diff
==============================================================================
--- incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/URIUtils.java (original)
+++ incubator/stanbol/trunk/owl/src/main/java/org/apache/stanbol/owl/util/URIUtils.java Thu Aug  4 11:07:32 2011
@@ -22,6 +22,12 @@ import org.semanticweb.owlapi.model.IRI;
 
 public class URIUtils {
 
+    /**
+     * Removes either the fragment, or query, or last path component from a URI, whatever it finds first.
+     * 
+     * @param iri
+     * @return
+     */
     public static IRI upOne(IRI iri) {
         return upOne(iri.toURI());
     }