1 package org.simantics.modeling.scl;
4 import java.util.Collection;
5 import java.util.Collections;
7 import org.simantics.Simantics;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.common.request.UnaryRead;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.scl.compiler.module.repository.UpdateListener;
12 import org.simantics.scl.compiler.source.ModuleSource;
13 import org.simantics.scl.compiler.source.PrecompiledModuleSource;
14 import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;
15 import org.simantics.scl.runtime.SCLContext;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import gnu.trove.procedure.TObjectProcedure;
21 public enum OntologyModuleSourceRepository implements ModuleSourceRepository {
24 private static final Logger LOGGER = LoggerFactory.getLogger(OntologyModuleSourceRepository.class);
26 static class ModuleSourceRequest extends UnaryRead<String, ModuleSource> {
28 public ModuleSourceRequest(String moduleName) {
33 public ModuleSource perform(ReadGraph graph) throws DatabaseException {
34 return new PrecompiledModuleSource(new OntologyModule(graph, parameter), -1.0);
40 public ModuleSource getModuleSource(final String moduleName,
41 UpdateListener listener) {
42 if(!moduleName.startsWith("http://"))
43 return null; // Don't do a graph request if this cannot be a resource
45 ReadGraph graph = (ReadGraph)SCLContext.getCurrent().get("graph");
49 return new PrecompiledModuleSource(new OntologyModule(graph, moduleName), -1.0);
52 return Simantics.getSession().syncRequest(new ModuleSourceRequest(moduleName));
53 } catch(DatabaseException e) {
54 LOGGER.error("Failed to read ontology module " + moduleName + ".", e);
60 public void forAllModules(TObjectProcedure<String> procedure) {
64 public Collection<String> getModuleNames() {
65 return Collections.emptyList();