]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java
Merge branch 'private/db-threads' into private/threads-testing
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / AdaptValue.java
index c8bd03257f5783f0300ff08f1714069406bc48b1..02877596b00d4423fac8387a31bdc73cdde76e87 100644 (file)
@@ -1,12 +1,13 @@
 package org.simantics.db.common.request;
 
-import org.simantics.db.ExternalValue;
 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.reflection.ReflectionUtils;
+import org.simantics.scl.reflection.ValueNotFoundException;
 import org.simantics.scl.runtime.function.FunctionImpl3;
 
 /**
@@ -19,7 +20,7 @@ public class AdaptValue extends ResourceRead<Object> {
         super(resource);
     }
 
-    public static final FunctionImpl3 functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
+    private static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
 
                @Override
                public Object apply(ReadGraph graph, Resource resource, Object context) {
@@ -35,11 +36,12 @@ public class AdaptValue extends ResourceRead<Object> {
     @Override
     public Object perform(ReadGraph graph) throws DatabaseException {
         String uri = graph.getURI(resource);        
-        if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
-                       
-        ExternalValue ev = graph.adapt(resource, ExternalValue.class);
-        return ev.getValue(graph, resource);
-
+        try {
+                       if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
+            return ReflectionUtils.getValue(uri).getValue();
+        } catch (ValueNotFoundException e) {
+            throw new DatabaseException("Couldn't adapt the value " + uri, e);
+        }
     }
 
 }