2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.system.graph.component;
19 import org.wamblee.system.core.SystemAssemblyException;
20 import org.wamblee.system.graph.Edge;
21 import org.wamblee.system.graph.Graph;
22 import org.wamblee.system.graph.Node;
23 import org.wamblee.system.graph.Visitor;
25 import java.util.List;
26 import java.util.logging.Logger;
29 * Visitor that checks whether all required external interfaces of the container
32 * @author Erik Brakkee
34 public class CheckExternallyRequiredVisitor implements Visitor {
35 private static final Logger LOG = Logger.getLogger(CheckExternallyRequiredVisitor.class.getName());
40 * Creates a new CheckExternallyRequiredVisitor object.
43 public CheckExternallyRequiredVisitor(Graph aGraph) {
48 public void visitEdge(Edge aEdge) {
53 public void visitNode(Node aNode) {
54 if (aNode instanceof ExternalRequiredInterfaceNode) {
55 ExternalRequiredInterfaceNode required = (ExternalRequiredInterfaceNode) aNode;
57 if (!required.getRequired().isOptional() &&
58 (required.getRequired().getProvider() == null)) {
59 throw new SystemAssemblyException(aNode +
60 ": External required interface is not provided");
63 List<Edge> edges = graph.findIncoming(aNode);
65 if (edges.isEmpty()) {
66 LOG.warning(aNode + ": Superfluous required interface");
69 for (Edge edge : edges) {
70 Node from = edge.getFrom();
71 assert from instanceof RequiredInterfaceNode;
73 RequiredInterfaceNode reqNode = (RequiredInterfaceNode) from;
75 if (!reqNode.getRequired().isOptional() &&
76 required.getRequired().isOptional()) {
77 throw new SystemAssemblyException(
79 ": externally required interface is optional but a corresponding internal required interface is mandatory: " +