/* * 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 ConnectExternalProvidedProvidedFilter implements EdgeFilter { private String externalProvided; private String component; private String provided; /** * Creates a new ConnectExternalProvidedProvidedFilter object. * */ public ConnectExternalProvidedProvidedFilter(String aExternalProvided, String aComponent, String aProvided) { externalProvided = aExternalProvided; component = aComponent; provided = aProvided; if (externalProvided == null) { throw new IllegalArgumentException( "External provided interface name must be specified."); } if (component == null) { throw new IllegalArgumentException( "Component name must be specified"); } if (provided == null) { throw new IllegalArgumentException( "Provided interface name of internal component must be specified"); } } @Override public boolean isViolated(Edge aEdge) { if (aEdge.getFrom() instanceof ExternalProvidedInterfaceNode && aEdge.getTo() instanceof ProvidedInterfaceNode) { return isViolated((ExternalProvidedInterfaceNode) aEdge.getFrom(), (ProvidedInterfaceNode) aEdge.getTo()); } return false; } private boolean isViolated(ExternalProvidedInterfaceNode aFrom, ProvidedInterfaceNode aTo) { if (!aFrom.getName().equals(externalProvided)) { return false; // wrong provided interface. } if (aTo.getComponent().getName().equals(component) && aTo.getProvided().getName().equals(provided)) { return false; // ok } return true; } }