]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java
Variable optimizations for documents (Simupedia)
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / variables / StandardProceduralChildVariable.java
index f133adee02e3c783b7e7fe5b8dc12ef93a6a4d5a..e96fd050a021ee1c9451efe19c1ee88d112d5855 100644 (file)
@@ -1,8 +1,5 @@
 package org.simantics.structural2.variables;
 
 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;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -16,7 +13,6 @@ import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Statement;
 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;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.layer0.function.All;
@@ -39,9 +35,12 @@ import org.simantics.structural2.procedural.Terminal;
 import org.simantics.utils.datastructures.Pair;
 import org.slf4j.LoggerFactory;
 
 import org.simantics.utils.datastructures.Pair;
 import org.slf4j.LoggerFactory;
 
+import gnu.trove.map.hash.THashMap;
+
 public class StandardProceduralChildVariable extends AbstractChildVariable {
 
 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
         * 
        /*
         * Extension points
         * 
@@ -64,102 +63,6 @@ public class StandardProceduralChildVariable extends AbstractChildVariable {
        final private Map<String, Variable> properties;
        final private List<Object> propertyIdentity;
        
        final private Map<String, Variable> properties;
        final private List<Object> propertyIdentity;
        
-    public static class FixedConnection implements org.simantics.structural2.variables.Connection {
-
-               final public Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
-        
-        final private Variable parent;
-        
-        public FixedConnection(Variable parent) {
-            this.parent = parent;
-        }
-        
-        @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 ? 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<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
-                       
-               Set<String> result = new THashSet<String>();
-            for(Pair<String,Resource> 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<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 ? 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<Property> properties, Collection<Connection> conns) throws DatabaseException {
                super(node);
                assert name != null;
        public StandardProceduralChildVariable(ReadGraph graph, Variable parent, VariableNode node, String name, Resource type, List<Property> properties, Collection<Connection> conns) throws DatabaseException {
                super(node);
                assert name != null;
@@ -208,7 +111,7 @@ public class StandardProceduralChildVariable extends AbstractChildVariable {
                for(Property p : properties) {
                    String pn = graph.getRelatedValue(p.relation, L0.HasName, Bindings.STRING);
                    if(p.value == null) {
                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 (p.value instanceof Expression) {
                        Expression expression = (Expression)p.value;
                            this.properties.put(pn, new StructuralProceduralExpressionPropertyVariable(graph, this, p.relation, expression.text) );
@@ -242,7 +145,7 @@ public class StandardProceduralChildVariable extends AbstractChildVariable {
                                fc = new FixedConnection(parent);
                                map.put(p, fc);
                        }
                                fc = new FixedConnection(parent);
                                map.put(p, fc);
                        }
-                       fc.cps.addAll(cps);             
+                       fc.addAll(cps);
                    }
                }
                for(Map.Entry<Resource, FixedConnection> entry : map.entrySet()) {
                    }
                }
                for(Map.Entry<Resource, FixedConnection> entry : map.entrySet()) {