]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/scl/CompileSCLValueRequest.java
Find SCL references in SCLModuleEditor with Ctrl+Shift+G
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / scl / CompileSCLValueRequest.java
1 package org.simantics.modeling.scl;
2
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
5 import org.simantics.db.exception.DatabaseException;
6 import org.simantics.db.layer0.variable.Variable;
7 import org.simantics.scl.runtime.SCLContext;
8 import org.simantics.scl.runtime.function.Function1;
9 import org.simantics.structural2.scl.CompileStructuralValueRequest;
10
11 public class CompileSCLValueRequest extends CompileStructuralValueRequest {
12
13     public CompileSCLValueRequest(ReadGraph graph, Variable context)
14             throws DatabaseException {
15         super(graph, context);
16     }
17
18     public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
19         SCLContext sclContext = SCLContext.getCurrent();
20         Object oldGraph = sclContext.get("graph");
21         try {
22             Function1<Variable,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
23                     TransientCacheListener.<Function1<Variable,Object>>instance());
24             sclContext.put("graph", graph);
25             return exp.apply(context);
26         } catch (DatabaseException e) {
27             throw (DatabaseException)e;
28         } catch (Throwable t) {
29             throw new DatabaseException(t);
30         } finally {
31             sclContext.put("graph", oldGraph);
32         }
33     }
34     
35 }