]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantValueStandardGraphPropertyVariable.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / ConstantValueStandardGraphPropertyVariable.java
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantValueStandardGraphPropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantValueStandardGraphPropertyVariable.java
new file mode 100644 (file)
index 0000000..3b063f1
--- /dev/null
@@ -0,0 +1,54 @@
+package org.simantics.db.layer0.variable;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.adapter.AdaptException;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.type.Datatype;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class ConstantValueStandardGraphPropertyVariable extends StandardGraphPropertyVariable {\r
+\r
+       final private Object value;\r
+       final private Datatype datatype;\r
+\r
+       public ConstantValueStandardGraphPropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, Resource predicate, Object value, Datatype datatype) throws DatabaseException {\r
+               super(graph, parent, null, parentResource, predicate);\r
+               this.value = value;\r
+               this.datatype = datatype;\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public <T> T getValue(ReadGraph graph) throws DatabaseException {\r
+               return (T)value;\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {\r
+               try {\r
+                       return (T)Bindings.adapt(value, Bindings.getBinding(datatype), binding);\r
+               } catch (AdaptException e) {\r
+                       throw new DatabaseException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public Datatype getDatatype(ReadGraph graph) throws DatabaseException {\r
+               return datatype;\r
+       }\r
+\r
+       @Override\r
+       public void setValue(WriteGraph graph, Object value) throws DatabaseException {\r
+               throw new DatabaseException("setValue is not supported.");\r
+       }\r
+       \r
+       @Override\r
+       public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {\r
+               throw new DatabaseException("setValue is not supported.");\r
+       }\r
+       \r
+}\r