-package org.simantics.structural2.scl;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.procedure.adapter.TransientCacheListener;\r
-import org.simantics.db.common.request.IndexRoot;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.scl.runtime.SCLContext;\r
-import org.simantics.scl.runtime.function.Function1;\r
-\r
-/**\r
- * Compiles an SCL expression that is attached to a literal\r
- * whose parent is a component that is a part of a component type.\r
- * \r
- * @author Hannu Niemistö\r
- */\r
-public class CompileStructuralValueRequest extends AbstractCompileStructuralValueRequest {\r
- \r
- protected final Resource component;\r
- protected final Resource literal;\r
- \r
- public CompileStructuralValueRequest(Resource component, Resource literal, Resource relation) {\r
- super(relation);\r
- this.component = component;\r
- this.literal = literal;\r
- }\r
- \r
- public CompileStructuralValueRequest(ReadGraph graph, Variable context) throws DatabaseException {\r
- this(context.getParent(graph).getRepresents(graph),\r
- context.getRepresents(graph),\r
- context.getPredicateResource(graph));\r
- }\r
- \r
- public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {\r
- SCLContext sclContext = SCLContext.getCurrent();\r
- Object oldGraph = sclContext.get("graph");\r
- CompileStructuralValueRequest request = new CompileStructuralValueRequest(graph, context);\r
- try {\r
- Function1<Variable,Object> exp = graph.syncRequest(request, TransientCacheListener.<Function1<Variable,Object>>instance());\r
- sclContext.put("graph", graph);\r
- return exp.apply(context);\r
- } catch (Throwable t) {\r
- throw new DatabaseException("Compiling structural value request for component=" + request.component + ", literal=" + request.literal + " and relation " + request.relation + " failed!", t);\r
- } finally {\r
- sclContext.put("graph", oldGraph);\r
- }\r
- }\r
- \r
- @Override\r
- protected String getExpressionText(ReadGraph graph)\r
- throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- return graph.getRelatedValue(literal, L0.SCLValue_expression, Bindings.STRING);\r
- }\r
-\r
- @Override\r
- protected Resource getIndexRoot(ReadGraph graph) throws DatabaseException {\r
- return graph.syncRequest(new IndexRoot(literal));\r
- }\r
-\r
- @Override\r
- protected Resource getComponentType(ReadGraph graph)\r
- throws DatabaseException {\r
- // This is possible e.g. for interface expressions inside procedurals\r
- if(component == null) return null;\r
- return graph.syncRequest(new FindPossibleComponentTypeRequest(component));\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + ((component == null) ? 0 : component.hashCode());\r
- result = prime * result + ((literal == null) ? 0 : literal.hashCode());\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- CompileStructuralValueRequest other = (CompileStructuralValueRequest) obj;\r
- if (component == null) {\r
- if (other.component != null)\r
- return false;\r
- } else if (!component.equals(other.component))\r
- return false;\r
- if (literal == null) {\r
- if (other.literal != null)\r
- return false;\r
- } else if (!literal.equals(other.literal))\r
- return false;\r
- return true;\r
- }\r
- \r
-}\r
+package org.simantics.structural2.scl;
+
+import org.simantics.databoard.Bindings;
+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.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.layer0.Layer0;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function1;
+
+/**
+ * Compiles an SCL expression that is attached to a literal
+ * whose parent is a component that is a part of a component type.
+ *
+ * @author Hannu Niemistö
+ */
+public class CompileStructuralValueRequest extends AbstractCompileStructuralValueRequest {
+
+ protected final Resource component;
+ protected final Resource literal;
+
+ public CompileStructuralValueRequest(Resource component, Resource literal, Resource relation) {
+ super(relation);
+ this.component = component;
+ this.literal = literal;
+ }
+
+ public CompileStructuralValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
+ this(context.getParent(graph).getRepresents(graph),
+ context.getRepresents(graph),
+ context.getPredicateResource(graph));
+ }
+
+ public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.get("graph");
+ CompileStructuralValueRequest request = new CompileStructuralValueRequest(graph, context);
+ try {
+ Function1<Variable,Object> exp = graph.syncRequest(request, TransientCacheListener.<Function1<Variable,Object>>instance());
+ sclContext.put("graph", graph);
+ return exp.apply(context);
+ } catch (Throwable t) {
+ throw new DatabaseException("Compiling structural value request for component=" + request.component + ", literal=" + request.literal + " and relation " + request.relation + " failed!", t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+ }
+
+ @Override
+ protected String getExpressionText(ReadGraph graph)
+ throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ return graph.getRelatedValue(literal, L0.SCLValue_expression, Bindings.STRING);
+ }
+
+ @Override
+ protected Resource getIndexRoot(ReadGraph graph) throws DatabaseException {
+ return graph.syncRequest(new IndexRoot(literal));
+ }
+
+ @Override
+ protected Resource getComponentType(ReadGraph graph)
+ throws DatabaseException {
+ // This is possible e.g. for interface expressions inside procedurals
+ if(component == null) return null;
+ return graph.syncRequest(new FindPossibleComponentTypeRequest(component));
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((component == null) ? 0 : component.hashCode());
+ result = prime * result + ((literal == null) ? 0 : literal.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CompileStructuralValueRequest other = (CompileStructuralValueRequest) obj;
+ if (component == null) {
+ if (other.component != null)
+ return false;
+ } else if (!component.equals(other.component))
+ return false;
+ if (literal == null) {
+ if (other.literal != null)
+ return false;
+ } else if (!literal.equals(other.literal))
+ return false;
+ return true;
+ }
+
+}