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.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
13 public class StandardGraphResourcePropertyVariable extends StandardGraphPropertyVariable {
15 private static final Logger LOGGER = LoggerFactory.getLogger(StandardGraphResourcePropertyVariable.class);
17 public StandardGraphResourcePropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, Resource property) throws DatabaseException {
18 super(graph, parent, null, parentResource, property);
22 public <T> T getValue(ReadGraph graph) throws DatabaseException {
23 if (parentResource == null)
24 throw new MissingVariableValueException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
26 return (T)graph.getSingleObject(parentResource, property.predicate);
27 } catch (NoSingleResultException e) {
28 LOGGER.error("No object for " + parentResource + " " + property);
29 throw new MissingVariableValueException(getPossibleURI(graph), e);
34 public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {
35 if (parentResource == null)
36 throw new MissingVariableValueException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ").");
38 return (T)graph.getSingleObject(parentResource, property.predicate);
39 } catch (NoSingleResultException e) {
40 LOGGER.error("No object for " + parentResource + " " + property);
41 throw new MissingVariableValueException(getPossibleURI(graph), e);
46 public Datatype getDatatype(ReadGraph graph) throws DatabaseException {