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
013 /**
014 * Constraint that accepts an adapter whose key type is either the
015 * same type or a subtype of the type(s) represented by this object.
016 *
017 * @author Nick Sieger
018 * @author Jörg Schaible
019 */
020 @SuppressWarnings("serial")
021 public final class IsKeyType extends AbstractConstraint {
022
023 private final Class type;
024
025 /**
026 * Creates a new <code>IsType</code> instance.
027 *
028 * @param c the <code>Class</code> to match
029 */
030 public IsKeyType(final Class c) {
031 this.type = c;
032 }
033
034 @Override
035 public boolean evaluate(final ComponentAdapter adapter) {
036 return type.isAssignableFrom(adapter.getComponentKey().getClass());
037 }
038
039 }