1 package org.simantics.db.layer0.variable;
\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
12 public class StandardGraphResourcePropertyVariable extends StandardGraphPropertyVariable {
\r
14 public StandardGraphResourcePropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, Resource property) throws DatabaseException {
\r
15 super(graph, parent, null, parentResource, property);
\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
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
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
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
43 public Datatype getDatatype(ReadGraph graph) throws DatabaseException {
\r