    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     * Idea by Rachel Davies, Original code by various                           *
    009     *****************************************************************************/
    010    package org.nanocontainer.aop.defaults;
    011
    012    import org.nanocontainer.aop.ComponentPointcut;
    013
    014    /**
    015     * Component pointcut that matches against a component key.
    016     *
    017     * @author Stephen Molitor
    018     * @version $Revision: 3144 $
    019     */
    020    public class KeyEqualsComponentPointcut implements ComponentPointcut {
    021
    022        private final Object componentKey;
    023
    024        /**
    025         * Creates a new <code>KeyEqualsComponentPointcut</code> that matches
    026         * against <code>componentKey</code>.
    027         *
    028         * @param componentKey the component key to match against.
    029         */
    030        public KeyEqualsComponentPointcut(Object componentKey) {
    031            if (componentKey == null) {
    032                throw new NullPointerException("componentKey cannot be null");
    033            }
    034            this.componentKey = componentKey;
    035        }
    036
    037        /**
    038         * Tests to see if the <code>componentKey</code> matches the component key
    039         * passed to the constructor.
    040         *
    041         * @param componentKey the candidate component key to match against.
    042         * @return true if <code>componentKey</code> is equivalent to the
    043         *         component key passed to the constructor, else false.
    044         */
    045        public boolean picks(Object componentKey) {
    046            return this.componentKey.equals(componentKey);
    047        }
    048
    049    }