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/07/27 18:50:32 UTC

svn commit: r1151531 - in /incubator/stanbol/trunk/ontologymanager: ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ registry/src/main/java/org/apache/stanbol/o...

Author: alexdma
Date: Wed Jul 27 16:50:29 2011
New Revision: 1151531

URL: http://svn.apache.org/viewvc?rev=1151531&view=rev
Log:
- OfflineConfiguration now computes and returns IRIs straight away (STANBOL-178)
- Moved distributed caching to the level of libraries (TODO manage multiple ontology instances). As a consequence, load balancing is no longer needed. (STANBOL-285)
- Deprecated RegistryLoader and its implementation. Currently only the RegistryIRISource is using it (TODO deprecate RegistryIRISource as well, once the RESTful API is agreed upon). (STANBOL-285)

Added:
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryItemIndex.java
Modified:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OfflineConfiguration.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/OfflineConfigurationImpl.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryLoader.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Library.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Registry.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryLoaderImpl.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryManagerImpl.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java
    incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java
    incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java
    incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OfflineConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OfflineConfiguration.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OfflineConfiguration.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/OfflineConfiguration.java Wed Jul 27 16:50:29 2011
@@ -18,6 +18,8 @@ package org.apache.stanbol.ontologymanag
 
 import java.util.List;
 
+import org.semanticweb.owlapi.model.IRI;
+
 /**
  * Provides the configuration needed for the {@link ONManager}. A configuration should only be handled
  * internally by the {@link ONManager} implementation.
@@ -38,6 +40,6 @@ public interface OfflineConfiguration {
      * 
      * @return an ordered list of directory paths for offline ontologies.
      */
-    List<String> getOntologySourceDirectories();
+    List<IRI> getOntologySourceLocations();
 
 }

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=1151531&r1=1151530&r2=1151531&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 Wed Jul 27 16:50:29 2011
@@ -287,7 +287,8 @@ public class ONManagerImpl implements ON
         // Bind components, starting with the local directories.
         List<String> dirs = new ArrayList<String>();
         try {
-            dirs = config.getOntologySourceDirectories();
+            for (IRI iri : config.getOntologySourceLocations())
+                dirs.add(iri.toString());
         } catch (NullPointerException ex) {
             // Ok, go empty
         }

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/OfflineConfigurationImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/OfflineConfigurationImpl.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/OfflineConfigurationImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/OfflineConfigurationImpl.java Wed Jul 27 16:50:29 2011
@@ -16,7 +16,8 @@
  */
 package org.apache.stanbol.ontologymanager.ontonet.impl;
 
-import java.util.Arrays;
+import java.io.File;
+import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.List;
 
@@ -27,14 +28,12 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
 import org.osgi.service.component.ComponentContext;
+import org.semanticweb.owlapi.model.IRI;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Default implementation of the {@link OfflineConfiguration}.
- * 
- * @author alessandro
- * 
  */
 @Component(immediate = true, metatype = true)
 @Service
@@ -48,6 +47,8 @@ public class OfflineConfigurationImpl im
     @Property(name = OfflineConfiguration.ONTOLOGY_PATHS, value = {".", "/ontologies"})
     private String[] ontologyDirs;
 
+    private List<IRI> locations = new ArrayList<IRI>();
+
     /**
      * This default constructor is <b>only</b> intended to be used by the OSGI environment with Service
      * Component Runtime support.
@@ -83,6 +84,28 @@ public class OfflineConfigurationImpl im
         ontologyDirs = (String[]) configuration.get(OfflineConfiguration.ONTOLOGY_PATHS);
         if (ontologyDirs == null) ontologyDirs = new String[] {".", "/ontologies"};
 
+        for (String path : ontologyDirs) {
+            IRI iri = null;
+            if (path.startsWith("/")) {
+                try {
+                    iri = IRI.create(getClass().getResource(path));
+                } catch (Exception e) {
+                    // TODO: Don't give up. It could still an absolute path.
+                }
+            } else try {
+                iri = IRI.create(path);
+            } catch (Exception e1) {
+                try {
+                    iri = IRI.create(new File(path));
+                } catch (Exception e2) {
+                    log.warn("Unable to obtain a path for {}. Skipping...", iri, e2);
+                    iri = null;
+                }
+            }
+            if (iri != null) locations.add(iri);
+        }
+        // else location stays empty.
+
     }
 
     @Deactivate
@@ -92,8 +115,8 @@ public class OfflineConfigurationImpl im
     }
 
     @Override
-    public List<String> getOntologySourceDirectories() {
-        return Arrays.asList(ontologyDirs);
+    public List<IRI> getOntologySourceLocations() {
+        return locations;
     }
 
 }

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryItemIndex.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryItemIndex.java?rev=1151531&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryItemIndex.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryItemIndex.java Wed Jul 27 16:50:29 2011
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.ontologymanager.registry.api;
+
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.registry.api.model.Library;
+import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
+import org.semanticweb.owlapi.model.IRI;
+
+public interface RegistryItemIndex {
+
+    /**
+     * Returns all the libraries managed by this object.
+     * 
+     * @return the set of all managed libraries.
+     */
+    Set<Library> getLibraries();
+
+    /**
+     * Returns all the libraries that contain the ontology with the given identifier.
+     * 
+     * @param ontologyID
+     *            the ontology identifier.
+     * @return the set of libraries that contain the ontology.
+     */
+    Set<Library> getLibraries(IRI ontologyID);
+
+    /**
+     * Returns the library with the given identifier, if present.<br/>
+     * <br/>
+     * NOTE THAT IF THE REGISTRY ITEM EXIST BUT IS NOT A LIBRARY, THIS METHOD WILL RETURN NULL.
+     * 
+     * @param id
+     *            the library identifier.
+     * @return the library with the given identifier, or null if not present or not a library.
+     */
+    Library getLibrary(IRI id);
+
+    /**
+     * Returns all the registries managed by this object.
+     * 
+     * @return the set of all managed registries.
+     */
+    Set<Registry> getRegistries();
+
+    /**
+     * Returns all the registries that reference the library with the given identifier.
+     * 
+     * @return the set of all managed registries.
+     */
+    Set<Registry> getRegistries(IRI libraryID);
+
+    /**
+     * Returns the registry with the given identifier, if present.<br/>
+     * <br/>
+     * NOTE THAT IF THE REGISTRY ITEM EXIST BUT IS NOT A REGISTRY, THIS METHOD WILL RETURN NULL.
+     * 
+     * @param id
+     *            the registry identifier.
+     * @return the registry with the given identifier, or null if not present.
+     */
+    Registry getRegistry(IRI id);
+
+}

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryLoader.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryLoader.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryLoader.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryLoader.java Wed Jul 27 16:50:29 2011
@@ -32,11 +32,14 @@ import org.semanticweb.owlapi.model.OWLO
  * <br/>
  * TODO will be dismissed along with its implementation in favor of the new registry management.
  */
+@Deprecated
 public interface RegistryLoader {
 
     /**
      * Loads all the OWL ontologies referenced by <code>registryItem</code>.
      * 
+     * @deprecated
+     * 
      * @param registryItem
      *            the parent registry item.
      * @param manager
@@ -73,29 +76,31 @@ public interface RegistryLoader {
      * Only extracts the ontologies belonging to the library specified, if found in the registry at the
      * supplied location.
      * 
-     * @param registryPhysicalRIRI
-     * @param libraryID
-     * @return
+     * 
      * @deprecated This method does not what is supposed to do (ontology loading is selective, not model
      *             construction). Calls to this method should be replaced by the sequence:
      *             {@link RegistryManager#createModel(Set)} and {@link RegistryManager#getRegistry(IRI)}.
+     * 
+     * @param registryPhysicalRIRI
+     * @param libraryID
+     * @return
      */
     Registry loadLibrary(IRI registryPhysicalIRI, IRI libraryID);
 
     /**
-     * 
-     * @throws RegistryContentException
      * @deprecated obsolete
+     * @throws RegistryContentException
      */
     void loadLocations() throws RegistryContentException;
 
     /**
      * The ontology at <code>physicalIRI</code> may in turn include more than one library.
      * 
-     * @param physicalIRI
-     * @return
      * @deprecated Calls to this method should be replaced by the sequence:
      *             {@link RegistryManager#createModel(Set)} and {@link RegistryManager#getRegistry(IRI)}.
+     * 
+     * @param physicalIRI
+     * @return
      */
     Registry loadRegistry(IRI registryPhysicalIRI, OWLOntologyManager mgr);
 }

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java Wed Jul 27 16:50:29 2011
@@ -18,6 +18,7 @@ package org.apache.stanbol.ontologymanag
 
 import java.util.Set;
 
+import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
 import org.apache.stanbol.ontologymanager.registry.api.model.CachingPolicy;
 import org.apache.stanbol.ontologymanager.registry.api.model.Library;
 import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
@@ -28,7 +29,7 @@ import org.semanticweb.owlapi.model.OWLO
 /**
  * Replacement for {@link RegistryLoader}. Also indexes libraries (and ontologies?).
  */
-public interface RegistryManager {
+public interface RegistryManager extends RegistryItemIndex {
 
     /**
      * The key used to configure the caching policy of the registry manager.
@@ -84,39 +85,7 @@ public interface RegistryManager {
      */
     CachingPolicy getCachingPolicy();
 
-    /**
-     * Returns all the libraries that contain the ontology with the given identifier.
-     * 
-     * @param ontologyID
-     *            the ontology identifier.
-     * @return the set of libraries that contain the ontology.
-     */
-    Set<Library> getLibraries(IRI ontologyID);
-
-    /**
-     * Returns the set of registries managed by this object.
-     * 
-     * @return the set of all managed registries.
-     */
-    Set<Registry> getRegistries();
-
-    /**
-     * Returns all the registries that reference the library with the given identifier.
-     * 
-     * @return the set of all managed registries.
-     */
-    Set<Registry> getRegistries(IRI libraryID);
-
-    /**
-     * Returns the registry with the given identifier, if present.<br/>
-     * <br/>
-     * NOTE THAT IF THE REGISTRY ITEM EXIST BUT IS NOT A REGISTRY, THIS METHOD WILL RETURN NULL.
-     * 
-     * @param id
-     *            the registry identifier.
-     * @return the registry with the given identifier, or null if not present.
-     */
-    Registry getRegistry(IRI id);
+    OfflineConfiguration getOfflineConfiguration();
 
     /**
      * Determines if the registry manager is set to load its resources only when a specific request for them
@@ -135,7 +104,7 @@ public interface RegistryManager {
      *            the ontology registry to be removed.
      */
     void removeRegistry(IRI registryId);
-
+    
     /**
      * Sets the resource loading policy of this registry manager. There is no guarantee that setting a policy
      * after a model has already been created will affect the existing model (i.e. unload all its ontologies

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Library.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Library.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Library.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Library.java Wed Jul 27 16:50:29 2011
@@ -33,6 +33,13 @@ public interface Library extends Registr
     final Type type = Type.LIBRARY;
 
     /**
+     * Returns the OWL ontology manager that this library is using as a cache of its ontologies.
+     * 
+     * @return the ontology manager that is used as a cache.
+     */
+    OWLOntologyManager getCache();
+
+    /**
      * Returns the OWL ontologies that have been loaded in this library, if any, otherwise an exception is
      * thrown.<br/>
      * <br/>
@@ -65,4 +72,13 @@ public interface Library extends Registr
      */
     void loadOntologies(OWLOntologyManager mgr);
 
+    /**
+     * Sets the OWL ontology manager that this library will use as a cache of its ontologies. If null, if will
+     * create its own.
+     * 
+     * @param cache
+     *            the ontology manager to be used as a cache.
+     */
+    void setCache(OWLOntologyManager cache);
+
 }

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Registry.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Registry.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Registry.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/model/Registry.java Wed Jul 27 16:50:29 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.stanbol.ontologymanager.registry.api.model;
 
-import org.semanticweb.owlapi.model.OWLOntologyManager;
-
 /**
  * An ontology registry can reference zero or more ontology libraries.
  */
@@ -28,19 +26,4 @@ public interface Registry extends Regist
      */
     final Type type = Type.REGISTRY;
 
-    /**
-     * Returns the OWL ontology manager that this registry is using as a cache of its ontologies.
-     * 
-     * @return the ontology manager that is used as a cache.
-     */
-    OWLOntologyManager getCache();
-
-    /**
-     * Sets the OWL ontology manager that this registry will use as a cache of its ontologies. If null, if
-     * will create its own.
-     * 
-     * @param cache
-     *            the ontology manager to be used as a cache.
-     */
-    void setCache(OWLOntologyManager cache);
 }

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryLoaderImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryLoaderImpl.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryLoaderImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryLoaderImpl.java Wed Jul 27 16:50:29 2011
@@ -72,6 +72,7 @@ import org.slf4j.LoggerFactory;
  * <br/>
  * TODO will be dismissed along with its interface in favor of the new registry management.
  */
+@Deprecated
 public class RegistryLoaderImpl implements RegistryLoader {
 
     private static final OWLClass cRegistryLibrary;
@@ -493,7 +494,7 @@ public class RegistryLoaderImpl implemen
 
     @Override
     public Registry loadRegistry(IRI registryPhysicalIRI, OWLOntologyManager mgr) {
-        // FIXME! linbraryID unused
+        // FIXME! libraryID unused
         Registry registry = null;
         if (mgr == null) mgr = onm.getOwlCacheManager();
         try {

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryManagerImpl.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryManagerImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/RegistryManagerImpl.java Wed Jul 27 16:50:29 2011
@@ -16,13 +16,10 @@
  */
 package org.apache.stanbol.ontologymanager.registry.impl;
 
-import java.io.File;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -180,32 +177,15 @@ public class RegistryManagerImpl impleme
             this.cachingPolicyString = cachingPolicy.toString();
         }
 
-        List<String> paths = offline.getOntologySourceDirectories();
         final IRI[] offlineResources;
-        if (paths != null) {
-            List<IRI> list = new ArrayList<IRI>();
-            for (String path : paths) {
-                IRI iri = null;
-                if (path.startsWith("/")) {
-                    try {
-                        iri = IRI.create(getClass().getResource(path));
-                    } catch (Exception e) {
-                        // TODO: Don't give up. It could still an absolute path.
-                    }
-                } else try {
-                    iri = IRI.create(path);
-                } catch (Exception e1) {
-                    try {
-                        iri = IRI.create(new File(path));
-                    } catch (Exception e2) {
-                        log.warn("Unable to obtain a path for {}. Skipping...", iri, e2);
-                        iri = null;
-                    }
-                }
-                if (iri != null) list.add(iri);
-            }
-            offlineResources = list.toArray(new IRI[0]);
-        } else offlineResources = new IRI[0];
+        if (this.offline != null) {
+            List<IRI> paths = offline.getOntologySourceLocations();
+            if (paths != null) offlineResources = paths.toArray(new IRI[0]);
+            // There are no offline paths.
+            else offlineResources = new IRI[0];
+        }
+        // There's no offline configuration at all.
+        else offlineResources = new IRI[0];
 
         // Used only for creating the registry model, do not use for caching.
         OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(offlineResources);
@@ -232,14 +212,22 @@ public class RegistryManagerImpl impleme
         // Create and set the cache.
         if (cachingPolicyString.equals(CachingPolicy.CENTRALISED.name())) {
             this.cache = OWLOntologyManagerFactory.createOWLOntologyManager(offlineResources);
-            for (Registry reg : getRegistries())
-                reg.setCache(this.cache);
         } else if (cachingPolicyString.equals(CachingPolicy.DISTRIBUTED.name())) {
-            for (Registry reg : getRegistries())
-                reg.setCache(OWLOntologyManagerFactory.createOWLOntologyManager(offlineResources));
             this.cache = null;
         }
 
+        Set<RegistryItem> visited = new HashSet<RegistryItem>();
+        for (Registry reg : getRegistries())
+            for (RegistryItem child : reg.getChildren())
+                if (!visited.contains(child)) {
+                    if (child instanceof Library) {
+                        if (this.cache != null) ((Library) child).setCache(this.cache);
+                        else ((Library) child).setCache(OWLOntologyManagerFactory
+                                .createOWLOntologyManager(offlineResources));
+                    }
+                    visited.add(child);
+                }
+
         if (isLazyLoading()) {
             // Nothing to do about it at the moment.
         } else {
@@ -249,6 +237,7 @@ public class RegistryManagerImpl impleme
 
     @Override
     public void addRegistry(Registry registry) {
+        // TODO: automatically set the cache if unset or non conform to the caching policy.
         try {
             population.put(registry.getIRI(), registry);
             registries.add(registry.getIRI());
@@ -265,8 +254,44 @@ public class RegistryManagerImpl impleme
         updateLocations();
     }
 
-    protected Map<Library,Float> computeLoadFactors() {
-        Map<Library,Float> loadFactors = new HashMap<Library,Float>();
+    /**
+     * @deprecated with each library having its own cache, load balancing is no longer necessary
+     * @return
+     */
+    protected Registry computeBestCandidate(Library lib) {
+        Map<IRI,Float> loadFactors = computeLoadFactors();
+        IRI current = null;
+        float lowest = 1.0f;
+        for (RegistryItem item : lib.getParents()) {
+            IRI iri = item.getIRI();
+            if (loadFactors.containsKey(iri)) {
+                float f = loadFactors.get(iri);
+                if (f < lowest) {
+                    lowest = f;
+                    current = iri;
+                }
+            }
+        }
+        return (Registry) (population.get(current));
+    }
+
+    /**
+     * @deprecated with each library having its own cache, load balancing is no longer necessary
+     * @return
+     */
+    protected Map<IRI,Float> computeLoadFactors() {
+        Map<IRI,Float> loadFactors = new HashMap<IRI,Float>();
+        for (Registry r : getRegistries()) {
+            int tot = 0, num = 0;
+            RegistryItem[] children = r.getChildren();
+            for (int i = 0; i < children.length; i++) {
+                if (children[i] instanceof Library) {
+                    if (((Library) children[i]).isLoaded()) num++;
+                    tot++;
+                }
+            }
+            loadFactors.put(r.getIRI(), (float) num / (float) tot);
+        }
         return loadFactors;
     }
 
@@ -412,12 +437,36 @@ public class RegistryManagerImpl impleme
     }
 
     @Override
+    public Set<Library> getLibraries() {
+        Set<Library> results = new HashSet<Library>();
+        for (IRI key : population.keySet()) {
+            RegistryItem item = population.get(key);
+            if (item instanceof Library) results.add((Library) item);
+        }
+        return results;
+    }
+
+    @Override
     public Set<Library> getLibraries(IRI ontologyID) {
-        // TODO Auto-generated method stub
+        Set<Library> results = new HashSet<Library>();
+        for (RegistryItem item : population.get(ontologyID).getParents())
+            if (item instanceof Library) results.add((Library) item);
+        return results;
+    }
+
+    @Override
+    public Library getLibrary(IRI id) {
+        RegistryItem item = population.get(id);
+        if (item != null && item instanceof Library) return (Library) item;
         return null;
     }
 
     @Override
+    public OfflineConfiguration getOfflineConfiguration() {
+        return offline;
+    }
+
+    @Override
     public Set<Registry> getRegistries() {
         Set<Registry> results = new HashSet<Registry>();
         for (IRI key : population.keySet()) {
@@ -450,6 +499,22 @@ public class RegistryManagerImpl impleme
         return lazyLoading;
     }
 
+    private void loadEager() {
+        for (RegistryItem item : population.values()) {
+            if (item instanceof Library && !((Library) item).isLoaded()) {
+                // TODO: implement ontology request targets.
+                if (CachingPolicy.CENTRALISED.equals(getCachingPolicy()) && this.cache != null) {
+                    ((Library) item).loadOntologies(this.cache);
+                } else if (CachingPolicy.DISTRIBUTED.equals(getCachingPolicy())) {
+                    Library lib = (Library) item;
+                    lib.loadOntologies(lib.getCache());
+                } else {
+                    log.error("Tried to load ontology resource {} using a null cache.", item);
+                }
+            }
+        }
+    }
+
     protected Library populateLibrary(OWLNamedIndividual ind, Set<OWLOntology> registries) throws RegistryContentException {
         IRI id = ind.getIRI();
         RegistryItem lib = null;
@@ -549,23 +614,6 @@ public class RegistryManagerImpl impleme
         return reg;
     }
 
-    private void loadEager() {
-        for (RegistryItem item : population.values()) {
-            if (item instanceof Library && !((Library) item).isLoaded()) {
-                // TODO: implement ontology request targets.
-                if (CachingPolicy.CENTRALISED.equals(getCachingPolicy()) && this.cache != null) {
-                    ((Library) item).loadOntologies(this.cache);
-                } else if (CachingPolicy.DISTRIBUTED.equals(getCachingPolicy())) {
-                    // TODO implement load balancing.
-                    Iterator<Registry> it = getRegistries(item.getIRI()).iterator();
-                    if (it.hasNext()) ((Library) item).loadOntologies(it.next().getCache());
-                } else {
-                    log.error("Tried to load ontology resource {} using a null cache.", item);
-                }
-            }
-        }
-    }
-
     @Override
     public void registryContentRequested(RegistryItem requestTarget) {
         log.debug("In {} registry content was requested on {}.", getClass(), requestTarget);
@@ -575,9 +623,8 @@ public class RegistryManagerImpl impleme
                     .loadOntologies(this.cache);
         } else if (CachingPolicy.DISTRIBUTED.equals(getCachingPolicy())) {
             if (requestTarget instanceof Library && !((Library) requestTarget).isLoaded()) {
-                // TODO implement load balancing.
-                Iterator<Registry> it = getRegistries(requestTarget.getIRI()).iterator();
-                if (it.hasNext()) ((Library) requestTarget).loadOntologies(it.next().getCache());
+                Library lib = (Library) requestTarget;
+                lib.loadOntologies(lib.getCache());
             }
         } else {
             log.error("Tried to load ontology resource {} using a null cache.", requestTarget);
@@ -586,13 +633,16 @@ public class RegistryManagerImpl impleme
 
     @Override
     public void removeRegistry(IRI registryId) {
+        // TODO: automatically remove ontologies from the cache if centralised.
         registries.remove(registryId);
         updateLocations();
     }
 
     @Override
     public void setLazyLoading(boolean lazy) {
+        // Warning: do not use in constructor!
         this.lazyLoading = lazy;
+        if (!lazy) loadEager();
     }
 
     protected synchronized void updateLocations() {

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java Wed Jul 27 16:50:29 2011
@@ -25,6 +25,7 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.registry.api.model.Library;
 import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
 import org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology;
+import org.semanticweb.owlapi.apibinding.OWLManager;
 import org.semanticweb.owlapi.model.IRI;
 import org.semanticweb.owlapi.model.OWLOntology;
 import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
@@ -39,16 +40,33 @@ import org.slf4j.LoggerFactory;
  */
 public class LibraryImpl extends AbstractRegistryItem implements Library {
 
+    private OWLOntologyManager cache;
+
     private boolean loaded = false;
 
     private Logger log = LoggerFactory.getLogger(getClass());
 
     public LibraryImpl(IRI iri) {
+        this(iri, OWLManager.createOWLOntologyManager());
+    }
+
+    public LibraryImpl(IRI iri, OWLOntologyManager cache) {
         super(iri);
+        setCache(cache);
     }
 
     public LibraryImpl(IRI iri, String name) {
+        this(iri, name, OWLManager.createOWLOntologyManager());
+    }
+
+    public LibraryImpl(IRI iri, String name, OWLOntologyManager cache) {
         super(iri, name);
+        setCache(cache);
+    }
+
+    @Override
+    public OWLOntologyManager getCache() {
+        return cache;
     }
 
     @Override
@@ -106,4 +124,11 @@ public class LibraryImpl extends Abstrac
         loaded = true;
     }
 
+    @Override
+    public void setCache(OWLOntologyManager cache) {
+        // TODO use the ontology manager factory.
+        if (cache == null) cache = OWLManager.createOWLOntologyManager();
+        this.cache = cache;
+    }
+
 }

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java Wed Jul 27 16:50:29 2011
@@ -17,37 +17,18 @@
 package org.apache.stanbol.ontologymanager.registry.impl.model;
 
 import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
-import org.semanticweb.owlapi.apibinding.OWLManager;
 import org.semanticweb.owlapi.model.IRI;
-import org.semanticweb.owlapi.model.OWLOntologyManager;
 
 public class RegistryImpl extends AbstractRegistryItem implements Registry {
 
-    private OWLOntologyManager cache;
-
     private String message = "";
 
     public RegistryImpl(IRI iri) {
-        this(iri, OWLManager.createOWLOntologyManager());
-    }
-
-    public RegistryImpl(IRI iri, OWLOntologyManager cache) {
         super(iri);
-        setCache(cache);
     }
 
     public RegistryImpl(IRI iri, String name) {
-        this(iri, name, OWLManager.createOWLOntologyManager());
-    }
-
-    public RegistryImpl(IRI iri, String name, OWLOntologyManager cache) {
         super(iri, name);
-        setCache(cache);
-    }
-
-    @Override
-    public OWLOntologyManager getCache() {
-        return cache;
     }
 
     public String getError() {
@@ -73,13 +54,6 @@ public class RegistryImpl extends Abstra
         return this.getError().equals("");
     }
 
-    @Override
-    public void setCache(OWLOntologyManager cache) {
-        // TODO use the ontology manager factory.
-        if (cache == null) cache = OWLManager.createOWLOntologyManager();
-        this.cache = cache;
-    }
-
     @Deprecated
     public void setError(String message) {
         this.message = message;

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java Wed Jul 27 16:50:29 2011
@@ -16,27 +16,27 @@
  */
 package org.apache.stanbol.ontologymanager.registry.io;
 
-import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.Set;
 
+import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.AbstractOntologyInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
 import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
-import org.apache.stanbol.ontologymanager.registry.api.RegistryLoader;
-import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
-import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryContentException;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
+import org.apache.stanbol.ontologymanager.registry.api.model.Library;
+import org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl;
 import org.apache.stanbol.ontologymanager.registry.impl.model.LibraryImpl;
-import org.apache.stanbol.owl.util.URIUtils;
+import org.apache.stanbol.owl.OWLOntologyManagerFactory;
 import org.semanticweb.owlapi.apibinding.OWLManager;
 import org.semanticweb.owlapi.model.IRI;
 import org.semanticweb.owlapi.model.OWLOntology;
-import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * An ontology input source that loads all the ontologies in a given library and attaches them to a parent
  * ontology, either new or supplied by the developer. This input source can either accept an already built
@@ -58,118 +58,15 @@ public class LibrarySource extends Abstr
      * @param libraryID
      *            the identifier of the ontology library.
      */
-    public LibrarySource(IRI libraryID) {
-        this(libraryID, URIUtils.upOne(libraryID));
-    }
-
-    /**
-     * Creates a new ontology source from a library.
-     * 
-     * @param libraryID
-     * @param registryLocation
-     */
-    public LibrarySource(IRI libraryID, IRI registryLocation) {
-        this(libraryID, registryLocation, null);
-    }
-
-    /**
-     * Creates a new ontology source from a library.
-     * 
-     * @param libraryID
-     *            the identifier of the ontology library.
-     * @param registryLocation
-     * @param ontologyManager
-     * @param loader
-     */
-    public LibrarySource(IRI libraryID,
-                         IRI registryLocation,
-                         OWLOntologyManager ontologyManager,
-                         RegistryLoader loader) {
-        this(libraryID, registryLocation, ontologyManager, loader, null);
-    }
-
-    /**
-     * Creates a new ontology source from a library.
-     * 
-     * @param libraryID
-     *            the identifier of the ontology library.
-     * @param registryLocation
-     * @param ontologyManager
-     * @param loader
-     * @param parentSrc
-     *            the source of the ontology that will import all the ontologies in the registry. If null, a
-     *            new blank ontology will be used.
-     */
-    public LibrarySource(IRI libraryID,
-                         IRI registryLocation,
-                         OWLOntologyManager ontologyManager,
-                         RegistryLoader loader,
-                         OntologyInputSource parentSrc) {
-        this.libraryID = libraryID;
-
-        // The ontology that imports the whole network is created in-memory, therefore it has no physical IRI.
-        bindPhysicalIri(null);
-
-        Set<OWLOntology> subtrees = new HashSet<OWLOntology>();
-        Registry reg = loader.loadLibrary(registryLocation, libraryID);
-        for (RegistryItem ri : reg.getChildren()) {
-            if (ri.isLibrary()) try {
-                Set<OWLOntology> adds = loader.gatherOntologies(ri, ontologyManager, true);
-                subtrees.addAll(adds);
-            } catch (OWLOntologyAlreadyExistsException e) {
-                // Chettefreca
-                continue;
-            } catch (OWLOntologyCreationException e) {
-                log.warn("Failed to load ontology library " + ri.getName() + ". Skipping.", e);
-                // If we can't load this library at all, scrap it.
-                // TODO : not entirely convinced of this step.
-                continue;
-            }
-        }
-
-        // We always construct a new root now, even if there's just one subtree.
-
-        // Set<OWLOntology> subtrees = mgr.getOntologies();
-        // if (subtrees.size() == 1)
-        // rootOntology = subtrees.iterator().next();
-        // else
-        try {
-            if (parentSrc != null) bindRootOntology(OntologyUtils.buildImportTree(parentSrc, subtrees,
-                ontologyManager));
-            else bindRootOntology(OntologyUtils.buildImportTree(subtrees, ontologyManager));
-        } catch (OWLOntologyCreationException e) {
-            log.error("Failed to build import tree for registry source " + registryLocation, e);
-        }
-    }
-
-    /**
-     * Creates a new ontology source from a library.
-     * 
-     * @param libraryID
-     *            the identifier of the ontology library.
-     * @param registryLocation
-     * @param loader
-     */
-    public LibrarySource(IRI libraryID, IRI registryLocation, RegistryLoader loader) {
-        this(libraryID, registryLocation, OWLManager.createOWLOntologyManager(), loader);
+    public LibrarySource(IRI libraryID) throws RegistryContentException {
+        this(libraryID, new RegistryManagerImpl(null, new Hashtable<String,Object>()));
     }
 
-    /**
-     * Creates a new ontology source from a library.
-     * 
-     * @param libraryID
-     *            the identifier of the ontology library.
-     * @param registryLocation
-     * @param loader
-     * @param parentSrc
-     *            the source of the ontology that will import all the ontologies in the registry. If null, a
-     *            new blank ontology will be used.
-     */
-    public LibrarySource(IRI libraryID,
-                         IRI registryLocation,
-                         RegistryLoader loader,
-                         OntologyInputSource parentSrc) {
-        this(libraryID, registryLocation, OWLManager.createOWLOntologyManager(), loader, parentSrc);
+    private static OWLOntologyManager checkOntologyManager(RegistryManager registryManager) {
+        OfflineConfiguration offline = registryManager.getOfflineConfiguration();
+        if (offline == null) return OWLManager.createOWLOntologyManager();
+        return OWLOntologyManagerFactory.createOWLOntologyManager(offline.getOntologySourceLocations()
+                .toArray(new IRI[0]));
     }
 
     /**
@@ -181,13 +78,122 @@ public class LibrarySource extends Abstr
      * 
      * @param libraryID
      *            the identifier of the ontology library.
-     * @param ontologyManager
      * @param loader
      */
-    public LibrarySource(IRI libraryID, OWLOntologyManager ontologyManager, RegistryLoader loader) {
-        this(libraryID, URIUtils.upOne(libraryID), ontologyManager, loader);
+    public LibrarySource(IRI libraryID, RegistryManager registryManager) throws RegistryContentException {
+        this(libraryID, registryManager, checkOntologyManager(registryManager));
     }
 
+    // /**
+    // * Creates a new ontology source from a library.
+    // *
+    // * @param libraryID
+    // * @param registryLocation
+    // */
+    // public LibrarySource(IRI libraryID, IRI registryLocation) {
+    // this(libraryID, registryLocation, null);
+    // }
+
+    // /**
+    // * Creates a new ontology source from a library.
+    // *
+    // * @param libraryID
+    // * the identifier of the ontology library.
+    // * @param registryLocation
+    // * @param ontologyManager
+    // * @param loader
+    // */
+    // public LibrarySource(IRI libraryID,
+    // IRI registryLocation,
+    // OWLOntologyManager ontologyManager,
+    // RegistryLoader loader) {
+    // this(libraryID, registryLocation, ontologyManager, loader, null);
+    // }
+
+    // /**
+    // * Creates a new ontology source from a library.
+    // *
+    // * @param libraryID
+    // * the identifier of the ontology library.
+    // * @param registryLocation
+    // * @param ontologyManager
+    // * @param loader
+    // * @param parentSrc
+    // * the source of the ontology that will import all the ontologies in the registry. If null, a
+    // * new blank ontology will be used.
+    // */
+    // public LibrarySource(IRI libraryID,
+    // IRI registryLocation,
+    // OWLOntologyManager ontologyManager,
+    // RegistryLoader loader,
+    // OntologyInputSource parentSrc) {
+    // this.libraryID = libraryID;
+    //
+    // // The ontology that imports the whole network is created in-memory, therefore it has no physical IRI.
+    // bindPhysicalIri(null);
+    //
+    // Set<OWLOntology> subtrees = new HashSet<OWLOntology>();
+    // Registry reg = loader.loadLibrary(registryLocation, libraryID);
+    // for (RegistryItem ri : reg.getChildren()) {
+    // if (ri.isLibrary()) try {
+    // Set<OWLOntology> adds = loader.gatherOntologies(ri, ontologyManager, true);
+    // subtrees.addAll(adds);
+    // } catch (OWLOntologyAlreadyExistsException e) {
+    // // Chettefreca
+    // continue;
+    // } catch (OWLOntologyCreationException e) {
+    // log.warn("Failed to load ontology library " + ri.getName() + ". Skipping.", e);
+    // // If we can't load this library at all, scrap it.
+    // // TODO : not entirely convinced of this step.
+    // continue;
+    // }
+    // }
+    //
+    // // We always construct a new root now, even if there's just one subtree.
+    //
+    // // Set<OWLOntology> subtrees = mgr.getOntologies();
+    // // if (subtrees.size() == 1)
+    // // rootOntology = subtrees.iterator().next();
+    // // else
+    // try {
+    // if (parentSrc != null) bindRootOntology(OntologyUtils.buildImportTree(parentSrc, subtrees,
+    // ontologyManager));
+    // else bindRootOntology(OntologyUtils.buildImportTree(subtrees, ontologyManager));
+    // } catch (OWLOntologyCreationException e) {
+    // log.error("Failed to build import tree for registry source " + registryLocation, e);
+    // }
+    // }
+
+    // /**
+    // * Creates a new ontology source from a library.
+    // *
+    // * @param libraryID
+    // * the identifier of the ontology library.
+    // * @param registryLocation
+    // * @param loader
+    // */
+    // public LibrarySource(IRI libraryID, IRI registryLocation, RegistryLoader loader) {
+    // this(libraryID, registryLocation, OWLManager.createOWLOntologyManager(), loader);
+    // }
+
+    // /**
+    // * Creates a new ontology source from a library.
+    // *
+    // * @param libraryID
+    // * the identifier of the ontology library.
+    // * @param registryLocation
+    // * @param loader
+    // * @param parentSrc
+    // * the source of the ontology that will import all the ontologies in the registry. If null, a
+    // * new blank ontology will be used.
+    // */
+    // public LibrarySource(IRI libraryID,
+    // IRI registryLocation,
+    // RegistryLoader loader,
+    // OntologyInputSource parentSrc) {
+    // this(libraryID, registryLocation, OWLManager.createOWLOntologyManager(), loader, parentSrc);
+    // }
+
     /**
      * Creates a new ontology source from a library. The physical registry location is assumed to be the
      * parent URL of <code>libraryID</code>. <br/>
@@ -197,17 +203,13 @@ public class LibrarySource extends Abstr
      * 
      * @param libraryID
      *            the identifier of the ontology library.
-     * @param ontologyManager
      * @param loader
      * @param parentSrc
      *            the source of the ontology that will import all the ontologies in the registry. If null, a
      *            new blank ontology will be used.
      */
-    public LibrarySource(IRI libraryID,
-                         OWLOntologyManager ontologyManager,
-                         RegistryLoader loader,
-                         OntologyInputSource parentSrc) {
-        this(libraryID, URIUtils.upOne(libraryID), ontologyManager, loader, parentSrc);
+    public LibrarySource(IRI libraryID, RegistryManager registryManager, OntologyInputSource parentSrc) throws RegistryContentException {
+        this(libraryID, registryManager, checkOntologyManager(registryManager), parentSrc);
     }
 
     /**
@@ -219,28 +221,67 @@ public class LibrarySource extends Abstr
      * 
      * @param libraryID
      *            the identifier of the ontology library.
+     * @param ontologyManager
      * @param loader
      */
-    public LibrarySource(IRI libraryID, RegistryLoader loader) {
-        this(libraryID, URIUtils.upOne(libraryID), loader);
+    public LibrarySource(IRI libraryID, RegistryManager registryManager, OWLOntologyManager ontologyManager) throws RegistryContentException {
+        this(libraryID, registryManager, ontologyManager, null);
     }
 
-    /**
-     * Creates a new ontology source from a library. The physical registry location is assumed to be the
-     * parent URL of <code>libraryID</code>. <br/>
-     * <br/>
-     * Example : if <code>libraryID</code> is <tt>http://foo.bar.baz/registry#library</tt>, the registry
-     * location will be <tt>http://foo.bar.baz/registry</tt>. Same goes for slash-URIs.
-     * 
-     * @param libraryID
-     *            the identifier of the ontology library.
-     * @param loader
-     * @param parentSrc
-     *            the source of the ontology that will import all the ontologies in the registry. If null, a
-     *            new blank ontology will be used.
-     */
-    public LibrarySource(IRI libraryID, RegistryLoader loader, OntologyInputSource parentSrc) {
-        this(libraryID, URIUtils.upOne(libraryID), OWLManager.createOWLOntologyManager(), loader, parentSrc);
+    //
+    // /**
+    // * Creates a new ontology source from a library. The physical registry location is assumed to be the
+    // * parent URL of <code>libraryID</code>. <br/>
+    // * <br/>
+    // * Example : if <code>libraryID</code> is <tt>http://foo.bar.baz/registry#library</tt>, the registry
+    // * location will be <tt>http://foo.bar.baz/registry</tt>. Same goes for slash-URIs.
+    // *
+    // * @param libraryID
+    // * the identifier of the ontology library.
+    // * @param ontologyManager
+    // * @param loader
+    // * @param parentSrc
+    // * the source of the ontology that will import all the ontologies in the registry. If null, a
+    // * new blank ontology will be used.
+    // */
+    // public LibrarySource(IRI libraryID,
+    // OWLOntologyManager ontologyManager,
+    // RegistryLoader loader,
+    // OntologyInputSource parentSrc) {
+    // this(libraryID, URIUtils.upOne(libraryID), ontologyManager, loader, parentSrc);
+    // }
+
+    public LibrarySource(IRI libraryID,
+                         RegistryManager registryManager,
+                         OWLOntologyManager ontologyManager,
+                         OntologyInputSource parentSrc) throws RegistryContentException {
+        if (registryManager == null) throw new IllegalArgumentException(
+                "A null registry manager is not allowed");
+
+        // The ontology that imports the whole network is created in-memory, therefore it has no physical IRI
+        // unless it is borrowed from the supplied parent.
+        bindPhysicalIri(parentSrc != null ? parentSrc.getPhysicalIRI() : null);
+
+        Library lib = registryManager.getLibrary(libraryID);
+        // If the manager is set to
+        if (lib != null) {
+            Set<OWLOntology> subtrees = lib.getOntologies();
+
+            // We always construct a new root now, even if there's just one subtree.
+
+            // if (subtrees.size() == 1)
+            // rootOntology = subtrees.iterator().next();
+            // else
+            try {
+                if (parentSrc != null) bindRootOntology(OntologyUtils.buildImportTree(parentSrc, subtrees,
+                    ontologyManager));
+                else bindRootOntology(OntologyUtils.buildImportTree(subtrees, ontologyManager));
+            } catch (OWLOntologyCreationException e) {
+                log.error("Failed to build import tree for library source " + libraryID, e);
+            }
+
+        }
+
     }
 
     @Override

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java Wed Jul 27 16:50:29 2011
@@ -23,20 +23,17 @@ import java.net.URL;
 import java.util.Dictionary;
 import java.util.Hashtable;
 
-import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
 import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
-import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
 import org.apache.stanbol.ontologymanager.ontonet.impl.OfflineConfigurationImpl;
-import org.apache.stanbol.ontologymanager.registry.api.RegistryLoader;
 import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
 import org.apache.stanbol.ontologymanager.registry.api.model.Library;
 import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
 import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
-import org.apache.stanbol.ontologymanager.registry.impl.RegistryLoaderImpl;
 import org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl;
 import org.apache.stanbol.ontologymanager.registry.impl.util.RegistryUtils;
 import org.apache.stanbol.ontologymanager.registry.io.LibrarySource;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -53,13 +50,7 @@ import org.semanticweb.owlapi.util.AutoI
  */
 public class TestOntologyLibrary {
 
-    private String registryResource = "/ontologies/registry/onmtest.owl";
-
-    private static ONManager onm;
-
-    private static RegistryLoader loader;
-
-    private OWLOntologyManager virginOntologyManager;
+    private static OfflineConfiguration offline;
 
     /**
      * Sets the ontology network manager and registry loader before running the tests.
@@ -68,11 +59,18 @@ public class TestOntologyLibrary {
     public static void setupTest() throws Exception {
         final Dictionary<String,Object> config = new Hashtable<String,Object>();
         config.put(OfflineConfiguration.ONTOLOGY_PATHS, new String[] {"/ontologies", "/ontologies/registry"});
-        OfflineConfiguration offline = new OfflineConfigurationImpl(config);
-        RegistryManager regman = new RegistryManagerImpl(offline, config);
-        // An ONManagerImpl with no store and default settings
-        onm = new ONManagerImpl(null, null, offline, config);
-        loader = new RegistryLoaderImpl(regman, onm);
+        offline = new OfflineConfigurationImpl(config);
+    }
+
+    private String registryResource = "/ontologies/registry/onmtest.owl";
+
+    private RegistryManager regMgr;
+
+    private OWLOntologyManager virginOntologyManager;
+
+    @After
+    public void reset() {
+        regMgr = null;
     }
 
     /**
@@ -83,7 +81,7 @@ public class TestOntologyLibrary {
      *             if any error occurs;
      */
     @Before
-    public void resetOntologyManager() throws Exception {
+    public void setup() throws Exception {
         virginOntologyManager = OWLManager.createOWLOntologyManager();
         URL url = getClass().getResource("/ontologies");
         virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
@@ -104,8 +102,17 @@ public class TestOntologyLibrary {
      */
     @Test
     public void testLibraryLoad() throws Exception {
+
         IRI localTestRegistry = IRI.create(getClass().getResource(registryResource));
-        Registry reg = loader.loadRegistry(localTestRegistry, virginOntologyManager);
+
+        Dictionary<String,Object> regmanConf = new Hashtable<String,Object>();
+        regmanConf.put(RegistryManager.REGISTRY_LOCATIONS, new String[] {localTestRegistry.toString()});
+        regMgr = new RegistryManagerImpl(offline, regmanConf);
+        assertNotNull(regMgr);
+
+        assertFalse(regMgr.getRegistries().isEmpty());
+        assertEquals(1, regMgr.getRegistries().size());
+        Registry reg = regMgr.getRegistries().iterator().next();
         assertTrue(reg.hasChildren());
         Library lib = null;
         // Look for test #Library2
@@ -132,9 +139,15 @@ public class TestOntologyLibrary {
      */
     @Test
     public void testLibrarySourceCreation() throws Exception {
+
         IRI localTestRegistry = IRI.create(getClass().getResource(registryResource));
-        OntologyInputSource src = new LibrarySource(Locations.LIBRARY_TEST1, localTestRegistry,
-                virginOntologyManager, loader);
+
+        Dictionary<String,Object> regmanConf = new Hashtable<String,Object>();
+        regmanConf.put(RegistryManager.REGISTRY_LOCATIONS, new String[] {localTestRegistry.toString()});
+        regMgr = new RegistryManagerImpl(offline, regmanConf);
+        assertNotNull(regMgr);
+
+        OntologyInputSource src = new LibrarySource(Locations.LIBRARY_TEST1, regMgr, virginOntologyManager);
         OWLOntology o = src.getRootOntology();
         boolean hasImporting = false, hasImported = false;
         for (OWLImportsDeclaration ax : o.getImportsDeclarations()) {

Modified: incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java?rev=1151531&r1=1151530&r2=1151531&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java Wed Jul 27 16:50:29 2011
@@ -86,7 +86,7 @@ public class TestRegistryManager {
         assertNotNull(regman);
         assertSame(CachingPolicy.CENTRALISED, regman.getCachingPolicy());
         // All registries must have the same cache.
-        Iterator<Registry> it = regman.getRegistries().iterator();
+        Iterator<Library> it = regman.getLibraries().iterator();
         OWLOntologyManager cache = it.next().getCache();
         while (it.hasNext())
             assertSame(cache, it.next().getCache());
@@ -124,7 +124,7 @@ public class TestRegistryManager {
         assertNotNull(regman);
         assertSame(CachingPolicy.DISTRIBUTED, regman.getCachingPolicy());
         // Each registry must have its own distinct cache.
-        Iterator<Registry> it = regman.getRegistries().iterator();
+        Iterator<Library> it = regman.getLibraries().iterator();
         OWLOntologyManager cache = it.next().getCache();
         // Just checking against the first in the list.
         while (it.hasNext()) {
@@ -135,7 +135,7 @@ public class TestRegistryManager {
     @Test
     public void testLoadingEager() throws Exception {
         // Change the caching policy and setup a new registry manager.
-        configuration.put(RegistryManager.CACHING_POLICY, CachingPolicy.CENTRALISED);
+        configuration.put(RegistryManager.CACHING_POLICY, CachingPolicy.DISTRIBUTED);
         configuration.put(RegistryManager.LAZY_LOADING, false);
         regman = new RegistryManagerImpl(offline, configuration);
         // Check that the configuration was set.
@@ -148,12 +148,13 @@ public class TestRegistryManager {
         while (!reg.hasChildren());
         assertNotNull(reg);
 
-        // There has to be at least one non-empty lib from the test ontologies.
+        // There has to be at least one non-empty library from the test registries...
         Library lib = null;
         RegistryItem[] children = reg.getChildren();
         for (int i = 0; i < children.length && lib == null; i++)
             if (children[i] instanceof Library) lib = (Library) (children[i]);
         assertNotNull(lib);
+        // ...and its ontologies must already be loaded without having to request them.
         assertTrue(lib.isLoaded());
     }
 
@@ -173,12 +174,13 @@ public class TestRegistryManager {
         while (!reg.hasChildren());
         assertNotNull(reg);
 
-        // There has to be at least one non-empty lib from the test ontologies.
+        // There has to be at least one non-empty library from the test registries...
         Library lib = null;
         RegistryItem[] children = reg.getChildren();
         for (int i = 0; i < children.length && lib == null; i++)
             if (children[i] instanceof Library) lib = (Library) (children[i]);
         assertNotNull(lib);
+        // ...but its ontologies must not be loaded yet.
         assertFalse(lib.isLoaded());
 
         // Touch the library. Also test that the listener system works.