1 /* 2 * Grapht, an open source dependency injector. 3 * Copyright 2014-2015 various contributors (see CONTRIBUTORS.txt) 4 * Copyright 2010-2014 Regents of the University of Minnesota 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as 8 * published by the Free Software Foundation; either version 2.1 of the 9 * License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 * details. 15 * 16 * You should have received a copy of the GNU General Public License along with 17 * this program; if not, write to the Free Software Foundation, Inc., 51 18 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 */ 20 package org.grouplens.grapht.context; 21 22 import org.apache.commons.lang3.tuple.Pair; 23 import org.grouplens.grapht.reflect.InjectionPoint; 24 import org.grouplens.grapht.reflect.Satisfaction; 25 26 import javax.inject.Qualifier; 27 import java.io.Serializable; 28 29 /** 30 * <p> 31 * ContextElementMatcher represents a "pattern" that can match an element within the 32 * dependency context created as a Resolver follows a dependency hierarchy. The 33 * dependency context is an ordered list of satisfactions and the qualifiers of the desires they satisfy. 34 * The first satisfaction is the root satisfaction, a {@code null} satisfaction of type {@code void}. 35 * <p> 36 * ContextMatchers can match or apply to these nodes and {@link Qualifier}s 37 * within a dependency context. As an example, the reflection based 38 * ContextElementMatcher matches nodes that are sub-types of the type the matcher was 39 * configured with. 40 * 41 * @author <a href="http://grouplens.org">GroupLens Research</a> 42 */ 43 public interface ContextElementMatcher extends Serializable { 44 /** 45 * Return true if this ContextElementMatcher matches or applies to the given Satisfaction and 46 * Qualifier. 47 * 48 * @param n The node and attributes in the current dependency context 49 * @return A match if this matcher matches the provided node label, or {@code false} if there is 50 * no match. 51 */ 52 MatchElement apply(Pair<Satisfaction, InjectionPoint> n); 53 }