X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fgraph%2Fcomponent%2FComponentGraph.java;h=b41c41c81445d277165fed2eb7f44414b224d944;hb=ee26f9544a0bf7f49390990c68981676e0e51014;hp=20313b5983785b82d8b9d033a929a6fb3942e64f;hpb=b522989a5f4a984c2c3ad0780886ac7c7b044bc7;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 20313b59..b41c41c8 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,51 +19,77 @@ 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 + * to work with to implement specific actions and validations than + * the component model. + */ public class ComponentGraph extends Graph { - private CompositeInterfaceRestriction _restriction; + private boolean _isLinked; + private CompositeEdgeFilter _edgeFilter; - public ComponentGraph() { - _restriction = new CompositeInterfaceRestriction(); - } - - public void addRestriction(InterfaceRestriction aRestriction) { - _restriction.add(aRestriction); + /** + * Constructs an empty component graph. + */ + public ComponentGraph() { + _isLinked = false; + _edgeFilter = new CompositeEdgeFilter(); } - public void addRequiredInterface(RequiredInterface aInterface) { - addNode(new ExternalRequiredInterfaceNode(aInterface)); + /** + * 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(Component aComponent, RequiredInterface aInterface) { + addNode(new ExternalRequiredInterfaceNode(aComponent, aInterface)); } - public void addProvidedInterface(ProvidedInterface aInterface) { - addNode(new ExternalProvidedInterfaceNode(aInterface)); + /** + * Adds an externally provided interface of a container. + * 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(Component aComponent, ProvidedInterface aInterface) { + addNode(new ExternalProvidedInterfaceNode(aComponent, aInterface)); } + /** + * Validates the component 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)); } - public void link() { + /** + * Links provided and required interfaces together in the component + * model based on the graph model. + */ + public void link() { + if ( _isLinked ) { + return; + } accept(new LinkVisitor()); + _isLinked = true; } /** @@ -86,7 +112,12 @@ public class ComponentGraph extends Graph { return result; } - public void addComponent(Component aComponent) { + /** + * Adds a component by adding required interfaces, components, and + * provided interfaces. + * @param aComponent Component to add. + */ + public void addComponent(Component aComponent) { // Add required interfaces. Node compNode = new ComponentNode(aComponent); List requiredNodes = new ArrayList(); @@ -116,4 +147,8 @@ public class ComponentGraph extends Graph { addEdge(new DefaultEdge(provNode, compNode)); } } + + public void addEdgeFilter(CompositeEdgeFilter aEdgeFilter) { + _edgeFilter.add(aEdgeFilter); + } }