X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fgraph%2Fcomponent%2FComponentGraph.java;h=f772299bcc53ad990c1be9d0593ac8f9608a80c1;hb=0d8d8f24656e585ee75558cfd6a4c661f8f14985;hp=15f86557ab2a55dccdec85b2d8604d6b3bfcc07a;hpb=9bc96feb1a8b20fdb87edbfca54297e206229112;p=utils diff --git a/system/general/src/main/java/org/wamblee/system/graph/component/ComponentGraph.java b/system/general/src/main/java/org/wamblee/system/graph/component/ComponentGraph.java index 15f86557..f772299b 100644 --- a/system/general/src/main/java/org/wamblee/system/graph/component/ComponentGraph.java +++ b/system/general/src/main/java/org/wamblee/system/graph/component/ComponentGraph.java @@ -19,20 +19,15 @@ 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; import org.wamblee.system.graph.Node; - -// TODO info superfluous required interfaces -// TODO check optional external required but mandatory internal. - /** * Represents a component graph and provides the bridge from the * component model to a graph model. The graph model is easier @@ -41,40 +36,36 @@ 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); + public ComponentGraph() { + isLinked = false; + edgeFilter = new CompositeEdgeFilter(); } /** * Adds an externally required interface of a container. * This should be called before any components of the container are * added. + * @param aComponent Component requiring the interface. * @param aInterface Required interface. */ - public void addRequiredInterface(RequiredInterface aInterface) { - addNode(new ExternalRequiredInterfaceNode(aInterface)); + public void addRequiredInterface(Component aComponent, RequiredInterface aInterface) { + addNode(new ExternalRequiredInterfaceNode(aComponent, aInterface)); } /** * Adds an externally provided interface of a container. - * This should be called after all components of the container have been added. + * This should be called after all components of the container have been added. + * @param aComponent Component providing the interface. * @param aInterface Provided interface. */ - public void addProvidedInterface(ProvidedInterface aInterface) { - addNode(new ExternalProvidedInterfaceNode(aInterface)); + public void addProvidedInterface(Component aComponent, ProvidedInterface aInterface) { + addNode(new ExternalProvidedInterfaceNode(aComponent, aInterface)); } /** @@ -82,9 +73,9 @@ 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()); + accept(new CheckExternallyRequiredVisitor(this)); accept(new CheckExternallyProvidedVisitor(this)); accept(new CheckStartupDependenciesVisitor(this)); } @@ -93,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; } /** @@ -122,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 requiredNodes = new ArrayList(); @@ -152,4 +147,8 @@ public class ComponentGraph extends Graph { addEdge(new DefaultEdge(provNode, compNode)); } } + + public void addEdgeFilter(CompositeEdgeFilter aEdgeFilter) { + edgeFilter.add(aEdgeFilter); + } }