From a5ed00d44573480dbb79f33766d9477430fa05bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Thu, 18 Oct 2018 10:49:37 +0300 Subject: [PATCH] Removed extra modules OntologyModule imported to namespace While fixing the problem, added some error logging in OntologyModule implementation gitlab #131 Change-Id: Ib36590f0901ed8a542afe4c9a225606c1f2109d8 --- .../db/layer0/util/EnvironmentRequest.java | 68 +++++++++++-------- .../scl/ontologymodule/OntologyModule.java | 25 ++++--- .../compiler/module/ImportDeclaration.java | 4 ++ 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/EnvironmentRequest.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/EnvironmentRequest.java index 2e37adee8..f1f235a88 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/EnvironmentRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/EnvironmentRequest.java @@ -15,11 +15,14 @@ import org.simantics.scl.compiler.module.repository.UpdateListener; import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.runtime.SCLContext; import org.simantics.utils.datastructures.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Finds the environment of a model or other index root. */ public abstract class EnvironmentRequest extends UnaryRead> { + private static final Logger LOGGER = LoggerFactory.getLogger(EnvironmentRequest.class); public EnvironmentRequest(Resource parameter) { super(parameter); @@ -78,6 +81,7 @@ public abstract class EnvironmentRequest extends UnaryRead(mainModuleUri) { - - UpdateListenerImpl sclListener; - - @Override - public void register(ReadGraph graph, Listener procedure) { - - SCLContext context = SCLContext.getCurrent(); - Object oldGraph = context.put("graph", graph); - try { - - if(procedure.isDisposed()) { - getEnvironment(environmentSpecification, procedure, null); - } else { - sclListener = new UpdateListenerImpl(environmentSpecification, procedure); - sclListener.notifyAboutUpdate(); + try { + return Pair.make(environmentSpecification, graph.syncRequest(new ParametrizedPrimitiveRead(mainModuleUri) { + + UpdateListenerImpl sclListener; + + @Override + public void register(ReadGraph graph, Listener procedure) { + + SCLContext context = SCLContext.getCurrent(); + Object oldGraph = context.put("graph", graph); + try { + + if(procedure.isDisposed()) { + getEnvironment(environmentSpecification, procedure, null); + } else { + sclListener = new UpdateListenerImpl(environmentSpecification, procedure); + sclListener.notifyAboutUpdate(); + } + + } finally { + context.put("graph", oldGraph); } - - } finally { - context.put("graph", oldGraph); + } - - } - - @Override - public void unregistered() { - if(sclListener != null) - sclListener.stopListening(); - } - - })); + + @Override + public void unregistered() { + if(sclListener != null) + sclListener.stopListening(); + } + + })); + } catch(DatabaseException e) { + LOGGER.error("Environment request failed", e); + throw e; + } } @Override diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/ontologymodule/OntologyModule.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/ontologymodule/OntologyModule.java index 96ee42182..aa1cffe23 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/ontologymodule/OntologyModule.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/ontologymodule/OntologyModule.java @@ -1,5 +1,6 @@ package org.simantics.modeling.scl.ontologymodule; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -15,7 +16,6 @@ import org.simantics.db.common.request.IndexRoot; import org.simantics.db.common.uri.UnescapedChildMapOfResource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.EnvironmentRequest; -import org.simantics.db.layer0.util.RuntimeEnvironmentRequest; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.scl.compiler.common.names.Name; @@ -58,18 +58,14 @@ public class OntologyModule extends LazyModule { public static final String SCL_TYPES_NAME = "SCLTypes"; private static final String DB_MODULE = "Simantics/DB"; private static final String VARIABLE_MODULE = "Simantics/Variable"; - private static final Collection DEPENDENCIES = Arrays.asList( - new ImportDeclaration(DB_MODULE, null), - new ImportDeclaration(VARIABLE_MODULE, null) - ); private static final TCon RESOURCE = Types.con(DB_MODULE, "Resource"); private static final TCon BROWSABLE = Types.con(DB_MODULE, "Browsable"); private static final TCon VARIABLE = Types.con(VARIABLE_MODULE, "Variable"); private Resource ontology; private String defaultLocalName; - private THashMap> childMaps = new THashMap>(); - private List importDeclarations; + private THashMap> childMaps = new THashMap<>(); + private ArrayList importDeclarations = new ArrayList<>(); private Environment environment; public OntologyModule(ReadGraph graph, String moduleName) throws DatabaseException { @@ -96,7 +92,8 @@ public class OntologyModule extends LazyModule { }); } }); - this.importDeclarations = pair.first.imports; + for(ImportDeclaration decl : pair.first.imports) + importDeclarations.add(decl.hidden()); this.environment = pair.second; } @@ -122,7 +119,11 @@ public class OntologyModule extends LazyModule { public final Resource resource; public JustResource(Resource resource) { this.resource = resource; - } + } + @Override + public String toString() { + return "JustResource(" + resource + ")"; + } } private static class ResourceAndSuffix implements ResourceSearchResult { public final Resource resource; @@ -130,7 +131,11 @@ public class OntologyModule extends LazyModule { public ResourceAndSuffix(Resource resource, String suffix) { this.resource = resource; this.suffix = suffix; - } + } + @Override + public String toString() { + return "ResourceAndSuffix(" + resource + ", " + suffix + ")"; + } } private ResourceSearchResult getResourceOrSuffixedResource(String name) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java index 77ac5e78e..8fe903f51 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java @@ -122,6 +122,10 @@ public class ImportDeclaration extends DeclarationAst { if (reexport != other.reexport) return false; return true; + } + + public ImportDeclaration hidden() { + return new ImportDeclaration(moduleName, null); } } -- 2.47.1