/* * 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 java.util.ArrayList; import java.util.Collection; import java.util.List; import org.wamblee.system.core.Component; import org.wamblee.system.core.ProvidedInterface; import org.wamblee.system.core.RequiredInterface; /** * Composite restriction that wraps a number of other restrictions. The restriction is * violated if one of the contained restrictions is violated. * * @author Erik Brakkee * */ public class CompositeInterfaceRestriction implements InterfaceRestriction { private List _restrictions; /** * Constructs the restriction. */ public CompositeInterfaceRestriction() { _restrictions = new ArrayList(); } /** * Constructs the restriction. * @param aRestrictions List of contained restrictions. */ public CompositeInterfaceRestriction(Collection aRestrictions) { this(); _restrictions.addAll(aRestrictions); } /** * Adds a restriction. * @param aRestriction Restriction. * @return Reference to this composite restriction to allow call chaining. */ public CompositeInterfaceRestriction add(InterfaceRestriction aRestriction) { _restrictions.add(aRestriction); return this; } @Override public boolean isViolated(Component aClient, RequiredInterface aRequired, Component aServer, ProvidedInterface aProvided) { for (InterfaceRestriction restriction: _restrictions) { if ( restriction.isViolated(aClient, aRequired, aServer, aProvided)) { return true; } } return false; } }