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;
18 import org.wamblee.system.graph.Edge;
19 import org.wamblee.system.graph.EdgeFilter;
22 * Filter used to explicitly connect required and provided interfaces within a
25 * @author Erik Brakkee
27 public class ConnectExternalProvidedProvidedFilter implements EdgeFilter {
28 private String externalProvided;
30 private String component;
32 private String provided;
35 * Creates a new ConnectExternalProvidedProvidedFilter object.
38 public ConnectExternalProvidedProvidedFilter(String aExternalProvided,
39 String aComponent, String aProvided) {
40 externalProvided = aExternalProvided;
41 component = aComponent;
44 if (externalProvided == null) {
45 throw new IllegalArgumentException(
46 "External provided interface name must be specified.");
49 if (component == null) {
50 throw new IllegalArgumentException(
51 "Component name must be specified");
54 if (provided == null) {
55 throw new IllegalArgumentException(
56 "Provided interface name of internal component must be specified");
61 public boolean isViolated(Edge aEdge) {
62 if (aEdge.getFrom() instanceof ExternalProvidedInterfaceNode &&
63 aEdge.getTo() instanceof ProvidedInterfaceNode) {
64 return isViolated((ExternalProvidedInterfaceNode) aEdge.getFrom(),
65 (ProvidedInterfaceNode) aEdge.getTo());
71 private boolean isViolated(ExternalProvidedInterfaceNode aFrom,
72 ProvidedInterfaceNode aTo) {
73 if (!aFrom.getName().equals(externalProvided)) {
74 return false; // wrong provided interface.
77 if (aTo.getComponent().getName().equals(component) &&
78 aTo.getProvided().getName().equals(provided)) {