--- /dev/null
+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