]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphResourcePropertyVariable.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / StandardGraphResourcePropertyVariable.java
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphResourcePropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphResourcePropertyVariable.java
new file mode 100644 (file)
index 0000000..aedfcb5
--- /dev/null
@@ -0,0 +1,47 @@
+package org.simantics.db.layer0.variable;\r
+\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.exception.DatabaseException;\r
+import org.simantics.db.exception.NoSingleResultException;\r
+import org.simantics.db.layer0.exception.MissingVariableValueException;\r
+import org.simantics.db.layer0.exception.VariableException;\r
+\r
+public class StandardGraphResourcePropertyVariable extends StandardGraphPropertyVariable {\r
+       \r
+       public StandardGraphResourcePropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, Resource property) throws DatabaseException {\r
+           super(graph, parent, null, parentResource, property);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getValue(ReadGraph graph) throws DatabaseException {\r
+               if (parentResource == null)\r
+                       throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");\r
+               try {\r
+               return (T)graph.getSingleObject(parentResource, property.predicate);\r
+               } catch (NoSingleResultException e) {\r
+                       System.err.println("No object for " + parentResource + " " + property);\r
+                       throw new MissingVariableValueException(getPossibleURI(graph));\r
+               } \r
+       }\r
+\r
+       @Override\r
+       public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {\r
+               if (parentResource == null)\r
+                       throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");\r
+               try {\r
+            return (T)graph.getSingleObject(parentResource, property.predicate);\r
+               } catch (NoSingleResultException e) {\r
+                       System.err.println("No object for " + parentResource + " " + property);\r
+                       throw new MissingVariableValueException(getPossibleURI(graph));\r
+               } \r
+       }\r
+       \r
+       @Override\r
+       public Datatype getDatatype(ReadGraph graph) throws DatabaseException {\r
+           return null;\r
+       }\r
+       \r
+}\r