/* * 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.container; import org.wamblee.system.core.Component; import org.wamblee.system.core.ProvidedInterface; import org.wamblee.system.core.RequiredInterface; /** * An interface restriction on the required interface of a component. * * @author Erik Brakkee * */ public class DefaultInterfaceRestriction implements InterfaceRestriction { private String _client; private String _required; private String _server; private String _provided; /** * Constructs the restriction. If the client name and required interface * name match, then the server name and interface name must also match. * Otherwise the restriction is violated. * * This can be used to explicitly connect required and provided interfaces * of components. * * @param aClient * Client or null if no restriction on the client. * @param aRequired * Required interface name or null if no restriction on the * required interface. * @param aServer * Server or null if no restriction on the server. * @param aProvided * Provided interface name or null if no restriction on the * provided interface. */ public DefaultInterfaceRestriction(String aClient, String aRequired, String aServer, String aProvided) { if ( aClient == null && aRequired == null ) { throw new IllegalArgumentException("No restriction on the required interface"); } if ( aServer == null && aProvided == null ) { throw new IllegalArgumentException("No restriction on the provided interface"); } _client = aClient; _required = aRequired; _server = aServer; _provided = aProvided; } @Override public boolean isViolated(Component aClient, RequiredInterface aRequired, Component aServer, ProvidedInterface aProvided) { if ( _client != null && !aClient.getName().equals(_client)) { return false; } if ( _required != null && !aRequired.getName().equals(_required)) { return false; } // The required interface matches if ( _server != null && !aServer.getName().equals(_server)) { // Server was specified and does not match. return true; } if ( _provided != null && !aProvided.getName().equals(_provided)) { // provided interface was specified and doe not match. return true; } // The required and provided interfaces match so this is not a violation. return false; } }