X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fvariables%2FStandardProceduralChildVariable.java;h=e7ba5ab7879c8749ffc527597e47c205629539f6;hb=refs%2Fchanges%2F31%2F3831%2F1;hp=a5b50f6f36bc5dc7f1368ff0acc80d9ea4a46e23;hpb=1dfeb7d5c49b1391cd9d877e1eddab18995cb151;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java index a5b50f6f3..e7ba5ab78 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java @@ -1,8 +1,5 @@ package org.simantics.structural2.variables; -import gnu.trove.map.hash.THashMap; -import gnu.trove.set.hash.THashSet; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -10,13 +7,13 @@ import java.util.HashMap; 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; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Statement; -import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.NoSingleResultException; import org.simantics.db.layer0.function.All; @@ -39,9 +36,12 @@ import org.simantics.structural2.procedural.Terminal; import org.simantics.utils.datastructures.Pair; import org.slf4j.LoggerFactory; +import gnu.trove.map.hash.THashMap; + public class StandardProceduralChildVariable extends AbstractChildVariable { - private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StandardProceduralChildVariable.class); + private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StandardProceduralChildVariable.class); + /* * Extension points * @@ -64,102 +64,6 @@ public class StandardProceduralChildVariable extends AbstractChildVariable { final private Map properties; final private List propertyIdentity; - public static class FixedConnection implements org.simantics.structural2.variables.Connection { - - final public Collection> cps = new ArrayList>(); - - final private Variable parent; - - public FixedConnection(Variable parent) { - this.parent = parent; - } - - @Override - public Collection getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException { - - Set result = new THashSet(); - for(Pair cp : cps) { - Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); - Variable cp2 = component.getPossibleProperty(graph, cp.second); - if(cp2 != null) - for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) { - result.add(desc.getVariable(graph)); - } - else - LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph)); - } - return result; - - } - - @Override - public Collection getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException { - - Set result = new THashSet(); - for(Pair cp : cps) { - Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); - Variable cp2 = component.getPossibleProperty(graph, cp.second); - if(cp2 != null) - for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) { - result.add(desc.getURI(graph)); - } - else - LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph)); - } - return result; - - } - - @Override - public Collection getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException { - - Set result = new THashSet(); - for(Pair cp : cps) { - Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); - Variable cp2 = component.getPossibleProperty(graph, cp.second); - if(cp2 != null) - result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType)); - else - LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph)); - } - return result; - - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((cps == null) ? 0 : cps.hashCode()); - result = prime * result - + ((parent == null) ? 0 : parent.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - FixedConnection other = (FixedConnection) obj; - if (cps == null) { - if (other.cps != null) - return false; - } else if (!cps.equals(other.cps)) - return false; - if (parent == null) { - if (other.parent != null) - return false; - } else if (!parent.equals(other.parent)) - return false; - return true; - } - - } - public StandardProceduralChildVariable(ReadGraph graph, Variable parent, VariableNode node, String name, Resource type, List properties, Collection conns) throws DatabaseException { super(node); assert name != null; @@ -208,10 +112,18 @@ public class StandardProceduralChildVariable extends AbstractChildVariable { for(Property p : properties) { String pn = graph.getRelatedValue(p.relation, L0.HasName, Bindings.STRING); if(p.value == null) { - Logger.defaultLogError("StandardProceduralChildVariable " + getURI(graph) + ": null value for property " + pn); + LOGGER.error("StandardProceduralChildVariable " + getURI(graph) + ": null value for property " + pn); } 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) ); } @@ -242,7 +154,7 @@ public class StandardProceduralChildVariable extends AbstractChildVariable { fc = new FixedConnection(parent); map.put(p, fc); } - fc.cps.addAll(cps); + fc.addAll(cps); } } for(Map.Entry entry : map.entrySet()) { @@ -271,7 +183,7 @@ public class StandardProceduralChildVariable extends AbstractChildVariable { public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException { if (graph.isInheritedFrom(type, baseType)) return type; - throw new NoSingleResultException("variable " + getPossibleURI(graph) + " has no type"); + throw new NoSingleResultException("variable " + getPossibleURI(graph) + " has no type", -1); } @Override