1 package org.simantics.structural2.variables;
3 import org.simantics.databoard.Bindings;
4 import org.simantics.databoard.adapter.AdaptException;
5 import org.simantics.databoard.binding.Binding;
6 import org.simantics.databoard.type.Datatype;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.WriteGraph;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.layer0.variable.StandardAssertedGraphPropertyVariable;
11 import org.simantics.db.layer0.variable.ValueAccessor;
12 import org.simantics.db.layer0.variable.Variable;
14 public class StandardProdeduralPropertyVariable extends StandardAssertedGraphPropertyVariable {
16 private Object defaultValue;
18 public StandardProdeduralPropertyVariable(ReadGraph graph,
19 StandardProceduralChildVariable parent,
20 StandardAssertedGraphPropertyVariable assertedVariable, Object value) throws DatabaseException {
21 super(graph, parent, assertedVariable.node, assertedVariable.parentResource, assertedVariable.property.predicate, assertedVariable.object);
23 this.defaultValue = value;
27 protected ValueAccessor getValueAccessor(ReadGraph graph) throws DatabaseException {
28 final ValueAccessor valueAccessor = super.getValueAccessor(graph);
29 return new ValueAccessor() {
31 public void setValue(WriteGraph graph, Variable context, Object value, Binding binding) throws DatabaseException {
32 valueAccessor.setValue(graph, context, value, binding);
36 public void setValue(WriteGraph graph, Variable context, Object value) throws DatabaseException {
37 valueAccessor.setValue(graph, context, value);
41 public Object getValue(ReadGraph graph, Variable context, Binding binding) throws DatabaseException {
43 return valueAccessor.getValue(graph, context, binding);
45 if (binding.isInstance(defaultValue))
49 return Bindings.adapt(defaultValue, Bindings.OBJECT, binding);
50 } catch (AdaptException e) {
51 throw new DatabaseException("Failed to adapt object " + defaultValue + " to " + binding);
57 public Object getValue(ReadGraph graph, Variable context) throws DatabaseException {
59 return valueAccessor.getValue(graph, context);
66 public Datatype getDatatype(ReadGraph graph, Variable context) throws DatabaseException {
67 return valueAccessor.getDatatype(graph, context);