/* * Copyright 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * 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 org.wamblee.system.graph.Edge; import org.wamblee.system.graph.EdgeFilter; /** * Filter used to explicitly connect required and provided interfaces within a * container. * * @author Erik Brakkee */ public class ConnectRequiredExternallyRequiredEdgeFilter implements EdgeFilter { private String client; private String required; private String externalRequired; /** * Creates a new ConnectRequiredExternallyRequiredEdgeFilter object. * */ public ConnectRequiredExternallyRequiredEdgeFilter(String aClient, String aRequired, String aExternalRequired) { client = aClient; required = aRequired; externalRequired = aExternalRequired; if (client == null) { throw new IllegalArgumentException( "Client component must be specified"); } if (required == null) { throw new IllegalArgumentException( "Required interface must be specified"); } if (externalRequired == null) { throw new IllegalArgumentException( "External required interface must be specified"); } } @Override public boolean isViolated(Edge aEdge) { if (aEdge.getFrom() instanceof RequiredInterfaceNode && aEdge.getTo() instanceof ExternalRequiredInterfaceNode) { return isViolated((RequiredInterfaceNode) aEdge.getFrom(), (ExternalRequiredInterfaceNode) aEdge.getTo()); } return false; } private boolean isViolated(RequiredInterfaceNode aFrom, ExternalRequiredInterfaceNode aTo) { if (!aFrom.getComponent().getName().equals(client)) { return false; // wrong component. } if (!((required == null) || aFrom.getRequired().getName().equals( required))) { return false; // wrong interface } if (!aTo.getRequired().getName().equals(externalRequired)) { return true; // wrong externally required interface. } return false; } }