2 * Copyright 2008 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;
23 * Filter used to explicitly connect required and provided interfaces
26 * @author Erik Brakkee
28 public class ConnectRequiredExternallyRequiredEdgeFilter implements EdgeFilter {
32 private String client;
37 private String required;
42 private String externalRequired;
45 * Creates a new ConnectRequiredExternallyRequiredEdgeFilter object.
47 * @param aClient DOCUMENT ME!
48 * @param aRequired DOCUMENT ME!
49 * @param aExternalRequired DOCUMENT ME!
51 public ConnectRequiredExternallyRequiredEdgeFilter(String aClient,
52 String aRequired, String aExternalRequired) {
55 externalRequired = aExternalRequired;
58 throw new IllegalArgumentException(
59 "Client component must be specified");
62 if (required == null) {
63 throw new IllegalArgumentException(
64 "Required interface must be specified");
67 if (externalRequired == null) {
68 throw new IllegalArgumentException(
69 "External required interface must be specified");
76 * @param aEdge DOCUMENT ME!
78 * @return DOCUMENT ME!
81 public boolean isViolated(Edge aEdge) {
82 if (aEdge.getFrom() instanceof RequiredInterfaceNode
83 && aEdge.getTo() instanceof ExternalRequiredInterfaceNode) {
84 return isViolated((RequiredInterfaceNode) aEdge.getFrom(),
85 (ExternalRequiredInterfaceNode) aEdge.getTo());
94 * @param aFrom DOCUMENT ME!
95 * @param aTo DOCUMENT ME!
97 * @return DOCUMENT ME!
99 private boolean isViolated(RequiredInterfaceNode aFrom,
100 ExternalRequiredInterfaceNode aTo) {
101 if (!aFrom.getComponent().getName().equals(client)) {
102 return false; // wrong component.
105 if (!((required == null)
106 || aFrom.getRequired().getName().equals(required))) {
107 return false; // wrong interface
110 if (!aTo.getRequired().getName().equals(externalRequired)) {
111 return true; // wrong externally required interface.