import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import org.simantics.databoard.Bindings;
} else if (p.value instanceof Expression) {
Expression expression = (Expression)p.value;
this.properties.put(pn, new StructuralProceduralExpressionPropertyVariable(graph, this, p.relation, expression.text) );
+ } else if (this.properties.containsKey(pn)) {
+ // The property overrides the value of an asserted property variable
+ StandardAssertedGraphPropertyVariable assertedValue = (StandardAssertedGraphPropertyVariable) this.properties.get(pn);
+ if (Objects.equals(assertedValue.property.predicate, p.relation)) {
+ this.properties.put(pn, new StandardProdeduralPropertyVariable(graph, this, assertedValue, p.value));
+ } else {
+ LOGGER.warn("Ignored attempt to override asserted property {}/{}#{} with a different relation", parent.getURI(graph), name, pn);
+ }
} else {
this.properties.put(pn, new StandardConstantGraphPropertyVariable(graph, this, p.relation, p.value) );
}
--- /dev/null
+package org.simantics.structural2.variables;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.adapter.AdaptException;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.StandardAssertedGraphPropertyVariable;
+import org.simantics.db.layer0.variable.ValueAccessor;
+import org.simantics.db.layer0.variable.Variable;
+
+public class StandardProdeduralPropertyVariable extends StandardAssertedGraphPropertyVariable {
+
+ private Object defaultValue;
+
+ public StandardProdeduralPropertyVariable(ReadGraph graph,
+ StandardProceduralChildVariable parent,
+ StandardAssertedGraphPropertyVariable assertedVariable, Object value) throws DatabaseException {
+ super(graph, parent, assertedVariable.node, assertedVariable.parentResource, assertedVariable.property.predicate, assertedVariable.object);
+
+ this.defaultValue = value;
+ }
+
+ @Override
+ protected ValueAccessor getValueAccessor(ReadGraph graph) throws DatabaseException {
+ final ValueAccessor valueAccessor = super.getValueAccessor(graph);
+ return new ValueAccessor() {
+ @Override
+ public void setValue(WriteGraph graph, Variable context, Object value, Binding binding) throws DatabaseException {
+ valueAccessor.setValue(graph, context, value, binding);
+ }
+
+ @Override
+ public void setValue(WriteGraph graph, Variable context, Object value) throws DatabaseException {
+ valueAccessor.setValue(graph, context, value);
+ }
+
+ @Override
+ public Object getValue(ReadGraph graph, Variable context, Binding binding) throws DatabaseException {
+ if (node != null) {
+ return valueAccessor.getValue(graph, context, binding);
+ } else {
+ if (binding.isInstance(defaultValue))
+ return defaultValue;
+ else
+ try {
+ return Bindings.adapt(defaultValue, Bindings.OBJECT, binding);
+ } catch (AdaptException e) {
+ throw new DatabaseException("Failed to adapt object " + defaultValue + " to " + binding);
+ }
+ }
+ }
+
+ @Override
+ public Object getValue(ReadGraph graph, Variable context) throws DatabaseException {
+ if (node != null) {
+ return valueAccessor.getValue(graph, context);
+ } else {
+ return defaultValue;
+ }
+ }
+
+ @Override
+ public Datatype getDatatype(ReadGraph graph, Variable context) throws DatabaseException {
+ return valueAccessor.getDatatype(graph, context);
+ }
+ };
+ }
+}