Removed DOCUMENT ME comments that were generated and applied source code
[utils] / system / general / src / main / java / org / wamblee / system / graph / component / LinkVisitor.java
1 /*
2  * Copyright 2008 the original author or authors.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.wamblee.system.graph.component;
17
18 import org.wamblee.system.core.ProvidedInterface;
19 import org.wamblee.system.core.SystemAssemblyException;
20 import org.wamblee.system.graph.DefaultEdge;
21 import org.wamblee.system.graph.Edge;
22 import org.wamblee.system.graph.Node;
23 import org.wamblee.system.graph.Visitor;
24
25 /**
26  * Visitor that creates links between required and provided interfaces as
27  * described by the edges in the graph. Specically it links together (1)
28  * required and provided interfaces of internal component of a container and (2)
29  * the providers of externally required interfaces and internal required
30  * interfaces.
31  * 
32  * @author Erik Brakkee
33  */
34 public class LinkVisitor implements Visitor {
35     @Override
36     public void visitEdge(Edge aEdge) {
37         Node from = aEdge.getFrom();
38         Node to = aEdge.getTo();
39
40         if (from instanceof RequiredInterfaceNode) {
41             RequiredInterfaceNode required = (RequiredInterfaceNode) from;
42
43             if (to instanceof ProvidedInterfaceNode) {
44                 ProvidedInterfaceNode provided = (ProvidedInterfaceNode) to;
45                 required.getRequired().setProvider(provided.getProvided());
46             } else if (to instanceof ExternalRequiredInterfaceNode) {
47                 ExternalRequiredInterfaceNode external = (ExternalRequiredInterfaceNode) to;
48                 ProvidedInterface provider = external.getRequired()
49                     .getProvider();
50
51                 if ((provider == null) && !required.getRequired().isOptional()) {
52                     throw new SystemAssemblyException("Mandatory interface '" +
53                         from + "' is not provided.");
54                 }
55
56                 if (provider != null) {
57                     required.getRequired().setProvider(provider);
58                 }
59             }
60         } else if (from instanceof ProvidedInterfaceNode) {
61             // Provided interfaces can only be published after the system has
62             // started.
63         }
64     }
65
66     @Override
67     public void visitNode(Node aNode) {
68         // Empty.
69     }
70 }