]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Still fixing regression
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 2 Nov 2018 07:16:30 +0000 (09:16 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Fri, 2 Nov 2018 07:16:30 +0000 (09:16 +0200)
Change-Id: Id64301d7435983aeb6db8c4498aa6fae73a5c909

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/ContextualRelatedValue.java
bundles/org.simantics.structural2/src/org/simantics/structural2/variables/FixedConnection.java

index b5f939aaa70690dc2296c3f467d4fad683dd6f9c..75c480993af3933d0096de49f9e0d74b648e2f7a 100644 (file)
@@ -35,7 +35,10 @@ abstract public class ContextualRelatedValue implements ConverterComputationalVa
                     } if (context instanceof Resource) {
                         Resource resource = (Resource)context;
                         try {
-                               Function1<Object,Object> fn = getFunction(graph, null, resource, null);
+                            /*
+                             * Here converter is the object and context is the subject
+                             */
+                               Function1<Object,Object> fn = getFunction(graph, resource, converter, null);
                             return fn.apply(resource);
                         } catch (DatabaseException e) {
                             throw new RuntimeDatabaseException(e);
index 524d2737ca2e144c2bd0fc7a60a01aa9b523a9ad..1e170e30b5a7fd73c299967744a32f3572e27a0b 100644 (file)
@@ -10,176 +10,185 @@ import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.utils.datastructures.Pair;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.set.hash.THashSet;
 
 public class FixedConnection implements Connection, Connection2 {
 
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(FixedConnection.class);
+
     /*
      * This is the parent of the component to be connected
      */
     final private Variable procedural;
-    
-    final private Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
-    
+
+    final private Collection<Pair<String, Resource>> cps = new ArrayList<Pair<String, Resource>>();
+
     public FixedConnection(Variable procedural) {
         this.procedural = procedural;
     }
-    
-    public void addAll(List<Pair<String,Resource>> cps) throws DatabaseException {
+
+    public void addAll(List<Pair<String, Resource>> cps) throws DatabaseException {
         /*
          * For interface connections the name is null
          */
-        for(Pair<String,Resource> cp : cps) {
+        for (Pair<String, Resource> cp : cps) {
             this.cps.add(cp);
         }
     }
-    
+
     public int size() {
         return cps.size();
     }
-    
-    public void addConnectionDescriptors(ReadGraph graph, Variable curConfiguration, Collection<VariableConnectionPointDescriptor> result) throws DatabaseException {
-        for(Pair<String,Resource> cpzz : cps) {
-            // This is a connection to an interface terminal. It is handled by ConnectionBrowser in separate logic. We should never have gotten this far
-            if(cpzz.first == null) {
+
+    public void addConnectionDescriptors(ReadGraph graph, Variable curConfiguration,
+            Collection<VariableConnectionPointDescriptor> result) throws DatabaseException {
+        for (Pair<String, Resource> cpzz : cps) {
+            // This is a connection to an interface terminal. It is handled by
+            // ConnectionBrowser in separate logic. We should never have gotten this far
+            if (cpzz.first == null) {
                 String message = "Lifted connection was not resolved. Child = " + procedural.getURI(graph);
                 throw new DatabaseException(message);
             }
             result.add(new PairConnectionDescriptor(curConfiguration, cpzz));
         }
     }
-    
+
     @Override
     public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
         Set<Variable> result = new THashSet<Variable>();
-        for(Pair<String,Resource> cp : cps) {
-            Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first); 
+        for (Pair<String, Resource> cp : cps) {
+            Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
             Variable cp2 = component.getPossibleProperty(graph, cp.second);
-            if(cp2 != null)
-                for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
+            if (cp2 != null)
+                for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second,
+                        relationType)) {
                     result.add(desc.getVariable(graph));
                 }
             else
-                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+                LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
         }
         return result;
     }
-    
-       @Override
-       public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
+
+    @Override
+    public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
         Set<String> result = new THashSet<String>();
-        for(Pair<String,Resource> cp : cps) {
+        for (Pair<String, Resource> cp : cps) {
             Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
             Variable cp2 = component.getPossibleProperty(graph, cp.second);
-            if(cp2 != null)
-                for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
+            if (cp2 != null)
+                for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second,
+                        relationType)) {
                     result.add(desc.getURI(graph));
                 }
             else
-                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+                LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
         }
         return result;
-       }
-       
-       @Override
-       public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
+    }
+
+    @Override
+    public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+            Resource relationType) throws DatabaseException {
         Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
-        for(Pair<String,Resource> cp : cps) {
-            Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first); 
+        for (Pair<String, Resource> cp : cps) {
+            Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
             Variable cp2 = component.getPossibleProperty(graph, cp.second);
-            if(cp2 != null)
+            if (cp2 != null)
                 result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
             else
-                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+                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 + ((procedural == null) ? 0 : procedural.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 (procedural == null) {
+            if (other.procedural != null)
+                return false;
+        } else if (!procedural.equals(other.procedural))
+            return false;
+        return true;
+    }
 
     @Override
-       public int hashCode() {
-               final int prime = 31;
-               int result = 1;
-               result = prime * result + ((cps == null) ? 0 : cps.hashCode());
-               result = prime * result
-                               + ((procedural == null) ? 0 : procedural.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 (procedural == null) {
-                       if (other.procedural != null)
-                               return false;
-               } else if (!procedural.equals(other.procedural))
-                       return false;
-               return true;
-       }
-
-       @Override
-       public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
-               Variable component_, Resource relationType) throws DatabaseException {
+    public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+            Variable component, Resource relationType) throws DatabaseException {
         Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
-        for(Pair<String,Resource> cp : cps) {
-            Variable component = cp.first == null ? component_.getParent(graph) : component_;
-            Variable cp2 = component.getPossibleProperty(graph, cp.second);
-            if(cp2 != null)
-                result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
+        for (Pair<String, Resource> cp : cps) {
+            Variable base = cp.first == null ? component.getParent(graph) : component;
+            Variable cp2 = base.getPossibleProperty(graph, cp.second);
+            if (cp2 != null)
+                result.addAll(ConnectionBrowser.flatten(graph, base, cp.second, relationType));
             else
-                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+                LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
         }
         return result;
-       }
-       
-       @Override
-       public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component_, Resource relationType)
-               throws DatabaseException {
+    }
+
+    @Override
+    public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType)
+            throws DatabaseException {
         Set<Variable> result = new THashSet<Variable>();
-        for(Pair<String,Resource> cp : cps) {
-            Variable component = cp.first == null ? component_.getParent(graph) : component_;
-            Variable cp2 = component.getPossibleProperty(graph, cp.second);
-            if(cp2 != null)
-                for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
+        for (Pair<String, Resource> cp : cps) {
+            Variable base = cp.first == null ? component.getParent(graph) : component;
+            Variable cp2 = base.getPossibleProperty(graph, cp.second);
+            if (cp2 != null)
+                for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, base, cp.second,
+                        relationType)) {
                     result.add(desc.getVariable(graph));
                 }
             else
-                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+                LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
         }
         return result;
-       }
-       
-       @Override
-       public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component_, Resource relationType)
-               throws DatabaseException {
+    }
+
+    @Override
+    public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType)
+            throws DatabaseException {
         Set<String> result = new THashSet<String>();
-        for(Pair<String,Resource> cp : cps) {
-            Variable component = cp.first == null ? component_.getParent(graph) : component_;
-            Variable cp2 = component.getPossibleProperty(graph, cp.second);
-            if(cp2 != null)
-                for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
+        for (Pair<String, Resource> cp : cps) {
+            Variable base = cp.first == null ? component.getParent(graph) : component;
+            Variable cp2 = base.getPossibleProperty(graph, cp.second);
+            if (cp2 != null)
+                for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, base, cp.second,
+                        relationType)) {
                     result.add(desc.getURI(graph));
                 }
             else
-                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+                LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
         }
         return result;
-       }
+    }
 
     @Override
     public Connection2 getConnection2() {
         return this;
     }
-       
+
 }
\ No newline at end of file