-package org.simantics.db.common.request;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.Functions;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.RuntimeDatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.scl.reflection.ReflectionUtils;\r
-import org.simantics.scl.reflection.ValueNotFoundException;\r
-import org.simantics.scl.runtime.function.FunctionImpl3;\r
-\r
-/**\r
- * Adapts a resource to (SCL) value.\r
- * @author Hannu Niemistö\r
- */\r
-public class AdaptValue extends ResourceRead<Object> {\r
- \r
- public AdaptValue(Resource resource) {\r
- super(resource);\r
- }\r
-\r
- private static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {\r
-\r
- @Override\r
- public Object apply(ReadGraph graph, Resource resource, Object context) {\r
- try {\r
- return Functions.exec(graph, resource, graph, resource, context);\r
- } catch (DatabaseException e) {\r
- throw new RuntimeDatabaseException(e);\r
- }\r
- }\r
-\r
- };\r
- \r
- @Override\r
- public Object perform(ReadGraph graph) throws DatabaseException {\r
- String uri = graph.getURI(resource); \r
- try {\r
- if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;\r
- return ReflectionUtils.getValue(uri).getValue();\r
- } catch (ValueNotFoundException e) {\r
- throw new DatabaseException("Couldn't adapt the value " + uri, e);\r
- }\r
- }\r
-\r
-}\r
+package org.simantics.db.common.request;
+
+import org.simantics.db.ComputationalValue;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.Functions;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.layer0.Layer0;
+import org.simantics.scl.runtime.function.FunctionImpl3;
+
+/**
+ * Adapts a resource to (SCL) value.
+ * @author Hannu Niemistö
+ */
+public class AdaptValue extends ResourceRead<Object> {
+
+ public AdaptValue(Resource resource) {
+ super(resource);
+ }
+
+ public static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
+
+ @Override
+ public Object apply(ReadGraph graph, Resource resource, Object context) {
+ try {
+ return Functions.exec(graph, resource, graph, resource, context);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
+ }
+ }
+
+ };
+
+ @Override
+ public Object perform(ReadGraph graph) throws DatabaseException {
+ String uri = graph.getURI(resource);
+ if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
+ ComputationalValue ev = graph.adapt(resource, ComputationalValue.class);
+ return ev.getValue(graph, resource);
+
+ }
+
+}