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