(no commit message)
[utils] / system / general / src / main / java / org / wamblee / system / container / Container.java
index 59067f974f2835d6980078ab8b240a518e628d58..60456c5e4cdb98f84b74ab811eeab0c96cac53bf 100644 (file)
@@ -16,6 +16,7 @@
 package org.wamblee.system.container;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -31,10 +32,10 @@ import org.wamblee.system.core.RequiredInterface;
 import org.wamblee.system.core.Scope;
 import org.wamblee.system.core.SystemAssemblyException;
 import org.wamblee.system.graph.CompositeEdgeFilter;
-import org.wamblee.system.graph.EdgeFilter;
 import org.wamblee.system.graph.component.ComponentGraph;
+import org.wamblee.system.graph.component.ConnectExternalProvidedProvidedFilter;
+import org.wamblee.system.graph.component.ConnectRequiredExternallyRequiredEdgeFilter;
 import org.wamblee.system.graph.component.ConnectRequiredProvidedEdgeFilter;
-import org.wamblee.system.graph.component.RequiredProvidedEdgeFactory;
 
 /**
  * Container consisting of multiple components.
@@ -63,7 +64,7 @@ public class Container extends AbstractComponent<Scope> {
      *            Required services by the container.
      */
     public Container(String aName, Component[] aComponents,
-            ProvidedInterface[] aProvided, RequiredInterface[] aRequired) {
+            List<ProvidedInterface> aProvided, List<RequiredInterface> aRequired) {
         super(aName, aProvided, aRequired);
         _components = new ArrayList<Component>();
 
@@ -74,6 +75,23 @@ public class Container extends AbstractComponent<Scope> {
             addComponent(component);
         }
     }
+    
+    /**
+     * Constructs the container
+     * 
+     * @param aName
+     *            Name of the container
+     * @param aComponents
+     *            Components.
+     * @param aProvided
+     *            Provided services of the container
+     * @param aRequired
+     *            Required services by the container.
+     */
+    public Container(String aName, Component[] aComponents,
+            ProvidedInterface[] aProvided, RequiredInterface[] aRequired) {
+        this(aName, aComponents, Arrays.asList(aProvided), Arrays.asList(aRequired));
+    }
 
     public Container(String aName) {
         this(aName, new Component[0], new ProvidedInterface[0],
@@ -110,20 +128,28 @@ public class Container extends AbstractComponent<Scope> {
     public void connectRequiredProvided(String aClientComponent, String aRequiredInterface, 
             String aServerComponent, String aProvidedInterface) {
         checkSealed();
+        // TODO validate 
         _edgeFilter.add(new ConnectRequiredProvidedEdgeFilter(aClientComponent, aRequiredInterface, aServerComponent, aProvidedInterface));
     }
     
+    /**
+     * Explicitly connects a externally required interface to an internally required interface. 
+     * @param aComponent Component requiring the interface (must be non-null). 
+     * @param aRequiredInterface Required interface of the component (must be non-null).
+     * @param aExternalRequiredInterface Externally required interface (must be non-null).
+     */
     public void connectExternalRequired(String aComponent, String aRequiredInterface, 
             String aExternalRequiredInterface) {
         checkSealed();
-        // TODO implement. 
-        throw new RuntimeException("not implemented");
+        // TODO validate
+        _edgeFilter.add(new ConnectRequiredExternallyRequiredEdgeFilter(
+                aComponent, aRequiredInterface, aExternalRequiredInterface));
     }
     
     public void connectExternalProvided(String aExternalProvided, String aComponent, String aProvidedInterface) {
         checkSealed();
-        // TODO implement. 
-        throw new RuntimeException("not implemented"); 
+        // TODO validate
+        _edgeFilter.add(new ConnectExternalProvidedProvidedFilter(aExternalProvided, aComponent, aProvidedInterface));
     }
 
 
@@ -194,7 +220,7 @@ public class Container extends AbstractComponent<Scope> {
     protected Scope doStart(Scope aExternalScope) {
         checkSealed();
         validate();
-        Scope scope = new DefaultScope(getProvidedInterfaces(), aExternalScope);
+        Scope scope = new DefaultScope(getProvidedInterfaces().toArray(new ProvidedInterface[0]), aExternalScope);
         ComponentGraph graph = doStartOptionalDryRun(scope, false);
         exposeProvidedInterfaces(graph, aExternalScope, scope);
         seal();