]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/ReflectionExternalValue.java
Multiple readers and variable optimization
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / adapter / ReflectionExternalValue.java
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/ReflectionExternalValue.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/ReflectionExternalValue.java
new file mode 100644 (file)
index 0000000..6bc6afb
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.db.ExternalValue;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.scl.reflection.ReflectionUtils;
+import org.simantics.scl.reflection.ValueNotFoundException;
+
+public class ReflectionExternalValue implements ExternalValue {
+
+       @Override
+       public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
+               
+               try {
+                       return (T)ReflectionUtils.getValue(graph.getURI(resource)).getValue();
+               } catch(ValueNotFoundException e) {
+                       throw new DatabaseException(e);
+               } catch(ClassCastException e) {
+                       throw new DatabaseException(e);
+               }
+               
+       }
+
+}