You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by en...@apache.org on 2010/12/29 19:04:22 UTC

svn commit: r1053689 [2/6] - in /incubator/stanbol/trunk/kres: eu.iksproject.kres.api/ eu.iksproject.kres.api/src/main/java/eu/iksproject/kres/api/manager/ontology/ eu.iksproject.kres.api/src/main/java/eu/iksproject/kres/api/manager/registry/ eu.ikspro...

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/reasoners/Enrichment.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/reasoners/Enrichment.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/reasoners/Enrichment.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/reasoners/Enrichment.java Wed Dec 29 18:04:19 2010
@@ -8,6 +8,8 @@ package eu.iksproject.kres.jersey.reason
 import com.hp.hpl.jena.rdf.model.Model;
 import com.hp.hpl.jena.rdf.model.ModelFactory;
 import com.hp.hpl.jena.rdf.model.Resource;
+
+import eu.iksproject.kres.api.manager.KReSONManager;
 import eu.iksproject.kres.api.manager.ontology.OntologyScope;
 import eu.iksproject.kres.api.manager.ontology.OntologySpace;
 import eu.iksproject.kres.api.manager.ontology.ScopeRegistry;
@@ -16,6 +18,7 @@ import eu.iksproject.kres.api.rules.KReS
 import eu.iksproject.kres.api.rules.NoSuchRecipeException;
 import eu.iksproject.kres.api.rules.RuleStore;
 import eu.iksproject.kres.api.rules.util.KReSRuleList;
+import eu.iksproject.kres.api.storage.OntologyStoreProvider;
 import eu.iksproject.kres.manager.ONManager;
 import eu.iksproject.kres.reasoners.KReSCreateReasoner;
 import eu.iksproject.kres.reasoners.KReSRunReasoner;
@@ -23,8 +26,11 @@ import eu.iksproject.kres.reasoners.KReS
 import eu.iksproject.kres.rules.KReSKB;
 import eu.iksproject.kres.rules.manager.KReSRuleStore;
 import eu.iksproject.kres.rules.parser.KReSRuleParser;
+import eu.iksproject.kres.storage.provider.OntologyStorageProviderImpl;
+
 import java.io.File;
 import java.net.URL;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -54,6 +60,8 @@ import org.semanticweb.owlapi.model.OWLO
 import org.semanticweb.owlapi.model.OWLOntologyChange;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
 import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  *
@@ -66,49 +74,96 @@ public class Enrichment {
     private OWLOntology inputowl;
     private OWLOntology scopeowl;
 
+	protected KReSONManager onm;
+	protected OntologyStoreProvider storeProvider;
+
+	private Logger log = LoggerFactory.getLogger(getClass());
+
     /**
      * To get the KReSRuleStore where are stored the rules and the recipes
      *
-     * @param servletContext {To get the context where the REST service is running.}
+	 * @param servletContext
+	 *            {To get the context where the REST service is running.}
      */
     public Enrichment(@Context ServletContext servletContext){
-       this.kresRuleStore = (RuleStore) servletContext.getAttribute(RuleStore.class.getName());
+		// Retrieve the rule store
+		this.kresRuleStore = (RuleStore) servletContext
+				.getAttribute(RuleStore.class.getName());
+		// Retrieve the ontology network manager
+		this.onm = (KReSONManager) servletContext
+				.getAttribute(KReSONManager.class.getName());
+		this.storeProvider = (OntologyStoreProvider) servletContext
+				.getAttribute(OntologyStoreProvider.class.getName());
+		// Contingency code for missing components follows.
+		/*
+		 * FIXME! The following code is required only for the tests. This should
+		 * be removed and the test should work without this code.
+		 */
+		if (storeProvider == null) {
+			log
+					.warn("No OntologyStoreProvider in servlet context. Instantiating manually...");
+			storeProvider = new OntologyStorageProviderImpl();
+		}
+		if (onm == null) {
+			log
+					.warn("No KReSONManager in servlet context. Instantiating manually...");
+			onm = new ONManager(storeProvider.getActiveOntologyStorage(),
+					new Hashtable<String, Object>());
+		}
        if (kresRuleStore == null) {
-             System.err.println("WARNING: KReSRuleStore with stored rules and recipes is missing in ServletContext. A new instance has been created.");
-             this.kresRuleStore = new KReSRuleStore("");
-             System.err.println("PATH TO OWL FILE LOADED: "+kresRuleStore.getFilePath());
-//            throw new IllegalStateException(
-//                    "KReSRuleStore with stored rules and recipes is missing in ServletContext");
+			log
+					.warn("No KReSRuleStore with stored rules and recipes found in servlet context. Instantiating manually with default values...");
+			this.kresRuleStore = new KReSRuleStore(onm,
+					new Hashtable<String, Object>(), "");
+			log
+					.debug("PATH TO OWL FILE LOADED: "
+							+ kresRuleStore.getFilePath());
         }
     }
 
    /**
      * To trasform a sequence of rules to a Jena Model
-     * @param owl {OWLOntology object contains a single recipe}
+	 * 
+	 * @param owl
+	 *            {OWLOntology object contains a single recipe}
      * @return {A jena rdf model contains the SWRL rule.}
      */
-    private Model fromRecipeToModel(OWLOntology owl) throws NoSuchRecipeException{
+	private Model fromRecipeToModel(OWLOntology owl)
+			throws NoSuchRecipeException {
 
-        RuleStore store = new KReSRuleStore(owl);
+		// FIXME: why the heck is this method re-instantiating a rule store?!?
+		RuleStore store = new KReSRuleStore(onm,
+				new Hashtable<String, Object>(), owl);
         Model jenamodel = ModelFactory.createDefaultModel();
 
-        OWLDataFactory factory = owl.getOWLOntologyManager().getOWLDataFactory();
-        OWLClass ontocls = factory.getOWLClass(IRI.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#Recipe"));
+		OWLDataFactory factory = owl.getOWLOntologyManager()
+				.getOWLDataFactory();
+		OWLClass ontocls = factory
+				.getOWLClass(IRI
+						.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#Recipe"));
         Set<OWLClassAssertionAxiom> cls = owl.getClassAssertionAxioms(ontocls);
         Iterator<OWLClassAssertionAxiom> iter = cls.iterator();
         IRI recipeiri = IRI.create(iter.next().getIndividual().toStringID());
 
-	OWLIndividual recipeIndividual = factory.getOWLNamedIndividual(recipeiri);
+		OWLIndividual recipeIndividual = factory
+				.getOWLNamedIndividual(recipeiri);
 
-	OWLObjectProperty objectProperty = factory.getOWLObjectProperty(IRI.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasRule"));
-	Set<OWLIndividual> rules = recipeIndividual.getObjectPropertyValues(objectProperty, store.getOntology());
+		OWLObjectProperty objectProperty = factory
+				.getOWLObjectProperty(IRI
+						.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasRule"));
+		Set<OWLIndividual> rules = recipeIndividual.getObjectPropertyValues(
+				objectProperty, store.getOntology());
         String kReSRules = "";
         for(OWLIndividual rule : rules){
-			OWLDataProperty hasBodyAndHead = factory.getOWLDataProperty(IRI.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasBodyAndHead"));
-			Set<OWLLiteral> kReSRuleLiterals = rule.getDataPropertyValues(hasBodyAndHead, store.getOntology());
+			OWLDataProperty hasBodyAndHead = factory
+					.getOWLDataProperty(IRI
+							.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasBodyAndHead"));
+			Set<OWLLiteral> kReSRuleLiterals = rule.getDataPropertyValues(
+					hasBodyAndHead, store.getOntology());
 
 			for(OWLLiteral kReSRuleLiteral : kReSRuleLiterals){
-				kReSRules += kReSRuleLiteral.getLiteral() + System.getProperty("line.separator");
+				kReSRules += kReSRuleLiteral.getLiteral()
+						+ System.getProperty("line.separator");
 			}
 		}
 
@@ -125,15 +180,24 @@ public class Enrichment {
 
     }
 
-
    /**
-     * To perform a rule based reasoning with a given recipe and scope (or an ontology) to a RDF input specify via its IRI.
-     * @param session {A string contains the session IRI used to inference the input.}
-     * @param scope {A string contains either ontology or the scope IRI used to inference the input.}
-     * @param recipe {A string contains the recipe IRI from the service http://localhost:port/kres/recipe/recipeName.}
+	 * To perform a rule based reasoning with a given recipe and scope (or an
+	 * ontology) to a RDF input specify via its IRI.
+	 * 
+	 * @param session
+	 *            {A string contains the session IRI used to inference the
+	 *            input.}
+	 * @param scope
+	 *            {A string contains either ontology or the scope IRI used to
+	 *            inference the input.}
+	 * @param recipe
+	 *            {A string contains the recipe IRI from the service
+	 *            http://localhost:port/kres/recipe/recipeName.}
      * @Param file {A file in a RDF (eihter RDF/XML or owl) to inference.}
-     * @Param input_graph {A string contains the IRI of RDF (either RDF/XML or OWL) to inference.}
-     * @Param owllink_endpoint {A string contains the reasoner server end-point URL.}
+	 * @Param input_graph {A string contains the IRI of RDF (either RDF/XML or
+	 *        OWL) to inference.}
+	 * @Param owllink_endpoint {A string contains the reasoner server end-point
+	 *        URL.}
      * @return Return: <br/>
      *          200 Returns a graph with the enrichments <br/>
      *          204 No enrichments have been produced from the given graph <br/>
@@ -145,7 +209,13 @@ public class Enrichment {
     @POST
     @Consumes(MediaType.MULTIPART_FORM_DATA)
     @Produces("application/rdf+xml")
-    public Response ontologyEnrichment(@FormParam(value="session") String session,@FormParam(value="scope") String scope,@FormParam(value="recipe") String recipe,@FormParam(value="input-graph") String input_graph,@FormParam(value="file") File file,@FormParam(value="owllink-endpoint") String owllink_endpoint){
+	public Response ontologyEnrichment(
+			@FormParam(value = "session") String session,
+			@FormParam(value = "scope") String scope,
+			@FormParam(value = "recipe") String recipe,
+			@FormParam(value = "input-graph") String input_graph,
+			@FormParam(value = "file") File file,
+			@FormParam(value = "owllink-endpoint") String owllink_endpoint) {
 
       try{
 
@@ -162,16 +232,20 @@ public class Enrichment {
 
       //Load input file or graph
       if(file!=null)
-        this.inputowl = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(file);
+				this.inputowl = OWLManager.createOWLOntologyManager()
+						.loadOntologyFromOntologyDocument(file);
       if(input_graph!=null)
-        this.inputowl = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(IRI.create(input_graph));
+				this.inputowl = OWLManager.createOWLOntologyManager()
+						.loadOntologyFromOntologyDocument(
+								IRI.create(input_graph));
 
       if(inputowl==null)
         return Response.status(Status.NOT_FOUND).build();
 
        //Create list to add ontologies as imported
        OWLOntologyManager mgr = inputowl.getOWLOntologyManager();
-       OWLDataFactory factory = inputowl.getOWLOntologyManager().getOWLDataFactory();
+			OWLDataFactory factory = inputowl.getOWLOntologyManager()
+					.getOWLDataFactory();
        List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
 
        boolean ok = false;
@@ -181,16 +255,22 @@ public class Enrichment {
       if((scope!=null)&&(session==null))
       try{
           IRI iri = IRI.create(scope);
-          ScopeRegistry reg = ONManager.get().getScopeRegistry();
+					ScopeRegistry reg = onm.getScopeRegistry();
           OntologyScope ontoscope = reg.getScope(iri);
-          Iterator<OWLOntology> importscope = ontoscope.getCustomSpace().getOntologies().iterator();
-          Iterator<OntologySpace> importsession = ontoscope.getSessionSpaces().iterator();
+					Iterator<OWLOntology> importscope = ontoscope
+							.getCustomSpace().getOntologies().iterator();
+					Iterator<OntologySpace> importsession = ontoscope
+							.getSessionSpaces().iterator();
 
-          //Add ontology as import form scope, if it is anonymus we try to add single axioms.
+					// Add ontology as import form scope, if it is anonymus we
+					// try to add single axioms.
           while(importscope.hasNext()){
             OWLOntology auxonto = importscope.next();
             if(!auxonto.getOntologyID().isAnonymous()){
-            additions.add(new AddImport(inputowl, factory.getOWLImportsDeclaration(auxonto.getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
+							additions.add(new AddImport(inputowl, factory
+									.getOWLImportsDeclaration(auxonto
+											.getOWLOntologyManager()
+											.getOntologyDocumentIRI(auxonto))));
             }else{
                 mgr.addAxioms(inputowl,auxonto.getAxioms());
             }
@@ -198,11 +278,19 @@ public class Enrichment {
 
          //Add ontology form sessions
          while(importsession.hasNext()){
-             Iterator<OWLOntology> sessionontos = importsession.next().getOntologies().iterator();
+						Iterator<OWLOntology> sessionontos = importsession
+								.next().getOntologies().iterator();
              while(sessionontos.hasNext()){
                 OWLOntology auxonto = sessionontos.next();
                 if(!auxonto.getOntologyID().isAnonymous()){
-                    additions.add(new AddImport(inputowl, factory.getOWLImportsDeclaration(auxonto.getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
+								additions
+										.add(new AddImport(
+												inputowl,
+												factory
+														.getOWLImportsDeclaration(auxonto
+																.getOWLOntologyManager()
+																.getOntologyDocumentIRI(
+																		auxonto))));
                 }else{
                     mgr.addAxioms(inputowl,auxonto.getAxioms());
                 }
@@ -220,30 +308,38 @@ public class Enrichment {
       if((session!=null)&&(scope!=null))
       try{
           IRI iri = IRI.create(scope);
-          ScopeRegistry reg = ONManager.get().getScopeRegistry();
+					ScopeRegistry reg = onm.getScopeRegistry();
           OntologyScope ontoscope = reg.getScope(iri);
-          SessionOntologySpace sos = ontoscope.getSessionSpace(IRI.create(session));
+					SessionOntologySpace sos = ontoscope.getSessionSpace(IRI
+							.create(session));
 
-          Set<OWLOntology> ontos = sos.getOntologyManager().getOntologies();
+					Set<OWLOntology> ontos = sos.getOntologyManager()
+							.getOntologies();
           Iterator<OWLOntology> iteronto = ontos.iterator();
 
-          //Add session ontologies as import, if it is anonymus we try to add single axioms.
+					// Add session ontologies as import, if it is anonymus we
+					// try to add single axioms.
           while(iteronto.hasNext()){
             OWLOntology auxonto = iteronto.next();
             if(!auxonto.getOntologyID().isAnonymous()){
-                additions.add(new AddImport(inputowl, factory.getOWLImportsDeclaration(auxonto.getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
+							additions.add(new AddImport(inputowl, factory
+									.getOWLImportsDeclaration(auxonto
+											.getOWLOntologyManager()
+											.getOntologyDocumentIRI(auxonto))));
             }else{
                 mgr.addAxioms(inputowl,auxonto.getAxioms());
             }
           }
 
       }catch(Exception e){
-          System.err.println("ERROR: Problem with session: "+session);
+					System.err.println("ERROR: Problem with session: "
+							+ session);
           e.printStackTrace();
           Response.status(Status.NOT_FOUND).build();
       }
 
-      //After gathered the all ontology as imported now we apply the changes
+			// After gathered the all ontology as imported now we apply the
+			// changes
       if(additions.size()>0)
         mgr.applyChanges(additions);
 
@@ -252,23 +348,35 @@ public class Enrichment {
 
        try{
        if(recipe!=null) {
-            OWLOntology recipeowl = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(IRI.create(recipe));
-            //Get Jea RDF model of SWRL rule contained in the recipe
+						OWLOntology recipeowl = OWLManager
+								.createOWLOntologyManager()
+								.loadOntologyFromOntologyDocument(
+										IRI.create(recipe));
+						// Get Jea RDF model of SWRL rule contained in the
+						// recipe
             Model swrlmodel = fromRecipeToModel(recipeowl);
 
-            //Create a reasoner to run rules contained in the recipe
-            KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,inputowl);
-            //Run the rule reasoner to the input RDF with the added top-ontology
+						// Create a reasoner to run rules contained in the
+						// recipe
+						KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,
+								inputowl);
+						// Run the rule reasoner to the input RDF with the added
+						// top-ontology
             inputowl = rulereasoner.runRulesReasoner();
        }    
        
             //Create the reasoner for the enrichment
-            KReSCreateReasoner newreasoner = new KReSCreateReasoner(inputowl);
-            //Prepare and start the reasoner to enrich ontology's resources
-            KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner.getReasoner());
-
-            //Create a new OWLOntology model where to put the inferred axioms
-            OWLOntology output = OWLManager.createOWLOntologyManager().createOntology(inputowl.getOntologyID());
+					KReSCreateReasoner newreasoner = new KReSCreateReasoner(
+							inputowl);
+					// Prepare and start the reasoner to enrich ontology's
+					// resources
+					KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner
+							.getReasoner());
+
+					// Create a new OWLOntology model where to put the inferred
+					// axioms
+					OWLOntology output = OWLManager.createOWLOntologyManager()
+							.createOntology(inputowl.getOntologyID());
             //Initial input axioms count
             int startax = output.getAxiomCount();
             //Run the classification
@@ -287,27 +395,40 @@ public class Enrichment {
            System.err.println("CHECK ONTOLOGY CONSISTENCE");
             return Response.status(Status.NOT_FOUND).build();
         }
-      //If there is an owl-link server end-point specified in the form
+				// If there is an owl-link server end-point specified in the
+				// form
       }else{
 
       try{
        if(recipe!=null) {
-         OWLOntology recipeowl = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(IRI.create(recipe));
-         //Get Jea RDF model of SWRL rule contained in the recipe
+						OWLOntology recipeowl = OWLManager
+								.createOWLOntologyManager()
+								.loadOntologyFromOntologyDocument(
+										IRI.create(recipe));
+						// Get Jea RDF model of SWRL rule contained in the
+						// recipe
          Model swrlmodel = fromRecipeToModel(recipeowl);
-         //Create a reasoner to run rules contained in the recipe by using the server and-point
-         KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,inputowl,new URL(owllink_endpoint));
-         //Run the rule reasoner to the input RDF with the added top-ontology
+						// Create a reasoner to run rules contained in the
+						// recipe by using the server and-point
+						KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,
+								inputowl, new URL(owllink_endpoint));
+						// Run the rule reasoner to the input RDF with the added
+						// top-ontology
          inputowl = rulereasoner.runRulesReasoner();
        }
 
-         //Create a new OWLOntology model where to put the inferred axioms
-         OWLOntology output = OWLManager.createOWLOntologyManager().createOntology(inputowl.getOntologyID());
+					// Create a new OWLOntology model where to put the inferred
+					// axioms
+					OWLOntology output = OWLManager.createOWLOntologyManager()
+							.createOntology(inputowl.getOntologyID());
 
          //Create the reasoner for the enrichment
-         KReSCreateReasoner newreasoner = new KReSCreateReasoner(inputowl,new URL(owllink_endpoint));
-         //Prepare and start the reasoner to enrich ontology's resources
-         KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner.getReasoner());
+					KReSCreateReasoner newreasoner = new KReSCreateReasoner(
+							inputowl, new URL(owllink_endpoint));
+					// Prepare and start the reasoner to enrich ontology's
+					// resources
+					KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner
+							.getReasoner());
 
          //Initial input axioms count
          int startax = output.getAxiomCount();

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMOntResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMOntResource.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMOntResource.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMOntResource.java Wed Dec 29 18:04:19 2010
@@ -1,5 +1,7 @@
 package eu.iksproject.kres.jersey.resource;
 
+import java.util.Hashtable;
+
 import javax.servlet.ServletContext;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
@@ -18,26 +20,52 @@ import org.semanticweb.owlapi.model.IRI;
 import org.semanticweb.owlapi.model.OWLOntology;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
 import org.semanticweb.owlapi.model.OWLOntologyStorageException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import eu.iksproject.kres.api.manager.KReSONManager;
 import eu.iksproject.kres.api.manager.ontology.OntologyIndex;
+import eu.iksproject.kres.api.storage.OntologyStoreProvider;
+import eu.iksproject.kres.manager.ONManager;
+import eu.iksproject.kres.storage.provider.OntologyStorageProviderImpl;
 
 @Path("/ontology/get")
 public class ONMOntResource extends NavigationMixin {
 
+	private Logger log = LoggerFactory.getLogger(getClass());
+
 	/*
 	 * Placeholder for the KReSONManager to be fetched from the servlet context.
 	 */
 	protected KReSONManager onm;
-	
-	protected Serializer serializer;
+	protected OntologyStoreProvider storeProvider;
 
 	protected ServletContext servletContext;
 
+	protected Serializer serializer;
+
 	public ONMOntResource(@Context ServletContext servletContext) {
 		this.servletContext = servletContext;
-		onm = (KReSONManager) this.servletContext
+		this.onm = (KReSONManager) servletContext
 				.getAttribute(KReSONManager.class.getName());
+this.storeProvider = (OntologyStoreProvider) servletContext
+		.getAttribute(OntologyStoreProvider.class.getName());
+// Contingency code for missing components follows.
+/*
+ * FIXME! The following code is required only for the tests. This should
+ * be removed and the test should work without this code.
+ */
+if (storeProvider == null) {
+	log
+			.warn("No OntologyStoreProvider in servlet context. Instantiating manually...");
+	storeProvider = new OntologyStorageProviderImpl();
+}
+if (onm == null) {
+	log
+			.warn("No KReSONManager in servlet context. Instantiating manually...");
+	onm = new ONManager(storeProvider.getActiveOntologyStorage(),
+			new Hashtable<String, Object>());
+}
 		serializer = (Serializer) this.servletContext
 				.getAttribute(Serializer.class.getName());
 	}

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMRootResource.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMRootResource.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMRootResource.java Wed Dec 29 18:04:19 2010
@@ -1,5 +1,6 @@
 package eu.iksproject.kres.jersey.resource;
 
+import java.util.Hashtable;
 import java.util.Set;
 
 import javax.servlet.ServletContext;
@@ -15,13 +16,17 @@ import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
 
 import org.semanticweb.owlapi.model.OWLOntology;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import eu.iksproject.kres.api.format.KReSFormat;
 import eu.iksproject.kres.api.manager.KReSONManager;
 import eu.iksproject.kres.api.manager.ontology.OntologyScope;
 import eu.iksproject.kres.api.manager.ontology.ScopeRegistry;
+import eu.iksproject.kres.api.storage.OntologyStoreProvider;
 import eu.iksproject.kres.manager.ONManager;
 import eu.iksproject.kres.manager.renderers.ScopeSetRenderer;
+import eu.iksproject.kres.storage.provider.OntologyStorageProviderImpl;
 
 /**
  * The main Web resource of the KReS ontology manager. All the scopes, sessions
@@ -37,22 +42,37 @@ import eu.iksproject.kres.manager.render
 @Path("/ontology")
 public class ONMRootResource extends NavigationMixin {
 
+	private Logger log = LoggerFactory.getLogger(getClass());
+
 	/*
 	 * Placeholder for the KReSONManager to be fetched from the servlet context.
 	 */
 	protected KReSONManager onm;
+	protected OntologyStoreProvider storeProvider;
 
 	protected ServletContext servletContext;
 
 	public ONMRootResource(@Context ServletContext servletContext) {
 		this.servletContext = servletContext;
-		onm = (KReSONManager) this.servletContext
+		this.onm = (KReSONManager) servletContext
 				.getAttribute(KReSONManager.class.getName());
-
+		this.storeProvider = (OntologyStoreProvider) servletContext
+				.getAttribute(OntologyStoreProvider.class.getName());
+		// Contingency code for missing components follows.
+		/*
+		 * FIXME! The following code is required only for the tests. This should
+		 * be removed and the test should work without this code.
+		 */
+		if (storeProvider == null) {
+			log
+					.warn("No OntologyStoreProvider in servlet context. Instantiating manually...");
+			storeProvider = new OntologyStorageProviderImpl();
+		}
 		if (onm == null) {
-			System.err
-					.println("[KReS] :: No KReS Ontology Network Manager provided by Servlet Context. Instantiating now...");
-			onm = new ONManager();
+			log
+					.warn("No KReSONManager in servlet context. Instantiating manually...");
+			onm = new ONManager(storeProvider.getActiveOntologyStorage(),
+					new Hashtable<String, Object>());
 		}
 	}
 

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMScopeOntologyResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMScopeOntologyResource.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMScopeOntologyResource.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMScopeOntologyResource.java Wed Dec 29 18:04:19 2010
@@ -1,8 +1,10 @@
 package eu.iksproject.kres.jersey.resource;
 
-import static javax.ws.rs.core.Response.Status.*;
+import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
+import static javax.ws.rs.core.Response.Status.NOT_FOUND;
 
 import java.net.URI;
+import java.util.Hashtable;
 import java.util.Set;
 
 import javax.servlet.ServletContext;
@@ -20,12 +22,15 @@ import javax.ws.rs.core.UriInfo;
 import org.semanticweb.owlapi.apibinding.OWLManager;
 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
 import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLImportsDeclaration;
 import org.semanticweb.owlapi.model.OWLOntology;
 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
 import org.semanticweb.owlapi.model.OWLOntologySetProvider;
 import org.semanticweb.owlapi.model.OWLOntologyStorageException;
 import org.semanticweb.owlapi.util.OWLOntologyMerger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import eu.iksproject.kres.api.format.KReSFormat;
 import eu.iksproject.kres.api.manager.KReSONManager;
@@ -33,8 +38,11 @@ import eu.iksproject.kres.api.manager.on
 import eu.iksproject.kres.api.manager.ontology.OntologySpace;
 import eu.iksproject.kres.api.manager.ontology.OntologySpaceModificationException;
 import eu.iksproject.kres.api.manager.ontology.ScopeRegistry;
+import eu.iksproject.kres.api.storage.OntologyStoreProvider;
 import eu.iksproject.kres.jersey.util.OntologyRenderUtils;
+import eu.iksproject.kres.manager.ONManager;
 import eu.iksproject.kres.manager.io.RootOntologySource;
+import eu.iksproject.kres.storage.provider.OntologyStorageProviderImpl;
 
 /**
  * This resource represents ontologies loaded within a scope.
@@ -45,17 +53,38 @@ import eu.iksproject.kres.manager.io.Roo
 @Path("/ontology/{scopeid}/{uri:.+}")
 public class ONMScopeOntologyResource extends NavigationMixin {
 
+	private Logger log = LoggerFactory.getLogger(getClass());
+
 	/*
 	 * Placeholder for the KReSONManager to be fetched from the servlet context.
 	 */
 	protected KReSONManager onm;
+	protected OntologyStoreProvider storeProvider;
 
 	protected ServletContext servletContext;
 
 	public ONMScopeOntologyResource(@Context ServletContext servletContext) {
 		this.servletContext = servletContext;
-		onm = (KReSONManager) this.servletContext
+		this.onm = (KReSONManager) servletContext
 				.getAttribute(KReSONManager.class.getName());
+this.storeProvider = (OntologyStoreProvider) servletContext
+		.getAttribute(OntologyStoreProvider.class.getName());
+// Contingency code for missing components follows.
+/*
+ * FIXME! The following code is required only for the tests. This should
+ * be removed and the test should work without this code.
+ */
+if (storeProvider == null) {
+	log
+			.warn("No OntologyStoreProvider in servlet context. Instantiating manually...");
+	storeProvider = new OntologyStorageProviderImpl();
+}
+if (onm == null) {
+	log
+			.warn("No KReSONManager in servlet context. Instantiating manually...");
+	onm = new ONManager(storeProvider.getActiveOntologyStorage(),
+			new Hashtable<String, Object>());
+}
 	}
 
 	/**
@@ -93,15 +122,15 @@ public class ONMScopeOntologyResource ex
 			return Response.status(NOT_FOUND).build();
 
 		/* BEGIN debug code, uncomment only for local testing */
-		// OWLOntology test = null, top = null;
-		// test = scope.getCustomSpace().getOntology(ontiri);
-		// System.out.println("Ontology " + ontiri);
-		// for (OWLImportsDeclaration imp : test.getImportsDeclarations())
-		// System.out.println("\timports " + imp.getIRI());
-		// top = scope.getCoreSpace().getTopOntology();
-		// System.out.println("Core root for scope " + scopeid);
-		// for (OWLImportsDeclaration imp : top.getImportsDeclarations())
-		// System.out.println("\timports " + imp.getIRI());
+		 OWLOntology test = null, top = null;
+		 test = scope.getCustomSpace().getOntology(ontiri);
+		 System.out.println("Ontology " + ontiri);
+		 for (OWLImportsDeclaration imp : test.getImportsDeclarations())
+		 System.out.println("\timports " + imp.getIRI());
+		 top = scope.getCoreSpace().getTopOntology();
+		 System.out.println("Core root for scope " + scopeid);
+		 for (OWLImportsDeclaration imp : top.getImportsDeclarations())
+		 System.out.println("\timports " + imp.getIRI());
 		/* END debug code */
 
 		OWLOntology ont = null;
@@ -151,7 +180,7 @@ public class ONMScopeOntologyResource ex
 		} catch (OWLOntologyStorageException e) {
 			throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
 		}
-		return Response.ok(res).build();
+		return Response.ok(/*ont*/res).build();
 
 	}
 

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMScopeResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMScopeResource.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMScopeResource.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.jersey/src/main/java/eu/iksproject/kres/jersey/resource/ONMScopeResource.java Wed Dec 29 18:04:19 2010
@@ -2,6 +2,8 @@ package eu.iksproject.kres.jersey.resour
 
 import static javax.ws.rs.core.Response.Status.*;
 
+import java.util.Hashtable;
+
 import javax.servlet.ServletContext;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
@@ -24,6 +26,8 @@ import javax.ws.rs.core.UriInfo;
 import org.semanticweb.owlapi.model.IRI;
 import org.semanticweb.owlapi.model.OWLOntology;
 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import eu.iksproject.kres.api.format.KReSFormat;
 import eu.iksproject.kres.api.manager.DuplicateIDException;
@@ -34,31 +38,47 @@ import eu.iksproject.kres.api.manager.on
 import eu.iksproject.kres.api.manager.ontology.OntologySpace;
 import eu.iksproject.kres.api.manager.ontology.ScopeRegistry;
 import eu.iksproject.kres.api.manager.ontology.UnmodifiableOntologySpaceException;
+import eu.iksproject.kres.api.storage.OntologyStoreProvider;
 import eu.iksproject.kres.manager.ONManager;
 import eu.iksproject.kres.manager.io.OntologyRegistryIRISource;
 import eu.iksproject.kres.manager.io.RootOntologyIRISource;
+import eu.iksproject.kres.storage.provider.OntologyStorageProviderImpl;
 
 @Path("/ontology/{scopeid}")
 public class ONMScopeResource extends NavigationMixin {
 
+	private Logger log = LoggerFactory.getLogger(getClass());
+
 	/*
 	 * Placeholder for the KReSONManager to be fetched from the servlet context.
 	 */
 	protected KReSONManager onm;
+	protected OntologyStoreProvider storeProvider;
 
 	protected ServletContext servletContext;
 
 	public ONMScopeResource(@Context ServletContext servletContext) {
 		this.servletContext = servletContext;
-		onm = (KReSONManager) this.servletContext
+		this.onm = (KReSONManager) servletContext
 				.getAttribute(KReSONManager.class.getName());
-
+this.storeProvider = (OntologyStoreProvider) servletContext
+		.getAttribute(OntologyStoreProvider.class.getName());
+// Contingency code for missing components follows.
+/*
+ * FIXME! The following code is required only for the tests. This should
+ * be removed and the test should work without this code.
+ */
+if (storeProvider == null) {
+	log
+			.warn("No OntologyStoreProvider in servlet context. Instantiating manually...");
+	storeProvider = new OntologyStorageProviderImpl();
+}
 		if (onm == null) {
-			System.err
-					.println("[KReS] :: No KReS Ontology Network Manager provided by Servlet Context. Instantiating now...");
-			onm = new ONManager();
+	log
+			.warn("No KReSONManager in servlet context. Instantiating manually...");
+	onm = new ONManager(storeProvider.getActiveOntologyStorage(),
+			new Hashtable<String, Object>());
 		}
-
 	}
 
 	@DELETE
@@ -185,7 +205,8 @@ public class ONMScopeResource extends Na
 
 		// First thing, check the core source.
 		try {
-			coreSrc = new OntologyRegistryIRISource(IRI.create(coreRegistry));
+			coreSrc = new OntologyRegistryIRISource(IRI.create(coreRegistry),
+					onm.getOwlCacheManager(), onm.getRegistryLoader());
 		} catch (Exception e1) {
 			// Bad or not supplied core registry, try the ontology.
 			try {
@@ -203,7 +224,8 @@ public class ONMScopeResource extends Na
 			// ...but if it was, be prepared to throw exceptions.
 			try {
 				custSrc = new OntologyRegistryIRISource(IRI
-						.create(customRegistry));
+						.create(customRegistry), onm.getOwlCacheManager(), onm
+						.getRegistryLoader());
 			} catch (Exception e1) {
 				// Bad or not supplied custom registry, try the ontology.
 				try {

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/pom.xml?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/pom.xml (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/pom.xml Wed Dec 29 18:04:19 2010
@@ -7,14 +7,14 @@
 	<parent>
 		<groupId>eu.iksproject</groupId>
 		<artifactId>eu.iksproject.kres.parent</artifactId>
-		<version>0.6-SNAPSHOT</version>
+		<version>0.7</version>
 		<relativePath>../parent/pom.xml</relativePath>
 	</parent>
 
 	<groupId>eu.iksproject</groupId>
 	<artifactId>eu.iksproject.kres.manager</artifactId>
 	<packaging>bundle</packaging>
-	<version>0.6-SNAPSHOT</version>
+	<version>${kres-version}</version>
 
 	<name>IKS KReS Ontology Network Manager</name>
 	<description>IKS KReS Ontology Network Manager</description>
@@ -22,7 +22,7 @@
 	<inceptionYear>2010</inceptionYear>
 
 	<properties>
-		<kres-version>0.6-SNAPSHOT</kres-version>
+		<kres-version>0.7</kres-version>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 	</properties>
 
@@ -52,9 +52,10 @@
 							org.coode.owlapi.*,
 							org.osgi.*,
 							org.semanticweb.owlapi.*,
-							org.slf4j.*;version=${pom.version},
+							org.slf4j.*;version=1.5.2,
 							org.stlab.xd.registry.io,
-							org.stlab.xd.registry.models
+							org.stlab.xd.registry.models,
+							org.xml.sax.*
 						</Import-Package>
 
 						<Private-Package>
@@ -123,6 +124,20 @@
 			<scope>provided</scope>
 		</dependency>
 
+		<!-- Diagnostics deps -->
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>			
+            <version>1.5.2</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.13</version>
+			<scope>provided</scope>
+		</dependency>
+
 		<!-- Testing deps -->
 		<dependency>
 			<groupId>junit</groupId>
@@ -136,18 +151,6 @@
                             </exclusion>
                         </exclusions>
 		</dependency>
-		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-api</artifactId>			
-            <version>1.5.6</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
-			<groupId>log4j</groupId>
-			<artifactId>log4j</artifactId>
-			<version>1.2.13</version>
-			<scope>provided</scope>
-		</dependency>
 
 	</dependencies>
 

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/Activator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/Activator.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/Activator.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/Activator.java Wed Dec 29 18:04:19 2010
@@ -16,6 +16,7 @@ public class Activator implements Bundle
 
 	@Override
 	public void start(BundleContext context) throws Exception {
+
 		// context.addBundleListener(new BundleListener() {
 		//			
 		// @Override
@@ -45,10 +46,10 @@ public class Activator implements Bundle
 
 		Logger log = LoggerFactory.getLogger(this.getClass());
 		log.debug("KReS :: Instantiating ONM static context...");
-		if (ONManager.get() != null) {
-			log.debug("KReS :: ONM static context instantiated.");
+//		if (ONManager.get() != null) {
+//			log.debug("KReS :: ONM static context instantiated.");
 			log.info("KReS :: Ontology Network Manager set up.");
-		}
+//		}
 	}
 
 	@Override

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ONManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ONManager.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ONManager.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ONManager.java Wed Dec 29 18:04:19 2010
@@ -3,8 +3,11 @@ package eu.iksproject.kres.manager;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Dictionary;
 
+import org.apache.felix.scr.annotations.Activate;
 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.Reference;
 import org.apache.felix.scr.annotations.Service;
@@ -60,24 +63,33 @@ import eu.iksproject.kres.manager.sessio
 // @Property(name="service.ranking",intValue=5)
 public class ONManager implements KReSONManager {
 
-	// @Property(value = "/ontology")
-	public static final String ALIAS_PROPERTY = "eu.iksproject.kres.manager.ontologyNetworkManager.alias";
+	public static final String _ALIAS_DEFAULT = "/ontology";
+	public static final String _CONFIG_FILE_PATH_DEFAULT = "";
+	public static final String _KRES_NAMESPACE_DEFAULT = "http://kres.iksproject.eu/";
 
-	@Property(value = "")
+	// @Property(value = _ALIAS_DEFAULT)
+	public static final String ALIAS = "eu.iksproject.kres.manager.ontologyNetworkManager.alias";
+
+	@Property(value = _CONFIG_FILE_PATH_DEFAULT)
 	public static String CONFIG_FILE_PATH = "eu.iksproject.kres.manager.ontologyNetworkManager.config_ont";
 
-	@Property(value = "http://kres.iksproject.eu/")
+	@Property(value = _KRES_NAMESPACE_DEFAULT)
 	public static String KRES_NAMESPACE = "kres.namespace";
 
-	private static ONManager me = new ONManager();
-
-	public static ONManager get() {
-		return me;
-	}
+	@SuppressWarnings("unused")
+	private String alias = _ALIAS_DEFAULT;
+	private String configPath = _CONFIG_FILE_PATH_DEFAULT;
+	private String kresNs = _KRES_NAMESPACE_DEFAULT;
+
+	// private static ONManager me = new ONManager();
+	//
+	// public static ONManager get() {
+	// return me;
+	// }
 
-	private ComponentContext ce;
+	// private ComponentContext ce;
 
-	public final Logger log = LoggerFactory.getLogger(getClass());
+	private final Logger log = LoggerFactory.getLogger(getClass());
 
 	private OntologyIndex oIndex;
 
@@ -104,50 +116,88 @@ public class ONManager implements KReSON
 	 */
 	private String[] toActivate = new String[] {};
 
-	/**
-	 * Instantiates all the default providers.
-	 * 
-	 * TODO : Felix component constraints prevent this constructor from being
-	 * private, find a way around...
-	 */
 	public ONManager() {
+		super();
 		owlFactory = OWLManager.getOWLDataFactory();
 		owlCacheManager = OWLManager.createOWLOntologyManager();
 
-		// These may require the OWL cache manager
-		ontologyScopeFactory = new OntologyScopeFactoryImpl();
-		ontologySpaceFactory = new OntologySpaceFactoryImpl();
-
 		// These depend on one another
 		scopeRegistry = new ScopeRegistryImpl();
-		oIndex = new OntologyIndexImpl(scopeRegistry);
+		oIndex = new OntologyIndexImpl(this);
+
+		// These may require the OWL cache manager
+		ontologySpaceFactory = new OntologySpaceFactoryImpl(scopeRegistry,
+				storage);
+		ontologyScopeFactory = new OntologyScopeFactoryImpl(scopeRegistry,
+				ontologySpaceFactory);
 		ontologyScopeFactory.addScopeEventListener(oIndex);
 
 		// This requires the OWL cache manager
-		registryLoader = new RegistryLoader();
+		registryLoader = new RegistryLoader(this);
 
 		// TODO : assign dynamically in case the FISE persistence store is not
 		// available.
 		// storage = new FISEPersistenceStorage();
 
 		sessionManager = new KReSSessionManagerImpl(IRI
-				.create("http://kres.iks-project.eu/"));
-		sessionManager.addSessionListener(ScopeSessionSynchronizer.get());
+				.create("http://kres.iks-project.eu/"), getScopeRegistry(),
+				getOntologyStore());
+		sessionManager.addSessionListener(new ScopeSessionSynchronizer(this));
 	}
 
-	protected void activate(ComponentContext ce) throws IOException {
+	/**
+	 * Instantiates all the default providers.
+	 * 
+	 * TODO : Felix component constraints prevent this constructor from being
+	 * private, find a way around...
+	 */
+	public ONManager(OntologyStorage ontologyStorage,
+			Dictionary<String, Object> configuration) {
+		this();
+		try {
+			activate(configuration);
+		} catch (IOException e) {
+			log.error("Unable to access servlet context.", e);
+		}
+	}
 
-		log.debug("KReS :: activating main component...");
+	/**
+	 * Used to configure an instance within an OSGi container.
+	 * 
+	 * @throws IOException
+	 */
+	@SuppressWarnings("unchecked")
+	@Activate
+	protected void activate(ComponentContext context) throws IOException {
+		log.info("in " + ONManager.class + " activate with context " + context);
+		if (context == null) {
+			throw new IllegalStateException("No valid" + ComponentContext.class
+					+ " parsed in activate!");
+		}
+		activate((Dictionary<String, Object>) context.getProperties());
+	}
+
+	protected void activate(Dictionary<String, Object> configuration)
+			throws IOException {
 
-		me = this;
-		this.ce = ce;
+		// log.debug("KReS :: activating main component...");
+		//
+		// me = this;
+		// this.ce = ce;
 
-		String path = (String) ce.getProperties().get(CONFIG_FILE_PATH);
+		String tfile = (String) configuration.get(CONFIG_FILE_PATH);
+		if (tfile != null)
+			this.configPath = tfile;
+		String tns = (String) configuration.get(KRES_NAMESPACE);
+		if (tns != null)
+			this.kresNs = tns;
+
+		// configPath = (String) configuration.get(CONFIG_FILE_PATH);
 
 		/*
 		 * If there is no configuration file, just start with an empty scope set
 		 */
-		if (path != null && !path.trim().isEmpty()) {
+		if (configPath != null && !configPath.trim().isEmpty()) {
 			OWLOntology oConf = null;
 			OWLOntologyManager tempMgr = OWLManager.createOWLOntologyManager();
 			OWLOntologyDocumentSource oConfSrc = null;
@@ -155,7 +205,8 @@ public class ONManager implements KReSON
 			try {
 				log
 						.debug("Try to load the configuration ontology from a local bundle relative path");
-				InputStream is = this.getClass().getResourceAsStream(path);
+				InputStream is = this.getClass()
+						.getResourceAsStream(configPath);
 				oConfSrc = new StreamDocumentSource(is);
 			} catch (Exception e1) {
 				try {
@@ -163,7 +214,7 @@ public class ONManager implements KReSON
 							e1);
 					log
 							.debug("Try to load the configuration ontology resolving the given IRI");
-					IRI iri = IRI.create(path);
+					IRI iri = IRI.create(configPath);
 					if (!iri.isAbsolute())
 						throw new Exception(
 								"IRI seems to be not absolute! value was: "
@@ -177,11 +228,11 @@ public class ONManager implements KReSON
 						log.debug("Cannot load from the web", e1);
 						log
 								.debug("Try to load the configuration ontology as full local file path");
-						oConfSrc = new FileDocumentSource(new File(path));
+						oConfSrc = new FileDocumentSource(new File(configPath));
 					} catch (Exception e2) {
 						log.error(
 								"Cannot load the configuration ontology from parameter value: "
-										+ path, e2);
+										+ configPath, e2);
 					}
 				}
 			}
@@ -189,7 +240,8 @@ public class ONManager implements KReSON
 			if (oConfSrc == null) {
 				log
 						.warn("KReS :: [NONFATAL] No ONM configuration file found at path "
-								+ path + ". Starting with blank scope set.");
+								+ configPath
+								+ ". Starting with blank scope set.");
 			} else {
 				try {
 					oConf = tempMgr.loadOntologyFromOntologyDocument(oConfSrc);
@@ -225,7 +277,7 @@ public class ONManager implements KReSON
 				String[] customs = ConfigurationManagement.getCustomOntologies(
 						configOntology, scopeIRI);
 
-				// "Be a man. Use printf()"
+				// "Be a man. Use printf"
 				log.debug("KReS :: Scope " + scopeIRI);
 				for (String s : cores) {
 					log.debug("\tKReS :: Core ontology " + s);
@@ -295,14 +347,18 @@ public class ONManager implements KReSON
 
 	}
 
-	protected void deactivate(ComponentContext ce) throws IOException {
-		log.debug("KReS :: Deactivating ONManager");
+	/**
+	 * Deactivation of the ONManager resets all its resources.
+	 */
+	@Deactivate
+	protected void deactivate(ComponentContext context) {
+		log.info("in " + ONManager.class + " deactivate with context "
+				+ context);
 	}
 
 	@Override
 	public String getKReSNamespace() {
-		String ns = (String) ce.getProperties().get(KRES_NAMESPACE);
-		return ns;
+		return kresNs;
 	}
 
 	public OntologyIndex getOntologyIndex() {

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/io/OntologyRegistryIRISource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/io/OntologyRegistryIRISource.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/io/OntologyRegistryIRISource.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/io/OntologyRegistryIRISource.java Wed Dec 29 18:04:19 2010
@@ -14,8 +14,7 @@ import org.stlab.xd.registry.models.Regi
 import org.stlab.xd.registry.models.RegistryItem;
 
 import eu.iksproject.kres.api.manager.ontology.OntologyInputSource;
-import eu.iksproject.kres.manager.ONManager;
-import eu.iksproject.kres.manager.registry.model.impl.RegistryLoader;
+import eu.iksproject.kres.api.manager.registry.KReSRegistryLoader;
 import eu.iksproject.kres.manager.util.OntologyUtils;
 
 /**
@@ -30,8 +29,9 @@ public class OntologyRegistryIRISource e
 
 	protected IRI registryIRI = null;
 
-	public OntologyRegistryIRISource(IRI registryIRI) {
-		this(registryIRI, null);
+	public OntologyRegistryIRISource(IRI registryIRI,
+			OWLOntologyManager ontologyManager, KReSRegistryLoader loader) {
+		this(registryIRI, ontologyManager, loader, null);
 	}
 
 	/**
@@ -42,22 +42,20 @@ public class OntologyRegistryIRISource e
 	 * @param registryIRI
 	 */
 	public OntologyRegistryIRISource(IRI registryIRI,
+			OWLOntologyManager ontologyManager, KReSRegistryLoader loader,
 			OntologyInputSource parentSrc) {
 
 		this.registryIRI = registryIRI;
 
 		Logger log = LoggerFactory.getLogger(getClass());
 
-		// TODO : support the use of other ontology managers.
-		OWLOntologyManager mgr = ONManager.get().getOwlCacheManager();
-		RegistryLoader loader = ONManager.get().getRegistryLoader();
 		Set<OWLOntology> subtrees = new HashSet<OWLOntology>();
 		for (Registry reg : loader.loadRegistriesEager(registryIRI)) {
 			for (RegistryItem ri : reg.getChildren()) {
 				if (ri.isLibrary())
 					try {
 						Set<OWLOntology> adds = loader.gatherOntologies(ri,
-								mgr, true);
+								ontologyManager, true);
 						subtrees.addAll(adds);
 					} catch (OWLOntologyAlreadyExistsException e) {
 						// Chettefreca
@@ -81,9 +79,10 @@ public class OntologyRegistryIRISource e
 		try {
 			if (parentSrc != null)
 				rootOntology = OntologyUtils.buildImportTree(parentSrc,
-						subtrees, mgr);
+						subtrees, ontologyManager);
 			else
-				rootOntology = OntologyUtils.buildImportTree(subtrees, mgr);
+				rootOntology = OntologyUtils.buildImportTree(subtrees,
+						ontologyManager);
 		} catch (OWLOntologyCreationException e) {
 			log.error(
 					"KReS :: Failed to build import tree for registry source "

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/AbstractOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/AbstractOntologySpaceImpl.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/AbstractOntologySpaceImpl.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/AbstractOntologySpaceImpl.java Wed Dec 29 18:04:19 2010
@@ -19,6 +19,7 @@ import org.semanticweb.owlapi.model.OWLO
 import org.semanticweb.owlapi.model.OWLOntologyStorageException;
 import org.semanticweb.owlapi.model.RemoveImport;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import eu.iksproject.kres.api.manager.ontology.IrremovableOntologyException;
 import eu.iksproject.kres.api.manager.ontology.MissingOntologyException;
@@ -28,6 +29,7 @@ import eu.iksproject.kres.api.manager.on
 import eu.iksproject.kres.api.manager.ontology.OntologySpaceListener;
 import eu.iksproject.kres.api.manager.ontology.OntologySpaceModificationException;
 import eu.iksproject.kres.api.manager.ontology.SessionOntologySpace;
+import eu.iksproject.kres.api.manager.ontology.SpaceType;
 import eu.iksproject.kres.api.manager.ontology.UnmodifiableOntologySpaceException;
 import eu.iksproject.kres.api.storage.OntologyStorage;
 import eu.iksproject.kres.manager.ONManager;
@@ -60,6 +62,8 @@ public abstract class AbstractOntologySp
 	 */
 	protected boolean locked = false;
 
+	protected Logger log = LoggerFactory.getLogger(getClass());
+
 	/**
 	 * Each ontology space comes with its OWL ontology manager. By default, it
 	 * is not available to the outside world, unless subclasses implement
@@ -67,26 +71,30 @@ public abstract class AbstractOntologySp
 	 */
 	protected OWLOntologyManager ontologyManager;
 
+	protected OntologyStorage storage;
+
 	protected IRI parentID = null;
 
+//	public static String SUFFIX = "";
+	
 	protected OWLOntology rootOntology = null;
 
 	protected boolean silent = false;
 
-	protected AbstractOntologySpaceImpl(IRI spaceID, IRI parentID) {
-		this(spaceID, parentID, OWLManager.createOWLOntologyManager());
+	protected AbstractOntologySpaceImpl(IRI spaceID, SpaceType type/*, IRI parentID*/, OntologyStorage storage) {
+		this(spaceID, type, /*parentID,*/ storage,OWLManager.createOWLOntologyManager());
 	}
 
-	/**
-	 * TODO: manage IDs properly
-	 * 
-	 * @param rootOntology
-	 */
-	public AbstractOntologySpaceImpl(IRI spaceID, IRI parentID,
-			OntologyInputSource rootOntology) {
-		this(spaceID, parentID, OWLManager.createOWLOntologyManager(),
-				rootOntology);
-	}
+//	/**
+//	 * TODO: manage IDs properly
+//	 * 
+//	 * @param rootOntology
+//	 */
+//	public AbstractOntologySpaceImpl(IRI spaceID, SpaceType type, IRI parentID,
+//			OntologyInputSource rootOntology) {
+//		this(spaceID, type, parentID, OWLManager.createOWLOntologyManager(),
+//				rootOntology);
+//	}
 
 	/**
 	 * Creates a new ontology space with the supplied ontology manager as the
@@ -94,21 +102,24 @@ public abstract class AbstractOntologySp
 	 * 
 	 * @param spaceID
 	 *            the IRI that will uniquely identify this space.
+	 	 * @param parentID
+	 *             IRI of the parent scope (TODO: get rid of it).
 	 * @param ontologyManager
 	 *            the default ontology manager for this space.
 	 */
-	protected AbstractOntologySpaceImpl(IRI spaceID, IRI parentID,
+	protected AbstractOntologySpaceImpl(IRI spaceID, SpaceType type, OntologyStorage storage, /*IRI parentID,*/
 			OWLOntologyManager ontologyManager) {
 
-		this.parentID = parentID;
-
-		// FIXME: ensure that this is not null
-		OntologyScope parentScope = ONManager.get().getScopeRegistry()
-				.getScope(parentID);
-
-		if (parentScope != null && parentScope instanceof OntologySpaceListener)
-			this.addOntologySpaceListener((OntologySpaceListener) parentScope);
+//		this.parentID = parentID;
+//		SUFFIX = type.getIRISuffix();
 
+//		// FIXME: ensure that this is not null
+//		OntologyScope parentScope = ONManager.get().getScopeRegistry()
+//				.getScope(parentID);
+//
+//		if (parentScope != null && parentScope instanceof OntologySpaceListener)
+//			this.addOntologySpaceListener((OntologySpaceListener) parentScope);
+this.storage = storage;
 		this._id = spaceID;
 		if (ontologyManager != null)
 			this.ontologyManager = ontologyManager;
@@ -136,29 +147,29 @@ public abstract class AbstractOntologySp
 				});
 	}
 
-	/**
-	 * Creates a new ontology space with the supplied ontology set as its top
-	 * ontology and the supplied ontology manager as the default manager for
-	 * this space.
-	 * 
-	 * @param spaceID
-	 *            the IRI that will uniquely identify this space.
-	 * @param ontologyManager
-	 *            the default ontology manager for this space.
-	 * @param rootSource
-	 *            the root ontology for this space.
-	 */
-	public AbstractOntologySpaceImpl(IRI spaceID, IRI parentID,
-			OWLOntologyManager ontologyManager, OntologyInputSource rootSource) {
-		this(spaceID, parentID, ontologyManager);
-		// Set the supplied ontology's parent as the root for this space.
-		try {
-			this.setTopOntology(rootSource, true);
-		} catch (UnmodifiableOntologySpaceException e) {
-			ONManager.get().log.error("KReS :: Ontology space " + spaceID
-					+ " found locked at creation time!", e);
-		}
-	}
+//	/**
+//	 * Creates a new ontology space with the supplied ontology set as its top
+//	 * ontology and the supplied ontology manager as the default manager for
+//	 * this space.
+//	 * 
+//	 * @param spaceID
+//	 *            the IRI that will uniquely identify this space.
+//	 * @param ontologyManager
+//	 *            the default ontology manager for this space.
+//	 * @param rootSource
+//	 *            the root ontology for this space.
+//	 */
+//	public AbstractOntologySpaceImpl(IRI spaceID,SpaceType type, IRI parentID,
+//			OWLOntologyManager ontologyManager, OntologyInputSource rootSource) {
+//		this(spaceID, type,parentID, ontologyManager);
+//		// Set the supplied ontology's parent as the root for this space.
+//		try {
+//			this.setTopOntology(rootSource, true);
+//		} catch (UnmodifiableOntologySpaceException e) {
+//			log.error("KReS :: Ontology space " + spaceID
+//					+ " found locked at creation time!", e);
+//		}
+//	}
 
 	/**
 	 * TODO: manage import statements
@@ -172,17 +183,6 @@ public abstract class AbstractOntologySp
 		if (locked)
 			throw new UnmodifiableOntologySpaceException(this);
 
-		Logger log = ONManager.get().log;
-
-		// if (ontologySource != null && parentID != null)
-		// // rewrite the source
-		// ontologySource = new ScopeOntologySource(parentID,
-		// ontologySource.getRootOntology(), ontologySource
-		// .getPhysicalIRI());
-
-		OWLOntology ontology = ontologySource != null ? ontologySource
-				.getRootOntology() : null;
-
 		if (getTopOntology() == null) {
 			// If no top ontology has been set, we must create one first.
 			IRI rootIri = null;
@@ -204,73 +204,9 @@ public abstract class AbstractOntologySp
 		}
 
 		// Now add the new ontology.
-		if (ontology != null) {
-
-			OWLOntologyID id = ontology.getOntologyID();
-
-			// if (ontologySource != null && parentID != null)
-			// // rewrite the source
-			// ontologySource = new ScopeOntologySource(parentID,
-			// ontologySource.getRootOntology(), ontologySource
-			// .getPhysicalIRI());
-
-			// Should not modify the child ontology in any way.
-			// TODO implement transaction control.
-			OntologyUtils
-					.appendOntology(new RootOntologySource(getTopOntology(),
-							null), ontologySource, ontologyManager/* ,parentID */);
-
-			StringDocumentTarget tgt = new StringDocumentTarget();
-			try {
-				ontologyManager.saveOntology(ontology,
-						new RDFXMLOntologyFormat(), tgt);
-			} catch (OWLOntologyStorageException e) {
-				log.error("KReS : [FATAL] Failed to store ontology " + id
-						+ " in memory.", e);
-				return;
-			}
-
-			try {
-				ontologyManager.removeOntology(ontology);
-				ontologyManager
-						.loadOntologyFromOntologyDocument(new StringDocumentSource(
-								tgt.toString()));
-			} catch (OWLOntologyAlreadyExistsException e) {
-				// Could happen if we supplied an ontology manager that already
-				// knows this ontology. Nothing to do then.
-				log.warn("KReS : [NONFATAL] Tried to copy ontology " + id
-						+ " to existing one.");
-			} catch (OWLOntologyCreationException e) {
-				log.error("Unexpected exception caught while copying ontology "
-						+ id + " across managers", e);
-				return;
-			}
-
-			try {
-				// Store the top ontology
-				if (!(this instanceof SessionOntologySpace)) {
-					OntologyStorage storage = ONManager.get()
-							.getOntologyStore();
-					if (storage == null)
-						log
-								.error("KReS :: [NONFATAL] no ontology storage found. Ontology "
-										+ ontology.getOntologyID()
-										+ " will be stored in-memory only.");
-					else {
-						storage.store(ontology);
-					}
-				}
-				// ONManager.get().getOntologyStore().load(rootOntology.getOntologyID().getOntologyIRI());
-			} catch (Exception ex) {
-				log.error(
-						"KReS :: [NONFATAL] An error occurred while storing ontology "
-								+ ontology
-								+ " . Ontology management will be volatile!",
-						ex);
-			}
-
-			fireOntologyAdded(id.getOntologyIRI());
-
+		if (ontologySource != null && ontologySource.hasRootOntology()) {
+			// Remember that this method also fores the event
+			performAdd(ontologySource);
 		}
 
 	}
@@ -340,6 +276,64 @@ public abstract class AbstractOntologySp
 		return silent;
 	}
 
+	private void performAdd(OntologyInputSource ontSrc) {
+		OWLOntology ontology = ontSrc.getRootOntology();
+		OWLOntologyID id = ontology.getOntologyID();
+
+		// Should not modify the child ontology in any way.
+		// TODO implement transaction control.
+		OntologyUtils.appendOntology(new RootOntologySource(getTopOntology(),
+				null), ontSrc, ontologyManager/* ,parentID */);
+
+		StringDocumentTarget tgt = new StringDocumentTarget();
+		try {
+			ontologyManager.saveOntology(ontology, new RDFXMLOntologyFormat(),
+					tgt);
+		} catch (OWLOntologyStorageException e) {
+			log.error("KReS : [FATAL] Failed to store ontology " + id
+					+ " in memory.", e);
+			return;
+		}
+
+		try {
+			ontologyManager.removeOntology(ontology);
+			ontologyManager
+					.loadOntologyFromOntologyDocument(new StringDocumentSource(
+							tgt.toString()));
+		} catch (OWLOntologyAlreadyExistsException e) {
+			// Could happen if we supplied an ontology manager that already
+			// knows this ontology. Nothing to do then.
+			log.warn("KReS : [NONFATAL] Tried to copy ontology " + id
+					+ " to existing one.");
+		} catch (OWLOntologyCreationException e) {
+			log.error("Unexpected exception caught while copying ontology "
+					+ id + " across managers", e);
+			return;
+		}
+
+		try {
+			// Store the top ontology
+			if (!(this instanceof SessionOntologySpace)) {
+				if (storage == null)
+					log
+							.error("KReS :: [NONFATAL] no ontology storage found. Ontology "
+									+ ontology.getOntologyID()
+									+ " will be stored in-memory only.");
+				else {
+					storage.store(ontology);
+				}
+			}
+			// ONManager.get().getOntologyStore().load(rootOntology.getOntologyID().getOntologyIRI());
+		} catch (Exception ex) {
+			log.error(
+					"KReS :: [NONFATAL] An error occurred while storing ontology "
+							+ ontology
+							+ " . Ontology management will be volatile!", ex);
+		}
+
+		fireOntologyAdded(id.getOntologyIRI());
+	}
+
 	/**
 	 * TODO 1 : optimize addition/removal <br>
 	 * TODO 2 : set import statements
@@ -408,8 +402,6 @@ public abstract class AbstractOntologySp
 	public synchronized void setTopOntology(OntologyInputSource ontologySource,
 			boolean createParent) throws UnmodifiableOntologySpaceException {
 
-		Logger log = ONManager.get().log;
-
 		// TODO : implement or avoid passing of OWLOntology objects across
 		// managers
 
@@ -450,12 +442,6 @@ public abstract class AbstractOntologySp
 		if (ontologySource != null)
 			try {
 
-				// if (ontologySource != null && parentID != null)
-				// // rewrite the source
-				// ontologySource = new ScopeOntologySource(parentID,
-				// ontologySource.getRootOntology(), ontologySource
-				// .getPhysicalIRI());
-
 				// Append the supplied ontology to the parent.
 				oParent = OntologyUtils.appendOntology(new RootOntologySource(
 						oParent, null), ontologySource, ontologyManager/*
@@ -490,7 +476,6 @@ public abstract class AbstractOntologySp
 
 			// Store the top ontology
 			if (!(this instanceof SessionOntologySpace)) {
-				OntologyStorage storage = ONManager.get().getOntologyStore();
 				if (storage == null)
 					log
 							.error("KReS :: [NONFATAL] no ontology storage found. Ontology "

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/CoreOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/CoreOntologySpaceImpl.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/CoreOntologySpaceImpl.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/CoreOntologySpaceImpl.java Wed Dec 29 18:04:19 2010
@@ -5,27 +5,43 @@ import org.semanticweb.owlapi.model.OWLO
 
 import eu.iksproject.kres.api.manager.ontology.CoreOntologySpace;
 import eu.iksproject.kres.api.manager.ontology.OntologyInputSource;
+import eu.iksproject.kres.api.manager.ontology.SpaceType;
+import eu.iksproject.kres.api.storage.OntologyStorage;
 import eu.iksproject.kres.manager.util.StringUtils;
 
 public class CoreOntologySpaceImpl extends AbstractOntologySpaceImpl implements
 		CoreOntologySpace {
 
-	public static final String SUFFIX = "core";
-
-	public CoreOntologySpaceImpl(IRI scopeID,
-			OntologyInputSource topOntology) {
-		super(
-				IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
-						+ SUFFIX), scopeID, topOntology);
+	public static final String SUFFIX = SpaceType.CORE.getIRISuffix();
+//	static {
+//		SUFFIX = SpaceType.CORE.getIRISuffix();
+//	}
+	
+	public CoreOntologySpaceImpl(IRI scopeID, OntologyStorage storage) {
+		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+				+ SpaceType.CORE.getIRISuffix()), SpaceType.CORE/*, scopeID*/,storage);
 	}
 
-	public CoreOntologySpaceImpl(IRI scopeID,
-			OntologyInputSource topOntology, OWLOntologyManager ontologyManager) {
-		super(
-				IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
-						+ SUFFIX), scopeID, ontologyManager, topOntology);
+	public CoreOntologySpaceImpl(IRI scopeID, OntologyStorage storage,
+			OWLOntologyManager ontologyManager) {
+		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+				+ SpaceType.CORE.getIRISuffix()), SpaceType.CORE, /*scopeID,*/storage,
+				ontologyManager);
 	}
 
+//	public CoreOntologySpaceImpl(IRI scopeID, OntologyInputSource topOntology) {
+//		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+//				+ SpaceType.CORE.getIRISuffix()), SpaceType.CORE, scopeID,
+//				topOntology);
+//	}
+//
+//	public CoreOntologySpaceImpl(IRI scopeID, OntologyInputSource topOntology,
+//			OWLOntologyManager ontologyManager) {
+//		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+//				+ SpaceType.CORE.getIRISuffix()), SpaceType.CORE, scopeID,
+//				ontologyManager, topOntology);
+//	}
+
 	/**
 	 * When set up, a core space is write-locked.
 	 */

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/CustomOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/CustomOntologySpaceImpl.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/CustomOntologySpaceImpl.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/CustomOntologySpaceImpl.java Wed Dec 29 18:04:19 2010
@@ -1,38 +1,51 @@
 package eu.iksproject.kres.manager.ontology;
 
 import org.semanticweb.owlapi.model.IRI;
-import org.semanticweb.owlapi.model.OWLImportsDeclaration;
 import org.semanticweb.owlapi.model.OWLOntology;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
-import org.slf4j.Logger;
 
 import eu.iksproject.kres.api.manager.ontology.CoreOntologySpace;
 import eu.iksproject.kres.api.manager.ontology.CustomOntologySpace;
 import eu.iksproject.kres.api.manager.ontology.OntologyInputSource;
+import eu.iksproject.kres.api.manager.ontology.SpaceType;
 import eu.iksproject.kres.api.manager.ontology.UnmodifiableOntologySpaceException;
-import eu.iksproject.kres.manager.ONManager;
+import eu.iksproject.kres.api.storage.OntologyStorage;
 import eu.iksproject.kres.manager.io.RootOntologySource;
 import eu.iksproject.kres.manager.util.StringUtils;
 
 public class CustomOntologySpaceImpl extends AbstractOntologySpaceImpl
 		implements CustomOntologySpace {
 
-	Logger log = ONManager.get().log;
-
-	public static final String SUFFIX = "custom";
-
-	public CustomOntologySpaceImpl(IRI scopeID, OntologyInputSource topOntology) {
-		super(
-				IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
-						+ SUFFIX), scopeID, topOntology);
+	public static final String SUFFIX = SpaceType.CUSTOM.getIRISuffix();
+//	static {
+//		SUFFIX = SpaceType.CUSTOM.getIRISuffix();
+//	}
+	
+	public CustomOntologySpaceImpl(IRI scopeID, OntologyStorage storage) {
+		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+				+ SpaceType.CUSTOM.getIRISuffix()), SpaceType.CUSTOM/*, scopeID*/,storage
+				);
 	}
 
-	public CustomOntologySpaceImpl(IRI scopeID,
-			OntologyInputSource topOntology, OWLOntologyManager ontologyManager) {
-		super(
-				IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
-						+ SUFFIX), scopeID, ontologyManager, topOntology);
+	public CustomOntologySpaceImpl(IRI scopeID, OntologyStorage storage,
+			 OWLOntologyManager ontologyManager) {
+		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+				+ SpaceType.CUSTOM.getIRISuffix()), SpaceType.CUSTOM, storage, /*scopeID,*/
+				ontologyManager);
 	}
+	
+//	public CustomOntologySpaceImpl(IRI scopeID, OntologyInputSource topOntology) {
+//	super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+//			+ SpaceType.CUSTOM.getIRISuffix()), SpaceType.CUSTOM, scopeID,
+//			topOntology);
+//}
+//
+//public CustomOntologySpaceImpl(IRI scopeID,
+//		OntologyInputSource topOntology, OWLOntologyManager ontologyManager) {
+//	super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+//			+ SpaceType.CUSTOM.getIRISuffix()), SpaceType.CUSTOM, scopeID,
+//			ontologyManager, topOntology);
+//}
 
 	@Override
 	public void attachCoreSpace(CoreOntologySpace coreSpace, boolean skipRoot)

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyIndexImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyIndexImpl.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyIndexImpl.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyIndexImpl.java Wed Dec 29 18:04:19 2010
@@ -10,6 +10,7 @@ import org.semanticweb.owlapi.model.OWLO
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import eu.iksproject.kres.api.manager.KReSONManager;
 import eu.iksproject.kres.api.manager.ontology.NoSuchScopeException;
 import eu.iksproject.kres.api.manager.ontology.OntologyIndex;
 import eu.iksproject.kres.api.manager.ontology.OntologyScope;
@@ -27,12 +28,17 @@ public class OntologyIndexImpl implement
 
 	private ScopeRegistry scopeRegistry;
 
-	public OntologyIndexImpl(ScopeRegistry scopeRegistry) {
+	private KReSONManager onm;
+
+	public OntologyIndexImpl(KReSONManager onm) {
+
 		ontScopeMap = new HashMap<IRI, Set<IRI>>();
-		if (scopeRegistry == null)
+		if (onm == null)
 			this.scopeRegistry = new ScopeRegistryImpl();
-		else
-			this.scopeRegistry = scopeRegistry;
+		else {
+			this.onm=onm;
+			this.scopeRegistry = onm.getScopeRegistry();
+		}
 		this.scopeRegistry.addScopeRegistrationListener(this);
 	}
 
@@ -211,7 +217,7 @@ public class OntologyIndexImpl implement
 				+ " registered. Now you can check for its activation status.");
 
 		Set<OntologyScope> scopez = scopeRegistry.getRegisteredScopes();
-		for (String token : ONManager.get().getUrisToActivate()) {
+		for (String token : onm.getUrisToActivate()) {
 			try {
 				IRI scopeId = IRI.create(token.trim());
 				scopeRegistry.setScopeActive(scopeId, true);

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyScopeFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyScopeFactoryImpl.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyScopeFactoryImpl.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyScopeFactoryImpl.java Wed Dec 29 18:04:19 2010
@@ -10,7 +10,9 @@ import eu.iksproject.kres.api.manager.Du
 import eu.iksproject.kres.api.manager.ontology.OntologyInputSource;
 import eu.iksproject.kres.api.manager.ontology.OntologyScope;
 import eu.iksproject.kres.api.manager.ontology.OntologyScopeFactory;
+import eu.iksproject.kres.api.manager.ontology.OntologySpaceFactory;
 import eu.iksproject.kres.api.manager.ontology.ScopeEventListener;
+import eu.iksproject.kres.api.manager.ontology.ScopeRegistry;
 import eu.iksproject.kres.manager.ONManager;
 
 /**
@@ -23,6 +25,14 @@ public class OntologyScopeFactoryImpl im
 
 	private Set<ScopeEventListener> listeners = new HashSet<ScopeEventListener>();
 
+	protected ScopeRegistry registry;
+	protected OntologySpaceFactory spaceFactory;
+	
+	public OntologyScopeFactoryImpl(ScopeRegistry registry, OntologySpaceFactory spaceFactory) {
+		this.registry = registry;
+		this.spaceFactory = spaceFactory;
+	}
+	
 	@Override
 	public void addScopeEventListener(ScopeEventListener listener) {
 		listeners.add(listener);
@@ -45,12 +55,12 @@ public class OntologyScopeFactoryImpl im
 			OntologyInputSource coreSource, OntologyInputSource customSource)
 			throws DuplicateIDException {
 
-		if (ONManager.get().getScopeRegistry().containsScope(scopeID))
+		if (registry.containsScope(scopeID))
 			throw new DuplicateIDException(scopeID,
 					"Scope registry already contains ontology scope with ID "
 							+ scopeID);
 
-		OntologyScope scope = new OntologyScopeImpl(scopeID, coreSource,
+		OntologyScope scope = new OntologyScopeImpl(scopeID,spaceFactory, coreSource,
 				customSource);
 		// scope.addOntologyScopeListener(ONManager.get().getOntologyIndex());
 		// TODO : manage scopes with null core ontologies

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyScopeImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyScopeImpl.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyScopeImpl.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologyScopeImpl.java Wed Dec 29 18:04:19 2010
@@ -19,7 +19,6 @@ import eu.iksproject.kres.api.manager.on
 import eu.iksproject.kres.api.manager.ontology.ScopeOntologyListener;
 import eu.iksproject.kres.api.manager.ontology.SessionOntologySpace;
 import eu.iksproject.kres.api.manager.ontology.UnmodifiableOntologySpaceException;
-import eu.iksproject.kres.manager.ONManager;
 
 /**
  * The default implementation of an ontology scope.
@@ -59,18 +58,16 @@ public class OntologyScopeImpl implement
 	 */
 	protected Map<IRI, SessionOntologySpace> sessionSpaces;
 
-	public OntologyScopeImpl(IRI id, OntologyInputSource coreRoot) {
-		this(id, coreRoot, null);
+	public OntologyScopeImpl(IRI id, OntologySpaceFactory factory,OntologyInputSource coreRoot) {
+		this(id, factory, coreRoot,null);
 	}
 
-	public OntologyScopeImpl(IRI id, OntologyInputSource coreRoot,
+	public OntologyScopeImpl(IRI id,OntologySpaceFactory factory, OntologyInputSource coreRoot, 
 			OntologyInputSource customRoot) {
 		if (id == null)
 			throw new NullPointerException(
 					"Ontology scope must be identified by a non-null IRI.");
 
-		OntologySpaceFactory factory = ONManager.get()
-				.getOntologySpaceFactory();
 		this.id = id;
 		this.coreSpace = factory.createCoreOntologySpace(id, coreRoot);
 		this.coreSpace.addOntologySpaceListener(this);

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologySpaceFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologySpaceFactoryImpl.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologySpaceFactoryImpl.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/OntologySpaceFactoryImpl.java Wed Dec 29 18:04:19 2010
@@ -1,12 +1,20 @@
 package eu.iksproject.kres.manager.ontology;
 
 import org.semanticweb.owlapi.model.IRI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import eu.iksproject.kres.api.manager.ontology.CoreOntologySpace;
 import eu.iksproject.kres.api.manager.ontology.CustomOntologySpace;
 import eu.iksproject.kres.api.manager.ontology.OntologyInputSource;
+import eu.iksproject.kres.api.manager.ontology.OntologyScope;
+import eu.iksproject.kres.api.manager.ontology.OntologySpace;
 import eu.iksproject.kres.api.manager.ontology.OntologySpaceFactory;
+import eu.iksproject.kres.api.manager.ontology.OntologySpaceListener;
+import eu.iksproject.kres.api.manager.ontology.ScopeRegistry;
 import eu.iksproject.kres.api.manager.ontology.SessionOntologySpace;
+import eu.iksproject.kres.api.manager.ontology.UnmodifiableOntologySpaceException;
+import eu.iksproject.kres.api.storage.OntologyStorage;
 
 /**
  * Utility class that generates default implementations of the three types of
@@ -17,6 +25,16 @@ import eu.iksproject.kres.api.manager.on
  */
 public class OntologySpaceFactoryImpl implements OntologySpaceFactory {
 
+	protected Logger log = LoggerFactory.getLogger(getClass());
+
+	protected ScopeRegistry registry;
+	protected OntologyStorage storage;
+
+	public OntologySpaceFactoryImpl(ScopeRegistry registry, OntologyStorage storage) {
+		this.registry = registry;
+		this.storage = storage;
+	}
+
 	/*
 	 * (non-Javadoc)
 	 * @see eu.iksproject.kres.api.manager.ontology.OntologySpaceFactory#createCoreOntologySpace(org.semanticweb.owlapi.model.IRI, eu.iksproject.kres.api.manager.ontology.OntologyInputSource)
@@ -24,8 +42,8 @@ public class OntologySpaceFactoryImpl im
 	@Override
 	public CoreOntologySpace createCoreOntologySpace(IRI scopeID,
 			OntologyInputSource coreSource) {
-		CoreOntologySpace s = new CoreOntologySpaceImpl(scopeID, coreSource);
-		// s.setUp();
+		CoreOntologySpace s = new CoreOntologySpaceImpl(scopeID,storage);
+		setupSpace(s, scopeID, coreSource);
 		return s;
 	}
 
@@ -36,8 +54,8 @@ public class OntologySpaceFactoryImpl im
 	@Override
 	public CustomOntologySpace createCustomOntologySpace(IRI scopeID,
 			OntologyInputSource customSource) {
-		CustomOntologySpace s = new CustomOntologySpaceImpl(scopeID , customSource);
-		// s.setUp();
+		CustomOntologySpace s = new CustomOntologySpaceImpl(scopeID,storage);
+		setupSpace(s, scopeID, customSource);
 		return s;
 	}
 
@@ -47,9 +65,26 @@ public class OntologySpaceFactoryImpl im
 	 */
 	@Override
 	public SessionOntologySpace createSessionOntologySpace(IRI scopeID) {
-		SessionOntologySpace s = new SessionOntologySpaceImpl(scopeID);
+		SessionOntologySpace s = new SessionOntologySpaceImpl(scopeID,storage);
 		// s.setUp();
 		return s;
 	}
 
+	private void setupSpace(OntologySpace s, IRI scopeID,
+			OntologyInputSource rootSource) {
+		// FIXME: ensure that this is not null
+		OntologyScope parentScope = registry.getScope(scopeID);
+
+		if (parentScope != null && parentScope instanceof OntologySpaceListener)
+			s.addOntologySpaceListener((OntologySpaceListener) parentScope);
+		// Set the supplied ontology's parent as the root for this space.
+		try {
+			s.setTopOntology(rootSource, true);
+		} catch (UnmodifiableOntologySpaceException e) {
+			log.error("KReS :: Ontology space " + s.getID()
+					+ " found locked at creation time!", e);
+		}
+		// s.setUp();
+	}
+
 }

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/SessionOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/SessionOntologySpaceImpl.java?rev=1053689&r1=1053688&r2=1053689&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/SessionOntologySpaceImpl.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.manager/src/main/java/eu/iksproject/kres/manager/ontology/SessionOntologySpaceImpl.java Wed Dec 29 18:04:19 2010
@@ -9,18 +9,27 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import eu.iksproject.kres.api.manager.ontology.SessionOntologySpace;
+import eu.iksproject.kres.api.manager.ontology.SpaceType;
 import eu.iksproject.kres.api.manager.ontology.UnmodifiableOntologySpaceException;
+import eu.iksproject.kres.api.storage.OntologyStorage;
 import eu.iksproject.kres.manager.io.RootOntologySource;
 import eu.iksproject.kres.manager.util.StringUtils;
 
 public class SessionOntologySpaceImpl extends AbstractOntologySpaceImpl
 		implements SessionOntologySpace {
 
-	public SessionOntologySpaceImpl(IRI scopeID) {
+	
+	public static final String SUFFIX = SpaceType.SESSION.getIRISuffix();
+//	static {
+//		SUFFIX = SpaceType.SESSION.getIRISuffix();
+//	}
+	
+	public SessionOntologySpaceImpl(IRI scopeID, OntologyStorage storage) {
 		// FIXME : sync session id with session space ID
-		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/session-"
-				+ new Random().nextLong()), scopeID);
-		Logger log = LoggerFactory.getLogger(getClass());
+		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+				+ SpaceType.SESSION.getIRISuffix() + "-"
+				+ new Random().nextLong()), SpaceType.SESSION,storage/*, scopeID*/);
+
 		IRI iri = IRI.create(StringUtils.stripIRITerminator(getID())
 				+ "/root.owl");
 		try {
@@ -40,11 +49,12 @@ public class SessionOntologySpaceImpl ex
 		}
 	}
 
-	public SessionOntologySpaceImpl(IRI scopeID,
+	public SessionOntologySpaceImpl(IRI scopeID, OntologyStorage storage,
 			OWLOntologyManager ontologyManager) {
 		// FIXME : sync session id with session space ID
-		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/session-"
-				+ new Random().nextLong()), scopeID, ontologyManager);
+		super(IRI.create(StringUtils.stripIRITerminator(scopeID) + "/"
+				+ SpaceType.SESSION.getIRISuffix() + "-"
+				+ new Random().nextLong()), SpaceType.SESSION,storage, /*scopeID,*/ ontologyManager);
 		Logger log = LoggerFactory.getLogger(getClass());
 		IRI iri = IRI.create(StringUtils.stripIRITerminator(getID())
 				+ "/root.owl");