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