001 /***************************************************************************** 002 * Copyright (C) PicoContainer Organization. All rights reserved. * 003 * ------------------------------------------------------------------------- * 004 * The software in this package is published under the terms of the BSD * 005 * style license a copy of which has been included with this distribution in * 006 * the LICENSE.txt file. * 007 *****************************************************************************/ 008 009 package org.picocontainer.gems.constraints; 010 011 import org.picocontainer.ComponentAdapter; 012 import org.picocontainer.PicoVisitor; 013 import org.picocontainer.defaults.CollectionComponentParameter; 014 015 /** 016 * Constraint that collects/aggregates dependencies to as many components 017 * that satisfy the given constraint. 018 * 019 * @author Nick Sieger 020 * @author Jörg Schaible 021 * @version 1.1 022 */ 023 public class CollectionConstraint extends CollectionComponentParameter implements Constraint { 024 protected Constraint constraint; 025 026 public CollectionConstraint(Constraint constraint) { 027 this(constraint, false); 028 } 029 030 public CollectionConstraint(Constraint constraint, boolean emptyCollection) { 031 super(Object.class, emptyCollection); 032 this.constraint = constraint; 033 } 034 035 public boolean evaluate(ComponentAdapter adapter) { 036 return constraint.evaluate(adapter); 037 } 038 039 public void accept(PicoVisitor visitor) { 040 super.accept(visitor); 041 constraint.accept(visitor); 042 } 043 }