X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Ffunction%2FCompileSCLValueRequest.java;fp=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Ffunction%2FCompileSCLValueRequest.java;h=9d39a27b7dd4fc84f97ffecd0f35594353a1140b;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/CompileSCLValueRequest.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/CompileSCLValueRequest.java new file mode 100644 index 000000000..9d39a27b7 --- /dev/null +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/CompileSCLValueRequest.java @@ -0,0 +1,63 @@ +package org.simantics.spreadsheet.graph.function; + +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.procedure.adapter.TransientCacheListener; +import org.simantics.db.common.request.IndexRoot; +import org.simantics.db.common.request.ResourceRead2; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RuntimeEnvironmentRequest; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; +import org.simantics.scl.compiler.runtime.RuntimeEnvironment; +import org.simantics.scl.runtime.SCLContext; +import org.simantics.scl.runtime.function.Function1; +import org.simantics.structural2.scl.CompileStructuralValueRequest; +import org.simantics.structural2.scl.ComponentTypeProperty; +import org.simantics.structural2.scl.ReadComponentTypeInterfaceRequest; + +public class CompileSCLValueRequest extends CompileStructuralValueRequest { + + public CompileSCLValueRequest(ReadGraph graph, Variable context) + throws DatabaseException { + super(graph, context); + } + + public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException { + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.get("graph"); + try { + Function1 exp = graph.syncRequest(new CompileSCLValueRequest(graph, context), + TransientCacheListener.>instance()); + sclContext.put("graph", graph); + return exp.apply(context); + } catch (DatabaseException e) { + throw (DatabaseException)e; + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } + } + + @Override + protected CompilationContext getCompilationContext(ReadGraph graph) throws DatabaseException { + Resource indexRoot = graph.syncRequest(new IndexRoot(literal)); + return graph.syncRequest(new ResourceRead2(component, indexRoot) { + @Override + public CompilationContext perform(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource parent = graph.getPossibleObject(resource, L0.PartOf); + Resource type = graph.getPossibleType(parent, L0.Entity); + RuntimeEnvironment runtimeEnvironment = graph.syncRequest(new RuntimeEnvironmentRequest(resource2)); + Map propertyMap = + graph.syncRequest(new ReadComponentTypeInterfaceRequest(type, runtimeEnvironment.getEnvironment()), + TransientCacheListener.>instance()); + return new CompilationContext(runtimeEnvironment, propertyMap); + } + }); + } + +}