]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphResourcePropertyVariable.java
Merge commit 'ad8333027322fda6b9a8a524c7a7e15a54c52f38'
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / StandardGraphResourcePropertyVariable.java
1 package org.simantics.db.layer0.variable;\r
2 \r
3 import org.simantics.databoard.binding.Binding;\r
4 import org.simantics.databoard.type.Datatype;\r
5 import org.simantics.db.ReadGraph;\r
6 import org.simantics.db.Resource;\r
7 import org.simantics.db.exception.DatabaseException;\r
8 import org.simantics.db.exception.NoSingleResultException;\r
9 import org.simantics.db.layer0.exception.MissingVariableValueException;\r
10 import org.simantics.db.layer0.exception.VariableException;\r
11 \r
12 public class StandardGraphResourcePropertyVariable extends StandardGraphPropertyVariable {\r
13         \r
14         public StandardGraphResourcePropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, Resource property) throws DatabaseException {\r
15             super(graph, parent, null, parentResource, property);\r
16         }\r
17 \r
18         @Override\r
19         public <T> T getValue(ReadGraph graph) throws DatabaseException {\r
20                 if (parentResource == null)\r
21                         throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");\r
22                 try {\r
23                 return (T)graph.getSingleObject(parentResource, property.predicate);\r
24                 } catch (NoSingleResultException e) {\r
25                         System.err.println("No object for " + parentResource + " " + property);\r
26                         throw new MissingVariableValueException(getPossibleURI(graph));\r
27                 } \r
28         }\r
29 \r
30         @Override\r
31         public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {\r
32                 if (parentResource == null)\r
33                         throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");\r
34                 try {\r
35             return (T)graph.getSingleObject(parentResource, property.predicate);\r
36                 } catch (NoSingleResultException e) {\r
37                         System.err.println("No object for " + parentResource + " " + property);\r
38                         throw new MissingVariableValueException(getPossibleURI(graph));\r
39                 } \r
40         }\r
41         \r
42         @Override\r
43         public Datatype getDatatype(ReadGraph graph) throws DatabaseException {\r
44             return null;\r
45         }\r
46         \r
47 }\r