    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.parameters.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&ouml;rg Schaible
    021     */
    022    @SuppressWarnings("serial")
    023    public final class CollectionConstraint extends CollectionComponentParameter implements Constraint {
    024
    025            protected final Constraint constraint;
    026
    027        public CollectionConstraint(final Constraint constraint) {
    028            this(constraint, false);
    029        }
    030
    031        public CollectionConstraint(final Constraint constraint, final boolean emptyCollection) {
    032            super(Object.class, emptyCollection);
    033            this.constraint = constraint;
    034        }
    035
    036        @Override
    037            public boolean evaluate(final ComponentAdapter adapter) {
    038            return constraint.evaluate(adapter);
    039        }
    040
    041        @Override
    042            public void accept(final PicoVisitor visitor) {
    043            super.accept(visitor);
    044            constraint.accept(visitor);
    045        }
    046    }