updated coding rules.
[utils] / system / general / src / main / java / org / wamblee / system / graph / component / ComponentGraph.java
index be861f309255da4deb64ed63cd12e63f15ab56da..f772299bcc53ad990c1be9d0593ac8f9608a80c1 100644 (file)
@@ -19,11 +19,10 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.wamblee.general.Pair;
-import org.wamblee.system.container.CompositeInterfaceRestriction;
-import org.wamblee.system.container.InterfaceRestriction;
 import org.wamblee.system.core.Component;
 import org.wamblee.system.core.ProvidedInterface;
 import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.graph.CompositeEdgeFilter;
 import org.wamblee.system.graph.DefaultEdge;
 import org.wamblee.system.graph.Edge;
 import org.wamblee.system.graph.Graph;
@@ -37,21 +36,15 @@ import org.wamblee.system.graph.Node;
  */
 public class ComponentGraph extends Graph {
     
-    private CompositeInterfaceRestriction _restriction; 
+    private boolean isLinked; 
+    private CompositeEdgeFilter edgeFilter; 
 
     /**
      * Constructs an empty component graph. 
      */
     public ComponentGraph() {
-        _restriction = new CompositeInterfaceRestriction(); 
-    }
-    
-    /**
-     * Adds a restriction that must be satisfied by the component model. 
-     * @param aRestriction Restriction. 
-     */
-    public void addRestriction(InterfaceRestriction aRestriction) { 
-        _restriction.add(aRestriction);
+        isLinked = false; 
+        edgeFilter = new CompositeEdgeFilter(); 
     }
     
     /**
@@ -80,7 +73,7 @@ public class ComponentGraph extends Graph {
      */
     public void validate() { 
         extend(new RequiredProvidedEdgeFactory());
-        accept(new ApplyRestrictionsVisitor(this, _restriction));
+        applyFilter(edgeFilter);
         accept(new CheckRequiredProvidedMultiplicityVisitor(this));
         accept(new CheckExternallyRequiredVisitor(this)); 
         accept(new CheckExternallyProvidedVisitor(this));
@@ -91,8 +84,12 @@ public class ComponentGraph extends Graph {
      * Links provided and required interfaces together in the component
      * model based on the graph model. 
      */
-    public void link() { 
+    public void link() {
+        if ( isLinked ) { 
+            return; 
+        }
         accept(new LinkVisitor());
+        isLinked = true; 
     }
     
     /**
@@ -120,7 +117,7 @@ public class ComponentGraph extends Graph {
      * provided interfaces. 
      * @param aComponent Component to add. 
      */
-    public void addComponent(Component aComponent) { 
+    public void addComponent(Component<?> aComponent) { 
         // Add required interfaces. 
         Node compNode = new ComponentNode(aComponent);
         List<Node> requiredNodes = new ArrayList<Node>();
@@ -150,4 +147,8 @@ public class ComponentGraph extends Graph {
             addEdge(new DefaultEdge(provNode, compNode));
         }
     }
+
+    public void addEdgeFilter(CompositeEdgeFilter aEdgeFilter) {
+        edgeFilter.add(aEdgeFilter);    
+    }
 }