From 080d7c58c8228aeefc00960b8fd50cf193a04c0c Mon Sep 17 00:00:00 2001 From: erik Date: Sun, 18 May 2008 08:34:02 +0000 Subject: [PATCH] --- .../wamblee/system/container/Container.java | 4 +- .../CheckExternallyRequiredVisitor.java | 50 +++++++++++++++---- ...ckRequiredProvidedMultiplicityVisitor.java | 4 +- .../graph/component/ComponentGraph.java | 20 ++++---- .../ExternalProvidedInterfaceNode.java | 9 +++- .../ExternalRequiredInterfaceNode.java | 11 +++- .../system/container/ContainerTest.java | 21 ++++---- 7 files changed, 79 insertions(+), 40 deletions(-) diff --git a/system/general/src/main/java/org/wamblee/system/container/Container.java b/system/general/src/main/java/org/wamblee/system/container/Container.java index cfc5b8aa..92aba214 100644 --- a/system/general/src/main/java/org/wamblee/system/container/Container.java +++ b/system/general/src/main/java/org/wamblee/system/container/Container.java @@ -224,13 +224,13 @@ public class Container extends AbstractComponent { private ComponentGraph createComponentGraph() { ComponentGraph graph = new ComponentGraph(); for (RequiredInterface req : getRequiredInterfaces()) { - graph.addRequiredInterface(req); + graph.addRequiredInterface(this, req); } for (Component comp : _components) { graph.addComponent(comp); } for (ProvidedInterface prov: getProvidedInterfaces()) { - graph.addProvidedInterface(prov); + graph.addProvidedInterface(this, prov); } graph.addRestriction(_restriction); diff --git a/system/general/src/main/java/org/wamblee/system/graph/component/CheckExternallyRequiredVisitor.java b/system/general/src/main/java/org/wamblee/system/graph/component/CheckExternallyRequiredVisitor.java index 9e412b6f..1ce53d07 100644 --- a/system/general/src/main/java/org/wamblee/system/graph/component/CheckExternallyRequiredVisitor.java +++ b/system/general/src/main/java/org/wamblee/system/graph/component/CheckExternallyRequiredVisitor.java @@ -12,24 +12,34 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.system.graph.component; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wamblee.system.core.SystemAssemblyException; import org.wamblee.system.graph.Edge; +import org.wamblee.system.graph.Graph; import org.wamblee.system.graph.Node; import org.wamblee.system.graph.Visitor; /** * Visitor that checks whether all required external interfaces of the container - * are provided. + * are provided. + * * @author Erik Brakkee - * + * */ public class CheckExternallyRequiredVisitor implements Visitor { - - public CheckExternallyRequiredVisitor() { - // Empty. + + private Log LOG = LogFactory.getLog(CheckExternallyRequiredVisitor.class); + + private Graph _graph; + + public CheckExternallyRequiredVisitor(Graph aGraph) { + _graph = aGraph; } @Override @@ -39,10 +49,30 @@ public class CheckExternallyRequiredVisitor implements Visitor { @Override public void visitNode(Node aNode) { - if ( aNode instanceof ExternalRequiredInterfaceNode) { - ExternalRequiredInterfaceNode required = (ExternalRequiredInterfaceNode) aNode; - if ( !required.getRequired().isOptional() && required.getRequired().getProvider() == null) { - throw new SystemAssemblyException(aNode + ": External required interface is not provided"); + if (aNode instanceof ExternalRequiredInterfaceNode) { + ExternalRequiredInterfaceNode required = (ExternalRequiredInterfaceNode) aNode; + if (!required.getRequired().isOptional() + && required.getRequired().getProvider() == null) { + throw new SystemAssemblyException(aNode + + ": External required interface is not provided"); + } + + List edges = _graph.findIncoming(aNode); + + if (edges.isEmpty()) { + LOG.warn(aNode + ": Superfluous required interface"); + } + for (Edge edge : edges) { + Node from = edge.getFrom(); + assert from instanceof RequiredInterfaceNode; + RequiredInterfaceNode reqNode = (RequiredInterfaceNode)from; + if (!reqNode.getRequired().isOptional() + && required.getRequired().isOptional()) { + throw new SystemAssemblyException( + aNode + + ": externally required interface is optional but a corresponding internal required interface is mandatory: " + + reqNode); + } } } } diff --git a/system/general/src/main/java/org/wamblee/system/graph/component/CheckRequiredProvidedMultiplicityVisitor.java b/system/general/src/main/java/org/wamblee/system/graph/component/CheckRequiredProvidedMultiplicityVisitor.java index 526b8923..608dfc16 100644 --- a/system/general/src/main/java/org/wamblee/system/graph/component/CheckRequiredProvidedMultiplicityVisitor.java +++ b/system/general/src/main/java/org/wamblee/system/graph/component/CheckRequiredProvidedMultiplicityVisitor.java @@ -55,14 +55,14 @@ public class CheckRequiredProvidedMultiplicityVisitor implements Visitor { RequiredInterfaceNode required = (RequiredInterfaceNode) aNode; List edges = _graph.findOutgoing(aNode); if (edges.size() > 1) { - createDuplicateException("Multiple internal providers of interface found", aNode, edges); + createDuplicateException("Multiple providers of required interface found", aNode, edges); } if (edges.size() == 0 && !required.getRequired().isOptional()) { throw new SystemAssemblyException( aNode + ": mandatpory required interface not provided by other components started earlier"); } - } else if ( aNode instanceof ProvidedInterfaceNode) { + } else if ( aNode instanceof ExternalProvidedInterfaceNode) { List edges = _graph.findOutgoing(aNode); if ( edges.size() > 1) { createDuplicateException("multiple internal matches for externally provided interface", aNode, edges); 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..be861f30 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 @@ -29,10 +29,6 @@ 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 @@ -46,7 +42,7 @@ public class ComponentGraph extends Graph { /** * Constructs an empty component graph. */ - public ComponentGraph() { + public ComponentGraph() { _restriction = new CompositeInterfaceRestriction(); } @@ -62,19 +58,21 @@ public class ComponentGraph extends Graph { * 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)); } /** @@ -84,7 +82,7 @@ public class ComponentGraph extends Graph { extend(new RequiredProvidedEdgeFactory()); accept(new ApplyRestrictionsVisitor(this, _restriction)); accept(new CheckRequiredProvidedMultiplicityVisitor(this)); - accept(new CheckExternallyRequiredVisitor()); + accept(new CheckExternallyRequiredVisitor(this)); accept(new CheckExternallyProvidedVisitor(this)); accept(new CheckStartupDependenciesVisitor(this)); } diff --git a/system/general/src/main/java/org/wamblee/system/graph/component/ExternalProvidedInterfaceNode.java b/system/general/src/main/java/org/wamblee/system/graph/component/ExternalProvidedInterfaceNode.java index 38801270..9f91447c 100644 --- a/system/general/src/main/java/org/wamblee/system/graph/component/ExternalProvidedInterfaceNode.java +++ b/system/general/src/main/java/org/wamblee/system/graph/component/ExternalProvidedInterfaceNode.java @@ -15,6 +15,7 @@ */ package org.wamblee.system.graph.component; +import org.wamblee.system.core.Component; import org.wamblee.system.core.ProvidedInterface; import org.wamblee.system.graph.Node; @@ -25,9 +26,11 @@ import org.wamblee.system.graph.Node; */ public class ExternalProvidedInterfaceNode implements Node { + private Component _component; private ProvidedInterface _provided; - public ExternalProvidedInterfaceNode(ProvidedInterface aProvided) { + public ExternalProvidedInterfaceNode(Component aComponent, ProvidedInterface aProvided) { + _component = aComponent; _provided = aProvided; } @@ -36,6 +39,10 @@ public class ExternalProvidedInterfaceNode implements Node { return _provided.getName(); } + public Component getComponent() { + return _component; + } + public ProvidedInterface getProvided() { return _provided; } diff --git a/system/general/src/main/java/org/wamblee/system/graph/component/ExternalRequiredInterfaceNode.java b/system/general/src/main/java/org/wamblee/system/graph/component/ExternalRequiredInterfaceNode.java index 3b195a65..5c65ebdb 100644 --- a/system/general/src/main/java/org/wamblee/system/graph/component/ExternalRequiredInterfaceNode.java +++ b/system/general/src/main/java/org/wamblee/system/graph/component/ExternalRequiredInterfaceNode.java @@ -15,6 +15,7 @@ */ package org.wamblee.system.graph.component; +import org.wamblee.system.core.Component; import org.wamblee.system.core.RequiredInterface; import org.wamblee.system.graph.Node; @@ -25,9 +26,11 @@ import org.wamblee.system.graph.Node; */ public class ExternalRequiredInterfaceNode implements Node { + private Component _component; private RequiredInterface _required; - public ExternalRequiredInterfaceNode(RequiredInterface aRequired) { + public ExternalRequiredInterfaceNode(Component aComponent, RequiredInterface aRequired) { + _component = aComponent; _required = aRequired; } @@ -36,12 +39,16 @@ public class ExternalRequiredInterfaceNode implements Node { return _required.getName(); } + public Component getComponent() { + return _component; + } + public RequiredInterface getRequired() { return _required; } @Override public String toString() { - return "EXTERNAL" + ":" + _required; + return _component.getQualifiedName() + ":" + _required; } } diff --git a/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java b/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java index 95d7e312..5908a85e 100644 --- a/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java +++ b/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java @@ -398,15 +398,12 @@ public class ContainerTest extends TestCase { .getProvidedInterfaces()[0]); container.getRequiredInterfaces()[1].setProvider(env .getProvidedInterfaces()[1]); - container.start(); - assertSame(env.getProvidedInterfaces()[0], container - .getRequiredInterfaces()[0].getProvider()); - assertSame(env.getProvidedInterfaces()[1], container - .getRequiredInterfaces()[1].getProvider()); - assertSame(env.getProvidedInterfaces()[0], application - .getRequiredInterfaces()[0].getProvider()); - assertSame(env.getProvidedInterfaces()[1], application - .getRequiredInterfaces()[1].getProvider()); + try { + container.start(); + } catch (SystemAssemblyException e) { + return; + } + fail(); } public void testSealed() { @@ -521,9 +518,9 @@ public class ContainerTest extends TestCase { top.addComponent(envcontainer).addComponent(appcontainer); top.start(); - AssertionUtils.assertEquals(new String[] { "start.environment", "start.application" }, - _tracker.getEvents(Thread.currentThread()).toArray( - new String[0])); + AssertionUtils.assertEquals(new String[] { "start.environment", + "start.application" }, _tracker.getEvents( + Thread.currentThread()).toArray(new String[0])); } } -- 2.31.1