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/07/10 19:00:55 UTC

svn commit: r1359786 [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/io/ ontonet/src/main/java/org/apache/st...

Author: alexdma
Date: Tue Jul 10 17:00:53 2012
New Revision: 1359786

URL: http://svn.apache.org/viewvc?rev=1359786&view=rev
Log:
* ONManager now has a configurable parameter CONNECTIVITY_POLICY, with values TIGHT and LOOSE. Currently the default setting is TIGHT (newly implemented) and it will cause all ontologies managed by a custom space to contain an import statement for the whole core space, whenever they are exported to OWL or RDF artifacts. (STANBOL-681)
* Fixed an IRI sanity issue that caused ontology collectors not to be rebuilt when managed ontology IDs ended with '#' (STANBOL-571)
* It is now possible to retrieve mappings from stored graphs to *physical* ontology IRIs (if different from the logical IRIs). These are stored as literal values for the "retrievedFrom" property, typed as xsd:anyURI (STANBOL-571)
* All methods that parse ontologies on multiple attempts now try to reset the input stream (or make a BufferedInputStream). If it is not possible and the first attempts fails a new OntologyLoadingException is thrown (STANBOL-680)
* Query parameters "coreont" and "corereg" for the PUT method of scope resources are now of type List<String> so multiple values can be parsed and used for adding multiple ontology sourcs at once. Also eliminated parameters "cusotmont" and "customreg", as ontologies are now added to the custom space using POST methods (STANBOL-682)
* In the Clerezza ontology provider, the loadInStore(Object, boolean) method now examines import statements *after* registering the importing ontology. This should break any loops that may occur when loading ontology networks that contain cyclic imports. (STANBOL-679)
* All scopes and sessions now expose their HTML ontology contents in Manchester syntax by default. Also, there are backward links to scopes and managers.
* It is now possible to create and delte scopes and sessions using the Stanbol HTML interface. For sessions, both the PUT method (client decides session ID) and the POST method (Stanbol decides the session ID) are supported, depending on whether the user supplies an ID or not. (STANBOL-683)

Added:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OntologyLoadingException.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreSpaceImpl.java
      - copied, changed from r1356657, incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomSpaceImpl.java
      - copied, changed from r1356657, incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestAxiomInterpretation.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/abox.owl
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/tbox.owl
Removed:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.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/io/GraphContentInputSource.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.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/CustomOntologySpace.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScope.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/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/owlapi/CustomOntologySpaceImpl.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyCollectors.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.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/java/org/apache/stanbol/ontologymanager/web/util/OntologyPrettyPrintResource.java
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntologyNetworkResource/index.ftl
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/ontology.ftl
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource/index.ftl
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/SessionResource/index.ftl
    incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/SessionResource/ontology.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=1359786&r1=1359785&r2=1359786&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 Jul 10 17:00:53 2012
@@ -45,6 +45,11 @@ public interface ONManager extends Scope
     String CONFIG_ONTOLOGY_PATH = "org.apache.stanbol.ontologymanager.ontonet.onconfig";
 
     /**
+     * The key used to configure the connectivity policy.
+     */
+    String CONNECTIVITY_POLICY = "org.apache.stanbol.ontologymanager.ontonet.connectivity";
+
+    /**
      * The key used to configure the ID of the ontology network manager.
      */
     String ID = "org.apache.stanbol.ontologymanager.ontonet.id";

Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OntologyLoadingException.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OntologyLoadingException.java?rev=1359786&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OntologyLoadingException.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OntologyLoadingException.java Tue Jul 10 17:00:53 2012
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+/**
+ * A runtime exception denoting that trying to load an ontology into the Ontology Manager has caused an
+ * undesired status. Most of the time the reason is to be found in the cause registered with this exception.
+ * 
+ * @author alexdma
+ * 
+ */
+public class OntologyLoadingException extends RuntimeException {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -8496827319814210715L;
+
+    /**
+     * Creates a new instance of {@link OntologyLoadingException}.
+     * 
+     * @param cause
+     *            the throwable that caused this exception to be thrown.
+     */
+    public OntologyLoadingException(Throwable cause) {
+        initCause(cause);
+    }
+
+    /**
+     * Creates a new instance of {@link OntologyLoadingException}.
+     * 
+     * @param message
+     *            the exception message.
+     */
+    public OntologyLoadingException(String message) {
+        super(message);
+    }
+
+}

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/GraphContentInputSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/GraphContentInputSource.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/GraphContentInputSource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/GraphContentInputSource.java Tue Jul 10 17:00:53 2012
@@ -16,9 +16,11 @@
  */
 package org.apache.stanbol.ontologymanager.ontonet.api.io;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
 
 import org.apache.clerezza.rdf.core.Graph;
 import org.apache.clerezza.rdf.core.MGraph;
@@ -29,6 +31,7 @@ import org.apache.clerezza.rdf.core.seri
 import org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException;
 import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
 import org.apache.stanbol.commons.owl.util.OWLUtils;
+import org.apache.stanbol.ontologymanager.ontonet.api.OntologyLoadingException;
 import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -87,14 +90,17 @@ public class GraphContentInputSource ext
 
     /**
      * Creates a new graph input source by parsing <code>content</code> (using the supplied {@link Parser})
-     * into a graph created using the supplied {@link TcProvider}, assuming it has the given format.
+     * into a graph created using the supplied {@link TcProvider}, assuming it has the given format. An
+     * {@link OntologyLoadingException} will be thrown if the parser fails.
      * 
      * @param content
      *            the serialized graph content.
      * @param formatIdentifier
-     *            the format to parse the content as.
+     *            the format to parse the content as. It cannot be null or blank.
      * @param tcProvider
-     *            the provider that will create the graph where the triples will be stored.
+     *            the provider that will create the graph where the triples will be stored. If null, an
+     *            in-memory graph will be created, in which case any ontology collectors using this input
+     *            source will most likely have to copy it to persistent storage.
      * @param parser
      *            the parser to use for creating the graph. If null, the default one will be used.
      */
@@ -106,11 +112,12 @@ public class GraphContentInputSource ext
 
         if (content == null) throw new IllegalArgumentException("No content supplied");
         if (parser == null) parser = Parser.getInstance();
+
         // No physical IRI
         bindPhysicalIri(null);
         bindTriplesProvider(tcProvider);
         boolean loaded = false;
-
+        if (content.markSupported()) content.mark(Integer.MAX_VALUE);
         Collection<String> formats;
         if (formatIdentifier == null || "".equals(formatIdentifier.trim())) formats = OntologyUtils
                 .getPreferredSupportedFormats(parser.getSupportedFormats());
@@ -120,23 +127,46 @@ public class GraphContentInputSource ext
             UriRef name = new UriRef(getClass().getCanonicalName() + "-" + System.currentTimeMillis());
             graph = tcProvider.createMGraph(name);
         } else graph = new IndexedMGraph();
-        for (String format : formats) {
+
+        Iterator<String> itf = formats.iterator();
+        if (itf.hasNext()) {
+            String f = itf.next();
             try {
-                parser.parse((MGraph) graph, content, format);
+                parser.parse((MGraph) graph, content, f);
                 loaded = true;
-                break;
             } catch (UnsupportedFormatException e) {
-                log.debug("Parsing format {} failed.", format);
-                continue;
+                log.debug("Parsing format {} failed.", f);
             } catch (Exception e) {
-                log.error("Error parsing " + format, e);
-                continue;
+                log.debug("Error parsing format " + f, e);
             }
+        } else throw new OntologyLoadingException("No suitable format defined.");
+
+        // If the first attempt failed, try all other formats if the streams allows it.
+        if (!loaded) {
+            if (content.markSupported()) for (String format : formats)
+                try {
+                    content.reset();
+                    parser.parse((MGraph) graph, content, format);
+                    loaded = true;
+                    break;
+                } catch (UnsupportedFormatException e) {
+                    log.debug("Parsing format {} failed.", format);
+                    continue;
+                } catch (IOException e) {
+                    log.debug("Failed to reset data stream while parsing format {}.", format);
+                    continue;
+                } catch (Exception e) {
+                    log.debug("Error parsing format " + format, e);
+                    continue;
+                }
+            else throw new OntologyLoadingException(
+                    "First parsing attempt failed and data stream cannot be reset. Giving up.");
         }
+
         if (loaded) {
             bindRootOntology(graph);
             log.debug("Root ontology is a {}.", getRootOntology().getClass().getCanonicalName());
-        }
+        } else throw new OntologyLoadingException("All parsers failed. Giving up.");
         log.debug("Input source initialization completed in {} ms.", (System.currentTimeMillis() - before));
     }
 

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.java Tue Jul 10 17:00:53 2012
@@ -28,14 +28,9 @@ public class RootOntologySource extends 
 
     public RootOntologySource(OWLOntology rootOntology) {
         bindRootOntology(rootOntology);
-        try {
-            bindPhysicalIri(rootOntology.getOntologyID().getDefaultDocumentIRI());
-            bindTriplesProvider(rootOntology.getOWLOntologyManager());
-        } catch (Exception e) {
-            // Ontology might be anonymous, no physical IRI then...
-            bindPhysicalIri(null);
-        }
-
+        // Never bind logical IDs as physical IRIs, as they risk overwriting previous bindings.
+        bindPhysicalIri(null);
+        bindTriplesProvider(rootOntology.getOWLOntologyManager());
     }
 
     /**

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=1359786&r1=1359785&r2=1359786&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 Jul 10 17:00:53 2012
@@ -258,12 +258,9 @@ public interface OntologyProvider<S> {
      *            the ontology content.
      * @param formatIdentifier
      *            the MIME type of the expected serialization format of this ontology. If null, all supported
-     *            formats will be tried until all parsers fail or one succeeds.
-     * @param preferredKey
-     *            a string that should preferrably identify the ontology internally within the provider. It
-     *            will be ignored if null or empty. It is not guaranteed that the supplied key can be used,
-     *            e.g. if there is already a duplicate of the key and the policy does not allow duplicates. In
-     *            this case, a different key will be set and returned by this method.
+     *            formats will be tried until all parsers fail or one succeeds. Whether the supplied format
+     *            will be the only one to be attempted, or simply the preferred one, is left to arbitration
+     *            and is implementation-dependent.
      * @param force
      *            if true, all mappings provided by the offline configuration will be ignored (both for the
      *            root ontology and its recursive imports) and the provider will forcibly try to resolve the
@@ -288,12 +285,9 @@ public interface OntologyProvider<S> {
      *            the physical IRI where the ontology is located.
      * @param formatIdentifier
      *            the MIME type of the expected serialization format of this ontology. If null, all supported
-     *            formats will be tried until all parsers fail or one succeeds.
-     * @param preferredKey
-     *            a string that should preferrably identify the ontology internally within the provider. It
-     *            will be ignored if null or empty. It is not guaranteed that the supplied key can be used,
-     *            e.g. if there is already a duplicate of the key and the policy does not allow duplicates. In
-     *            this case, a different key will be set and returned by this method.
+     *            formats will be tried until all parsers fail or one succeeds. Whether the supplied format
+     *            will be the only one to be attempted, or simply the preferred one, is left to arbitration
+     *            and is implementation-dependent.
      * @param force
      *            if true, all mappings provided by the offline configuration will be ignored (both for the
      *            root ontology and its recursive imports) and the provider will forcibly try to resolve the
@@ -314,11 +308,6 @@ public interface OntologyProvider<S> {
      * 
      * @param ontology
      *            the ontology to be stored.
-     * @param preferredKey
-     *            a string that should preferrably identify the ontology internally within the provider. It
-     *            will be ignored if null or empty. It is not guaranteed that the supplied key can be used,
-     *            e.g. if there is already a duplicate of the key and the policy does not allow duplicates. In
-     *            this case, a different key will be set and returned by this method.
      * @param force
      *            if true, all mappings provided by the offline configuration will be ignored (both for the
      *            root ontology and its recursive imports) and the provider will forcibly try to resolve the

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/CustomOntologySpace.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/CustomOntologySpace.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/CustomOntologySpace.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/CustomOntologySpace.java Tue Jul 10 17:00:53 2012
@@ -30,4 +30,13 @@ package org.apache.stanbol.ontologymanag
  */
 public interface CustomOntologySpace extends OntologySpace {
 
+    enum ConnectivityPolicy {
+        LOOSE,
+        TIGHT
+    };
+
+    ConnectivityPolicy getConnectivityPolicy();
+
+    void setConnectivityPolicy(ConnectivityPolicy policy);
+
 }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScope.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScope.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScope.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/scope/OntologyScope.java Tue Jul 10 17:00:53 2012
@@ -49,14 +49,14 @@ public interface OntologyScope extends N
      * 
      * @return the core ontology space
      */
-    OntologySpace getCoreSpace();
+    CoreOntologySpace getCoreSpace();
 
     /**
      * Returns the custom ontology space for this ontology scope.
      * 
      * @return the custom ontology space, or null if no custom space is registered for this scope.
      */
-    OntologySpace getCustomSpace();
+    CustomOntologySpace getCustomSpace();
 
     /**
      * Sets an ontology space as the custom space for this scope.
@@ -66,7 +66,7 @@ public interface OntologyScope extends N
      * @throws UnmodifiableOntologyCollectorException
      *             if either the scope or the supplied space are locked.
      */
-    void setCustomSpace(OntologySpace customSpace) throws UnmodifiableOntologyCollectorException;
+    void setCustomSpace(CustomOntologySpace customSpace) throws UnmodifiableOntologyCollectorException;
 
     /**
      * Performs the operations required for activating the ontology scope. It should be possible to perform

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=1359786&r1=1359785&r2=1359786&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 Jul 10 17:00:53 2012
@@ -30,6 +30,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyOption;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.ReferencePolicy;
@@ -47,6 +48,7 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
 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;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.NoSuchScopeException;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScopeFactory;
@@ -127,6 +129,7 @@ public class ONManagerImpl extends Scope
     }
 
     public static final String _CONFIG_ONTOLOGY_PATH_DEFAULT = "";
+    public static final String _CONNECTIVITY_POLICY_DEFAULT = "TIGHT";
     public static final String _ID_DEFAULT = "ontonet";
     public static final String _ID_SCOPE_REGISTRY_DEFAULT = "ontology";
     public static final String _ONTOLOGY_NETWORK_NS_DEFAULT = "http://localhost:8080/ontonet/";
@@ -134,6 +137,15 @@ public class ONManagerImpl extends Scope
     @Property(name = ONManager.CONFIG_ONTOLOGY_PATH, value = _CONFIG_ONTOLOGY_PATH_DEFAULT)
     private String configPath;
 
+    @Property(name = ONManager.CONNECTIVITY_POLICY, options = {
+                                                               @PropertyOption(value = '%'
+                                                                                       + ONManager.CONNECTIVITY_POLICY
+                                                                                       + ".option.tight", name = "TIGHT"),
+                                                               @PropertyOption(value = '%'
+                                                                                       + ONManager.CONNECTIVITY_POLICY
+                                                                                       + ".option.loose", name = "LOOSE")}, value = _CONNECTIVITY_POLICY_DEFAULT)
+    private String connectivityPolicyString;
+
     private Helper helper = null;
 
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -260,6 +272,13 @@ public class ONManagerImpl extends Scope
          * If there is no configuration file, just start with an empty scope set
          */
 
+        Object connectivityPolicy = configuration.get(ONManager.CONNECTIVITY_POLICY);
+        if (connectivityPolicy == null) {
+            this.connectivityPolicyString = _CONNECTIVITY_POLICY_DEFAULT;
+        } else {
+            this.connectivityPolicyString = connectivityPolicy.toString();
+        }
+
         String configPath = getOntologyNetworkConfigurationPath();
 
         if (configPath != null && !configPath.trim().isEmpty()) {
@@ -423,9 +442,22 @@ public class ONManagerImpl extends Scope
         OntologyScope scope = new OntologyScopeImpl(scopeID, IRI.create(getOntologyNetworkNamespace()
                                                                         + scopeRegistryId + "/"),
                 getOntologySpaceFactory(), coreSources);
+        if (scope.getCustomSpace() != null) {
+            CustomOntologySpace.ConnectivityPolicy policy;
+            try {
+                policy = CustomOntologySpace.ConnectivityPolicy.valueOf(connectivityPolicyString);
+            } catch (IllegalArgumentException e) {
+                log.warn("The value \""
+                         + connectivityPolicyString
+                         + "\" configured as default ConnectivityPolicy does not match any value of the Enumeration! "
+                         + "Setting the default policy as defined by the "
+                         + CustomOntologySpace.ConnectivityPolicy.class + ".");
+                policy = CustomOntologySpace.ConnectivityPolicy.valueOf(_CONNECTIVITY_POLICY_DEFAULT);
+            }
+            scope.getCustomSpace().setConnectivityPolicy(policy);
+        }
         if (scope != null) {
             // Commented out: for the time being we try not to propagate additions to scopes.
-
             // if (ontologyProvider instanceof OntologyCollectorListener) scope
             // .addOntologyCollectorListener((OntologyCollectorListener) ontologyProvider);
             fireScopeCreated(scope);
@@ -532,18 +564,31 @@ public class ONManagerImpl extends Scope
     private void rebuildScopes() {
         OntologyNetworkConfiguration struct = ontologyProvider.getOntologyNetworkConfiguration();
         for (String scopeId : struct.getScopeIDs()) {
+            long before = System.currentTimeMillis();
+            log.debug("Rebuilding scope with ID \"{}\".", scopeId);
             Collection<String> coreOnts = struct.getCoreOntologyKeysForScope(scopeId);
             OntologyInputSource<?,?>[] srcs = new OntologyInputSource<?,?>[coreOnts.size()];
             int i = 0;
-            for (String coreOnt : coreOnts)
+            for (String coreOnt : coreOnts) {
+                log.debug("Core ontology key : {}", coreOnts);
                 srcs[i++] = new GraphSource(coreOnt);
-            OntologyScope scope = new OntologyScopeImpl(scopeId, IRI.create(this
-                    .getOntologyNetworkNamespace()), this.getOntologySpaceFactory(), srcs);
+            }
+            OntologyScope scope;
+            try {
+                scope = createOntologyScope(scopeId, srcs);
+            } catch (DuplicateIDException e) {
+                String dupe = e.getDuplicateID();
+                log.warn("Tried to rebuild existing scope \"{}\". Reusing.", dupe);
+                scope = getScope(dupe);
+            }
             OntologySpace custom = scope.getCustomSpace();
             // Register even if some ontologies were to fail to be restored afterwards.
             scopeMap.put(scopeId, scope);
-            for (String key : struct.getCustomOntologyKeysForScope(scopeId))
+            for (String key : struct.getCustomOntologyKeysForScope(scopeId)) {
+                log.debug("Core ontology key : {}", key);
                 custom.addOntology(new GraphSource(key));
+            }
+            log.info("Scope \"{}\" rebuilt in {} ms.", scopeId, System.currentTimeMillis() - before);
         }
     }
 

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=1359786&r1=1359785&r2=1359786&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 Jul 10 17:00:53 2012
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.Literal;
 import org.apache.clerezza.rdf.core.MGraph;
 import org.apache.clerezza.rdf.core.NonLiteral;
 import org.apache.clerezza.rdf.core.Resource;
@@ -164,6 +165,8 @@ public abstract class AbstractOntologyCo
         if (key != null && !key.isEmpty()) {
             // add to index
             managedOntologies.add(id.getOntologyIRI());
+            // Always add sanitized version
+            managedOntologies.add(URIUtils.sanitizeID(id.getOntologyIRI()));
             // 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
@@ -272,8 +275,21 @@ public abstract class AbstractOntologyCo
                     root.addAll(g);
 
                     it = g.filter(null, OWL.imports, null);
-                    while (it.hasNext())
-                        importTargets.add(it.next().getObject());
+                    while (it.hasNext()) {
+                        IRI tgt;
+                        Resource r = it.next().getObject();
+                        try {
+                            if (r instanceof UriRef) tgt = IRI.create(((UriRef) r).getUnicodeString());
+                            else if (r instanceof Literal) tgt = IRI.create(((Literal) r).getLexicalForm());
+                            else tgt = IRI.create(r.toString());
+                            tgt = URIUtils.sanitizeID(tgt);
+                            importTargets.add(new UriRef(tgt.toString()));
+                        } catch (Exception ex) {
+                            log.error("FAILED to obtain import target from resource {}", r);
+                            continue;
+                        }
+
+                    }
 
                     it = g.filter(null, RDF.type, OWL.Ontology);
                     while (it.hasNext()) {
@@ -387,7 +403,7 @@ public abstract class AbstractOntologyCo
 
                 // The key set of managedOntologies contains the ontology IRIs, not their storage keys.
                 for (IRI ontologyIri : managedOntologies) {
-                    IRI physIRI = IRI.create(base + ontologyIri);
+                    IRI physIRI = URIUtils.sanitizeID(IRI.create(base + ontologyIri));
                     changes.add(new AddImport(root, df.getOWLImportsDeclaration(physIRI)));
                 }
 
@@ -552,7 +568,7 @@ public abstract class AbstractOntologyCo
         } else {
             // Rewrite import statements
             List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
-            OWLDataFactory df = o.getOWLOntologyManager().getOWLDataFactory();
+            OWLDataFactory df = OWLManager.getOWLDataFactory();
 
             /*
              * TODO manage import rewrites better once the container ID is fully configurable (i.e. instead of

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=1359786&r1=1359785&r2=1359786&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 Jul 10 17:00:53 2012
@@ -108,7 +108,12 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Clerezza-based ontology provider implementation. Whether it is persistent or in-memory depends on the
- * {@link TcProvider} used.
+ * {@link TcProvider} used.<br>
+ * <br>
+ * NOTE: in this implementation, the <code>preferredFormat</code> argument of the
+ * {@link #loadInStore(InputStream, String, boolean)} and {@link #loadInStore(IRI, String, boolean)} methods
+ * is not the only one to be tried when parsing an ontology, but merely the first one: should it fail, all
+ * other supported formats will be tried as a fallback.
  * 
  * @author alexdma
  * 
@@ -207,6 +212,7 @@ public class ClerezzaOntologyProvider im
          * @return
          */
         private OWLOntologyID buildOntologyId(UriRef resource) {
+            // TODO desanitize?
             IRI oiri = null, viri = null;
             Iterator<Triple> it = graph.filter(resource, new UriRef(Vocabulary.HAS_ONTOLOGY_IRI), null);
             if (it.hasNext()) {
@@ -233,8 +239,9 @@ public class ClerezzaOntologyProvider im
             // The UriRef is of the form ontologyIRI[:::versionIRI] (TODO use something less conventional?)
             IRI ontologyIRI = ontologyReference.getOntologyIRI(), versionIri = ontologyReference
                     .getVersionIRI();
-            UriRef entry = new UriRef(ontologyIRI.toString()
-                                      + ((versionIri == null) ? "" : (":::" + versionIri.toString())));
+            UriRef entry = new UriRef(URIUtils.sanitizeID(ontologyIRI).toString()
+                                      + ((versionIri == null) ? "" : (":::" + URIUtils.sanitizeID(versionIri)
+                                              .toString())));
             return entry;
         }
 
@@ -243,12 +250,21 @@ public class ClerezzaOntologyProvider im
         }
 
         UriRef getMapping(OWLOntologyID ontologyReference) {
-            Iterator<Triple> it = graph.filter(buildResource(ontologyReference), new UriRef(
-                    Vocabulary.MAPS_TO_GRAPH), null);
+            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;
             }
+            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;
+            }
             return null;
         }
 
@@ -259,6 +275,12 @@ public class ClerezzaOntologyProvider im
                 NonLiteral subj = it.next().getSubject();
                 if (subj instanceof UriRef) result.add(buildOntologyId((UriRef) subj));
             }
+            it = graph.filter(null, new UriRef(Vocabulary.RETRIEVED_FROM), null);
+            while (it.hasNext()) {
+                Resource subj = it.next().getObject();
+                if (subj instanceof UriRef) result.add(buildOntologyId((UriRef) subj));
+                else if (subj instanceof Literal) System.out.println(((Literal) subj).getLexicalForm());
+            }
             return result;
         }
 
@@ -266,7 +288,6 @@ public class ClerezzaOntologyProvider im
             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
             UriRef retrieved_from = new UriRef(Vocabulary.RETRIEVED_FROM);
-            boolean isOntology = true;
             Set<Triple> remove = new HashSet<Triple>();
             for (Iterator<Triple> nodes = graph.filter(graphName, null, null); nodes.hasNext();) {
                 Triple t = nodes.next();
@@ -493,18 +514,21 @@ public class ClerezzaOntologyProvider im
      */
     private void fillImportsReverse(UriRef importing, List<UriRef> reverseImports, List<UriRef> level1Imports) {
         log.debug("Filling reverse imports for {}", importing);
+        // Add the importing ontology first
         reverseImports.add(importing);
         if (level1Imports != null) level1Imports.add(importing);
-
         // Get the graph and explore its imports
         TripleCollection graph = store.getTriples(importing);
         Iterator<Triple> it = graph.filter(null, RDF.type, OWL.Ontology);
-        if (it.hasNext()) {
-            Iterator<Triple> it2 = graph.filter(it.next().getSubject(), OWL.imports, null);
-            while (it2.hasNext()) {
-                Resource obj = it2.next().getObject();
-                if (obj instanceof UriRef) {
-                    UriRef key = new UriRef(getKey(IRI.create(((UriRef) obj).getUnicodeString())));
+        if (!it.hasNext()) return;
+        Iterator<Triple> it2 = graph.filter(it.next().getSubject(), OWL.imports, null);
+        while (it2.hasNext()) {
+            Resource obj = it2.next().getObject();
+            if (obj instanceof UriRef) {
+                UriRef key = new UriRef(getKey(IRI.create(((UriRef) obj).getUnicodeString())));
+                // Check used for breaking cycles in the import graph.
+                // (Unoptimized, should not use contains() for stacks.)
+                if (!reverseImports.contains(key)) {
                     if (level1Imports != null) level1Imports.add(key);
                     fillImportsReverse(key, reverseImports, null);
                 }
@@ -617,7 +641,7 @@ public class ClerezzaOntologyProvider im
                             UriRef predicate = t.getPredicate();
                             if (predicate.equals(MANAGES)) {
                                 if (t.getObject() instanceof UriRef) coreOntologies.get(scopeId).add(
-                                  ((UriRef) t.getObject()).getUnicodeString());
+                                    ((UriRef) t.getObject()).getUnicodeString());
                             }
                         }
                         for (it2 = meta.filter(null, null, core_ur); it2.hasNext();) {
@@ -635,7 +659,7 @@ public class ClerezzaOntologyProvider im
                             UriRef predicate = t.getPredicate();
                             if (predicate.equals(MANAGES)) {
                                 if (t.getObject() instanceof UriRef) customOntologies.get(scopeId).add(
-                                  ((UriRef) t.getObject()).getUnicodeString());
+                                    ((UriRef) t.getObject()).getUnicodeString());
                             }
                         }
                         for (it2 = meta.filter(null, null, custom_ur); it2.hasNext();) {
@@ -643,7 +667,7 @@ public class ClerezzaOntologyProvider im
                             UriRef predicate = t.getPredicate();
                             if (predicate.equals(IS_MANAGED_BY)) {
                                 if (t.getSubject() instanceof UriRef) customOntologies.get(scopeId).add(
-                                  ((UriRef) t.getSubject()).getUnicodeString());
+                                    ((UriRef) t.getSubject()).getUnicodeString());
                             }
                         }
                     }
@@ -680,7 +704,7 @@ public class ClerezzaOntologyProvider im
                             UriRef predicate = t.getPredicate();
                             if (predicate.equals(IS_MANAGED_BY)) {
                                 if (t.getSubject() instanceof UriRef) sessionOntologies.get(sessionId).add(
-                                   ((UriRef) t.getSubject()).getUnicodeString());
+                                    ((UriRef) t.getSubject()).getUnicodeString());
                             }
                         }
                     }
@@ -795,33 +819,15 @@ public class ClerezzaOntologyProvider im
 
     @Override
     public String loadInStore(InputStream data, String formatIdentifier, boolean force) {
-
         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.");
 
-        // Force is ignored for the content, but the imports?
-
-        // Get sorted list of supported formats, or use specified one.
-        Collection<String> formats;
-        if (formatIdentifier == null || "".equals(formatIdentifier.trim())) formats = OntologyUtils
-                .getPreferredSupportedFormats(parser.getSupportedFormats());
-        else formats = Collections.singleton(formatIdentifier);
-
-        // Try each format, return on the first one that was parsed.
-        for (String format : formats) {
-            try {
-                TripleCollection rdfData = parser.parse(data, format);
-                return loadInStore(rdfData, force);
-            } catch (UnsupportedFormatException e) {
-                log.debug("Unsupported format format {}. Trying next one.", format);
-                continue;
-            } catch (Exception e) {
-                log.debug("Parsing format " + format + " failed. Trying next one.", e);
-                continue;
-            }
-        }
-        // No parser worked, return null.
-        log.error("All parsers failed, giving up.");
-        return null;
+        // This method only tries the supplied format once.
+        log.debug("Trying to parse data stream with format {}", formatIdentifier);
+        TripleCollection rdfData = parser.parse(data, formatIdentifier);
+        log.debug("SUCCESS format {}.", formatIdentifier);
+        return loadInStore(rdfData, force);
     }
 
     @Override
@@ -844,10 +850,18 @@ public class ClerezzaOntologyProvider im
 
         log.info("found {} in {}", ontologyIri, location);
 
-        Collection<String> formats;
-        if (formatIdentifier == null || "".equals(formatIdentifier.trim())) formats = OntologyUtils
-                .getPreferredSupportedFormats(parser.getSupportedFormats());
-        else formats = Collections.singleton(formatIdentifier);
+        // Get ordered list of preferred/supported formats, or use the specified one.
+        List<String> supported = OntologyUtils.getPreferredSupportedFormats(parser.getSupportedFormats());
+        List<String> formats;
+        if (formatIdentifier == null || "".equals(formatIdentifier.trim())) formats = supported;
+        else {
+            formats = new LinkedList<String>();
+            // Pre-check supported format
+            if (supported.contains(formatIdentifier)) formats.add(formatIdentifier);
+            for (String sup : supported)
+                if (sup != null && !formats.contains(sup)) formats.add(sup);
+        }
+
         for (String currentFormat : formats) {
             try {
                 final URLConnection con = location.toURI().toURL().openConnection();
@@ -865,10 +879,10 @@ public class ClerezzaOntologyProvider im
                     return key;
                 }
             } catch (UnsupportedFormatException e) {
-                log.debug("Unsupported format format {}. Trying next one.", currentFormat);
+                log.debug("FAILURE format {} (unsupported). Trying next one.", currentFormat);
                 continue;
             } catch (Exception e) {
-                log.debug("Parsing format " + currentFormat + " failed. Trying next one.", e);
+                log.debug("FAILURE format {} (parse error). Will try next one.", currentFormat);
                 continue;
             }
         }
@@ -882,7 +896,6 @@ public class ClerezzaOntologyProvider im
     public String loadInStore(Object ontology, boolean force) {
 
         if (ontology == null) throw new IllegalArgumentException("No ontology supplied.");
-
         long before = System.currentTimeMillis();
 
         TripleCollection graph; // The final graph
@@ -933,6 +946,7 @@ public class ClerezzaOntologyProvider im
          */
         UriRef uriref = new UriRef(s);
         log.debug("Storing ontology with graph ID {}", uriref);
+
         // 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
         if (!getStore().listTripleCollections().contains(uriref) || force) {
@@ -948,29 +962,6 @@ public class ClerezzaOntologyProvider im
             graph = store.getTriples(uriref);
         }
 
-        if (resolveImports) {
-            // Scan resources of type owl:Ontology, but only get the first.
-            Iterator<Triple> it = graph.filter(null, RDF.type, OWL.Ontology);
-            if (it.hasNext()) {
-                // Scan import statements for the one owl:Ontology considered.
-                Iterator<Triple> it2 = graph.filter(it.next().getSubject(), OWL.imports, null);
-                while (it2.hasNext()) {
-                    Resource obj = it2.next().getObject();
-                    if (obj instanceof UriRef) try {
-                        // TODO try locals first
-                        if (isOfflineMode()) throw new RuntimeException(
-                                "Camnnot load imported ontology " + obj
-                                        + " while Stanbol is in offline mode.");
-                        else loadInStore(IRI.create(((UriRef) obj).getUnicodeString()), null, false);
-                    } catch (UnsupportedFormatException e) {
-                        log.warn("Failed to parse format for resource " + obj, e);
-                    } catch (IOException e) {
-                        log.warn("Failed to load ontology from resource " + obj, e);
-                    }
-                }
-            }
-        }
-
         // All is already sanitized by the time we get here.
 
         // Now do the mappings
@@ -1002,7 +993,41 @@ public class ClerezzaOntologyProvider im
             keymap.setMapping(unv, uriref);
             mappedIds += " , " + unv;
         }
-        log.debug("Ontology \n\t\t{}\n\tstored with key\n\t\t{}", mappedIds, s);
+
+        // Do this AFTER registering the ontology, otherwise import cycles will cause infinite loops.
+        if (resolveImports) {
+            // Scan resources of type owl:Ontology, but only get the first.
+            Iterator<Triple> it = graph.filter(null, RDF.type, OWL.Ontology);
+            if (it.hasNext()) {
+                // Scan import statements for the one owl:Ontology considered.
+                Iterator<Triple> it2 = graph.filter(it.next().getSubject(), OWL.imports, null);
+                while (it2.hasNext()) {
+                    Resource obj = it2.next().getObject();
+                    log.info("Resolving import {}", obj);
+                    if (obj instanceof UriRef) try {
+                        // TODO try locals first
+                        if (isOfflineMode()) throw new RuntimeException(
+                                "Cannot load imported ontology " + obj + " while Stanbol is in offline mode.");
+                        else {
+                            UriRef target = (UriRef) obj;
+                            OWLOntologyID id = new OWLOntologyID(IRI.create(target.getUnicodeString()));
+                            if (keymap.getMapping(id) == null) {
+                                loadInStore(IRI.create(((UriRef) obj).getUnicodeString()), null, false);
+                            }
+                        }
+                    } catch (UnsupportedFormatException e) {
+                        log.warn("Failed to parse format for resource " + obj, e);
+                    } catch (IOException e) {
+                        log.warn("Failed to load ontology from resource " + obj, e);
+                    }
+                }
+            }
+        }
+
+        log.debug("Ontology");
+        log.debug("--- {}", mappedIds);
+        log.debug("--- stored with key");
+        log.debug("--- {}", s);
         log.debug("Time: {} ms", (System.currentTimeMillis() - before));
         return s;
 

Copied: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreSpaceImpl.java (from r1356657, incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreSpaceImpl.java?p2=incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreSpaceImpl.java&p1=incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java&r1=1356657&r2=1359786&rev=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreSpaceImpl.java Tue Jul 10 17:00:53 2012
@@ -26,7 +26,7 @@ import org.semanticweb.owlapi.model.IRI;
  * @author alexdma
  * 
  */
-public class CoreOntologySpaceImpl extends AbstractOntologySpaceImpl implements CoreOntologySpace {
+public class CoreSpaceImpl extends AbstractOntologySpaceImpl implements CoreOntologySpace {
 
     public static final String SUFFIX = SpaceType.CORE.getIRISuffix();
 
@@ -34,7 +34,7 @@ public class CoreOntologySpaceImpl exten
         return (scopeID != null ? scopeID : "") + "/" + SUFFIX;
     }
 
-    public CoreOntologySpaceImpl(String scopeID, IRI namespace, OntologyProvider<?> ontologyProvider) {
+    public CoreSpaceImpl(String scopeID, IRI namespace, OntologyProvider<?> ontologyProvider) {
         super(buildId(scopeID), namespace, SpaceType.CORE, ontologyProvider);
     }
 

Copied: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomSpaceImpl.java (from r1356657, incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomSpaceImpl.java?p2=incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomSpaceImpl.java&p1=incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.java&r1=1356657&r2=1359786&rev=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomSpaceImpl.java Tue Jul 10 17:00:53 2012
@@ -16,9 +16,23 @@
  */
 package org.apache.stanbol.ontologymanager.ontonet.impl.clerezza;
 
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+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.ontologymanager.ontonet.api.ontology.OntologyProvider;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.CustomOntologySpace;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.AddImport;
 import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
 
 /**
  * Default implementation of custom ontology space.
@@ -26,7 +40,7 @@ import org.semanticweb.owlapi.model.IRI;
  * @author alexdma
  * 
  */
-public class CustomOntologySpaceImpl extends AbstractOntologySpaceImpl implements CustomOntologySpace {
+public class CustomSpaceImpl extends AbstractOntologySpaceImpl implements CustomOntologySpace {
 
     public static final String SUFFIX = SpaceType.CUSTOM.getIRISuffix();
 
@@ -34,10 +48,69 @@ public class CustomOntologySpaceImpl ext
         return (scopeID != null ? scopeID : "") + "/" + SUFFIX;
     }
 
-    public CustomOntologySpaceImpl(String scopeID, IRI namespace, OntologyProvider<?> ontologyProvider) {
+    private ConnectivityPolicy policy;
+
+    public CustomSpaceImpl(String scopeID, IRI namespace, OntologyProvider<?> ontologyProvider) {
         super(buildId(scopeID), namespace, SpaceType.CUSTOM, ontologyProvider);
     }
 
+    @Override
+    public ConnectivityPolicy getConnectivityPolicy() {
+        return policy;
+    }
+
+    @Override
+    protected MGraph getOntologyAsMGraph(IRI ontologyIri, boolean merge) {
+        MGraph o = super.getOntologyAsMGraph(ontologyIri, merge);
+        switch (getConnectivityPolicy()) {
+            case LOOSE:
+                break;
+            case TIGHT:
+                Set<NonLiteral> onts = new HashSet<NonLiteral>(); // Expected to be a singleton
+                synchronized (o) {
+                    Iterator<Triple> it = o.filter(null, RDF.type, OWL.Ontology);
+                    while (it.hasNext())
+                        onts.add(it.next().getSubject());
+                }
+                String s = getID();
+                s = s.substring(0, s.indexOf(SUFFIX)); // strip "custom"
+                s += SpaceType.CORE.getIRISuffix(); // concatenate "core"
+                UriRef target = new UriRef(getNamespace() + s);
+                for (NonLiteral subject : onts)
+                    o.add(new TripleImpl(subject, OWL.imports, target));
+                break;
+            default:
+                break;
+        }
+        return o;
+
+    }
+
+    @Override
+    protected OWLOntology getOntologyAsOWLOntology(IRI ontologyIri, boolean merge) {
+        OWLOntology o = super.getOntologyAsOWLOntology(ontologyIri, merge);
+        switch (getConnectivityPolicy()) {
+            case LOOSE:
+                break;
+            case TIGHT:
+                String s = getID();
+                s = s.substring(0, s.indexOf(SUFFIX)); // strip "custom"
+                s += SpaceType.CORE.getIRISuffix(); // concatenate "core"
+                IRI target = IRI.create(getNamespace() + s);
+                o.getOWLOntologyManager().applyChange(
+                    new AddImport(o, OWLManager.getOWLDataFactory().getOWLImportsDeclaration(target)));
+                break;
+            default:
+                break;
+        }
+        return o;
+    }
+
+    @Override
+    public void setConnectivityPolicy(ConnectivityPolicy policy) {
+        this.policy = policy;
+    }
+
     /**
      * Once it is set up, a custom space is write-locked.
      */

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java Tue Jul 10 17:00:53 2012
@@ -58,7 +58,7 @@ public class OntologySpaceFactoryImpl im
 
     public OntologySpaceFactoryImpl() {
         super();
-    };
+    }
 
     public OntologySpaceFactoryImpl(OntologyProvider<TcProvider> provider,
                                     Dictionary<String,Object> configuration) {
@@ -125,7 +125,7 @@ public class OntologySpaceFactoryImpl im
 
     @Override
     public CoreOntologySpace createCoreOntologySpace(String scopeId, OntologyInputSource<?,?>... coreSources) {
-        CoreOntologySpace s = new CoreOntologySpaceImpl(scopeId, namespace, ontologyProvider);
+        CoreOntologySpace s = new CoreSpaceImpl(scopeId, namespace, ontologyProvider);
         configureSpace(s, scopeId, coreSources);
         return s;
     }
@@ -133,7 +133,7 @@ public class OntologySpaceFactoryImpl im
     @Override
     public CustomOntologySpace createCustomOntologySpace(String scopeId,
                                                          OntologyInputSource<?,?>... customSources) {
-        CustomOntologySpace s = new CustomOntologySpaceImpl(scopeId, namespace, ontologyProvider);
+        CustomOntologySpace s = new CustomSpaceImpl(scopeId, namespace, ontologyProvider);
         configureSpace(s, scopeId, customSources);
         return s;
     }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/OntologyScopeImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/OntologyScopeImpl.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/OntologyScopeImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/OntologyScopeImpl.java Tue Jul 10 17:00:53 2012
@@ -297,12 +297,12 @@ public class OntologyScopeImpl implement
     }
 
     @Override
-    public OntologySpace getCoreSpace() {
+    public CoreOntologySpace getCoreSpace() {
         return coreSpace;
     }
 
     @Override
-    public OntologySpace getCustomSpace() {
+    public CustomOntologySpace getCustomSpace() {
         return customSpace;
     }
 
@@ -350,7 +350,7 @@ public class OntologyScopeImpl implement
     }
 
     @Override
-    public synchronized void setCustomSpace(OntologySpace customSpace) throws UnmodifiableOntologyCollectorException {
+    public synchronized void setCustomSpace(CustomOntologySpace customSpace) throws UnmodifiableOntologyCollectorException {
         if (this.customSpace != null && this.customSpace.isLocked()) throw new UnmodifiableOntologyCollectorException(
                 getCustomSpace());
         else if (!(customSpace instanceof CustomOntologySpace)) throw new ClassCastException(

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/owlapi/CustomOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/owlapi/CustomOntologySpaceImpl.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/owlapi/CustomOntologySpaceImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/owlapi/CustomOntologySpaceImpl.java Tue Jul 10 17:00:53 2012
@@ -34,6 +34,8 @@ public class CustomOntologySpaceImpl ext
         return (scopeID != null ? scopeID : "") + "/" + SUFFIX;
     }
 
+    private ConnectivityPolicy policy;
+
     public CustomOntologySpaceImpl(String scopeID, IRI namespace) {
         super(buildId(scopeID), namespace, SpaceType.CUSTOM);
     }
@@ -42,6 +44,16 @@ public class CustomOntologySpaceImpl ext
         super(buildId(scopeID), namespace, SpaceType.CUSTOM, ontologyManager);
     }
 
+    @Override
+    public ConnectivityPolicy getConnectivityPolicy() {
+        return policy;
+    }
+
+    @Override
+    public void setConnectivityPolicy(ConnectivityPolicy policy) {
+        this.policy = policy;
+    }
+
     /**
      * Once it is set up, a custom space is write-locked.
      */

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties Tue Jul 10 17:00:53 2012
@@ -25,9 +25,16 @@ org.apache.stanbol.ontologymanager.onton
 org.apache.stanbol.ontologymanager.ontonet.ns.name = Ontology network namespace
 org.apache.stanbol.ontologymanager.ontonet.ns.description = The base namespace that should be used to identify components across the Stanbol ontology network e.g. scopes and spaces. It can be overridden programmatically.
 
-org.apache.stanbol.ontologymanager.ontonet.onconfig.name = Configuration ontology
-org.apache.stanbol.ontologymanager.ontonet.onconfig.description = The physical location of the ontology storing the configuration of the Stanbol ontology network. Can be an absolute URI or a file path (either absolute or relative to the bundle resource directory).
+org.apache.stanbol.ontologymanager.ontonet.onconfig.name = Configuration override ontology
+org.apache.stanbol.ontologymanager.ontonet.onconfig.description = The physical location of the ontology that overrides the Stanbol ontology network configuration. Can be an absolute URI or a file path (either absolute or relative to the bundle resource directory).
 
+org.apache.stanbol.ontologymanager.ontonet.connectivity.name = Scope connectivity policy
+org.apache.stanbol.ontologymanager.ontonet.connectivity.description = Determines the amount of import statements that will connect managed ontologies with scopes when they are exported to OWL.
+org.apache.stanbol.ontologymanager.ontonet.connectivity.option.loose = Loose (only the custom space imports the core space)
+org.apache.stanbol.ontologymanager.ontonet.connectivity.option.tight = Tight (every custom ontology imports the core space)
+
+org.apache.stanbol.ontologymanager.ontonet.scopeRegistry.id.name = Scope registry ID
+org.apache.stanbol.ontologymanager.ontonet.scopeRegistry.id.description = An identifier for the scope registry. It will be part of the prefix for all scope IRIs, as well as the Stanbol endpoint for managing them.
 
 #===============================================================================
 #Properties defined by the Ontology Manager offline configuration
@@ -38,7 +45,6 @@ org.apache.stanbol.ontologymanager.onton
 org.apache.stanbol.ontologymanager.ontonet.ontologypaths.name = Ontology directories
 org.apache.stanbol.ontologymanager.ontonet.ontologypaths.description = The local directories for ontology sources.
 
-
 #===============================================================================
 #Properties defined by the Ontology Provider
 #===============================================================================

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyCollectors.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyCollectors.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyCollectors.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyCollectors.java Tue Jul 10 17:00:53 2012
@@ -94,7 +94,7 @@ public class TestOntologyCollectors {
 
         OWLOntology original = src.getRootOntology();
         Assert.assertNotNull(original);
-        OntologySpace spc = new CustomOntologySpaceImpl("Test", scopeNs, ontologyProvider);
+        OntologySpace spc = new CustomSpaceImpl("Test", scopeNs, ontologyProvider);
         spc.addOntology(src);
 
     }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.java Tue Jul 10 17:00:53 2012
@@ -39,7 +39,7 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpace;
 import org.apache.stanbol.ontologymanager.ontonet.impl.OfflineConfigurationImpl;
 import org.apache.stanbol.ontologymanager.ontonet.impl.clerezza.ClerezzaOntologyProvider;
-import org.apache.stanbol.ontologymanager.ontonet.impl.clerezza.CoreOntologySpaceImpl;
+import org.apache.stanbol.ontologymanager.ontonet.impl.clerezza.CoreSpaceImpl;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -87,7 +87,7 @@ public class TestClerezzaInputSources {
         for (UriRef name : tcManager.listTripleCollections())
             log.info("-- {} (a {})", name, tcManager.getTriples(name).getClass().getSimpleName());
         assertEquals(1, tcManager.listTripleCollections().size());
-        OntologySpace spc = new CoreOntologySpaceImpl(TestClerezzaInputSources.class.getSimpleName(),
+        OntologySpace spc = new CoreSpaceImpl(TestClerezzaInputSources.class.getSimpleName(),
                 IRI.create("http://stanbol.apache.org/ontologies/"), provider);
         spc.addOntology(src);
         log.info("After addition to space, TcManager has {} graphs. ", tcManager.listTripleCollections()

Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestAxiomInterpretation.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestAxiomInterpretation.java?rev=1359786&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestAxiomInterpretation.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestAxiomInterpretation.java Tue Jul 10 17:00:53 2012
@@ -0,0 +1,70 @@
+/*
+ * 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.ontology;
+
+import static org.apache.stanbol.ontologymanager.ontonet.MockOsgiContext.onManager;
+import static org.apache.stanbol.ontologymanager.ontonet.MockOsgiContext.reset;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphContentInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestAxiomInterpretation {
+
+    @BeforeClass
+    public static void setup() throws Exception {
+        reset();
+    }
+
+    @Test
+    public void testCustomAboxCoreTbox() throws Exception {
+        String path = "/ontologies/imports-disconnected";
+
+        InputStream content = getClass().getResourceAsStream(path + "/abox.owl");
+        OntologyInputSource<?,?> coreSrc = new GraphContentInputSource(content, SupportedFormat.TURTLE);
+        OntologyScope scope = onManager.createOntologyScope("imports-disconnected", coreSrc);
+        assertNotNull(scope);
+
+        content = getClass().getResourceAsStream(path + "/tbox.owl");
+        OntologyInputSource<?,?> custSrc = new GraphContentInputSource(content, SupportedFormat.TURTLE);
+        scope.getCustomSpace().addOntology(custSrc);
+
+        Graph g = scope.export(Graph.class, true);
+
+        // for (Triple t : g)
+        // System.out.println(t);
+        //
+        // OWLOntology o = scope.export(OWLOntology.class, true);
+        // for (OWLAxiom ax : o.getAxioms())
+        // System.out.println(ax);
+
+    }
+
+    @After
+    public void cleanup() throws Exception {
+        reset();
+    }
+
+}

Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/abox.owl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/abox.owl?rev=1359786&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/abox.owl (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/abox.owl Tue Jul 10 17:00:53 2012
@@ -0,0 +1,14 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix : <http://www.ontologydesignpatterns.org/ont/test/ontonet#> .
+@prefix xml: <http://www.w3.org/XML/1998/namespace> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@base <http://www.ontologydesignpatterns.org/ont/test/ontonet/imports-disconnected/abox.owl> .
+
+<http://www.ontologydesignpatterns.org/ont/test/ontonet/imports-disconnected/abox.owl> rdf:type owl:Ontology .
+
+:Alex a :Person ; 
+      :knows :Begona .
+      
+:Begona a :Person .

Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/tbox.owl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/tbox.owl?rev=1359786&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/tbox.owl (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/imports-disconnected/tbox.owl Tue Jul 10 17:00:53 2012
@@ -0,0 +1,11 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix : <http://www.ontologydesignpatterns.org/ont/test/ontonet#> .
+@prefix xml: <http://www.w3.org/XML/1998/namespace> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@base <http://www.ontologydesignpatterns.org/ont/test/ontonet/imports-disconnected/tbox.owl> .
+
+<http://www.ontologydesignpatterns.org/ont/test/ontonet/imports-disconnected/tbox.owl> rdf:type owl:Ontology .
+
+:knows a owl:ObjectProperty .

Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java?rev=1359786&r1=1359785&r2=1359786&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java Tue Jul 10 17:00:53 2012
@@ -51,6 +51,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -91,7 +93,7 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
 import org.apache.stanbol.ontologymanager.registry.api.model.Library;
 import org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource;
-import org.coode.owlapi.turtle.TurtleOntologyFormat;
+import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat;
 import org.semanticweb.owlapi.model.AddImport;
 import org.semanticweb.owlapi.model.IRI;
 import org.semanticweb.owlapi.model.OWLDataFactory;
@@ -369,7 +371,7 @@ public class OntoNetRootResource extends
     @Produces({TEXT_HTML, TEXT_PLAIN, RDF_XML, TURTLE, X_TURTLE, N3})
     public Response postOntology(FormDataMultiPart data, @Context HttpHeaders headers) {
         log.debug(" post(FormDataMultiPart data)");
-        ResponseBuilder rb;
+        ResponseBuilder rb = null;
 
         IRI location = null;
         File file = null; // If found, it takes precedence over location.
@@ -393,19 +395,45 @@ public class OntoNetRootResource extends
         // Then add the file
         String key = null;
         if (file != null && file.canRead() && file.exists()) {
-            try {
-                InputStream content = new FileInputStream(file);
-                key = ontologyProvider.loadInStore(content, format, true);
-            } catch (UnsupportedFormatException e) {
-                log.warn(
-                    "POST method failed for media type {}. This should not happen (should fail earlier)",
-                    headers.getMediaType());
-                rb = Response.status(UNSUPPORTED_MEDIA_TYPE);
-            } catch (IOException e) {
-                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+
+            /*
+             * Because the ontology provider's load method could fail after only one attempt without resetting
+             * the stream, we might have to do that ourselves.
+             */
+
+            List<String> formats;
+            if (format != null && !format.trim().isEmpty()) formats = Collections.singletonList(format);
+            else // The RESTful API has its own list of preferred formats
+            formats = Arrays.asList(new String[] {RDF_XML, TURTLE, X_TURTLE, N3, N_TRIPLE, OWL_XML,
+                                                  FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON});
+            int unsupported = 0, failed = 0;
+            for (String f : formats)
+                try {
+                    // Re-instantiate the stream on every attempt
+                    InputStream content = new FileInputStream(file);
+                    key = ontologyProvider.loadInStore(content, f, true);
+                } catch (UnsupportedFormatException e) {
+                    log.warn(
+                        "POST method failed for media type {}. This should not happen (should fail earlier)",
+                        headers.getMediaType());
+                    // rb = Response.status(UNSUPPORTED_MEDIA_TYPE);
+                    unsupported++;
+                    continue;
+                } catch (IOException e) {
+                    log.debug(">>> FAILURE format {} (I/O error)", f);
+                    failed++;
+                    continue;
+                } catch (Exception e) { // SAXParseException and others
+                    log.debug(">>> FAILURE format {} (parse error)", f);
+                    failed++;
+                    continue;
+                }
+            if (key == null || key.trim().isEmpty()) {
+                if (failed > 0) throw new WebApplicationException(BAD_REQUEST);
+                else if (unsupported > 0) throw new WebApplicationException(UNSUPPORTED_MEDIA_TYPE);
             }
         } else if (location != null) {
-            try {
+            try { // Here we try every format supported by the Java API
                 key = ontologyProvider.loadInStore(location, null, true);
             } catch (Exception e) {
                 log.error("Failed to load ontology from " + location, e);
@@ -441,7 +469,7 @@ public class OntoNetRootResource extends
             if (o == null) rb = Response.status(NOT_FOUND);
             else try {
                 ByteArrayOutputStream out = new ByteArrayOutputStream();
-                o.getOWLOntologyManager().saveOntology(o, new TurtleOntologyFormat(), out);
+                o.getOWLOntologyManager().saveOntology(o, new ManchesterOWLSyntaxOntologyFormat(), out);
                 rb = Response.ok(new Viewable("ontology", new OntologyPrettyPrintResource(servletContext,
                         uriInfo, out)));
             } catch (OWLOntologyStorageException e) {
@@ -480,7 +508,7 @@ public class OntoNetRootResource extends
                     headers.getMediaType());
                 rb = Response.status(UNSUPPORTED_MEDIA_TYPE);
             } catch (IOException e) {
-                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+                throw new WebApplicationException(e, BAD_REQUEST);
             }
             // An exception should have been thrown earlier, but just in case.
             if (key == null || key.isEmpty()) rb = Response.status(Status.INTERNAL_SERVER_ERROR);