All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.caelum.brutauth.reflection.methodsearchers.AdaptedMethodSearcher Maven / Gradle / Ivy

There is a newer version: 4.0.4
Show newest version
package br.com.caelum.brutauth.reflection.methodsearchers;

import javax.inject.Inject;

import br.com.caelum.brutauth.auth.rules.CustomBrutauthRule;
import br.com.caelum.brutauth.reflection.Argument;
import br.com.caelum.brutauth.reflection.BrutauthMethod;
import br.com.caelum.brutauth.reflection.NamedParametersMethod;
import br.com.caelum.brutauth.reflection.Parameter;

public class AdaptedMethodSearcher implements MethodSearcher {

	private final DefaultMethodSearcher defaultMethodSearcher;
	private final ArgumentParameterMatcher matcher;

	/**
	 * @deprecated CDI eyes only
	 */
	public AdaptedMethodSearcher() {
		this(null, null);
	}
	
	@Inject
	public AdaptedMethodSearcher(DefaultMethodSearcher defaultMethodSearcher, ArgumentParameterMatcher matcher) {
		this.defaultMethodSearcher = defaultMethodSearcher;
		this.matcher = matcher;
	}
	
	@Override
	public BrutauthMethod search(CustomBrutauthRule ruleToSearch, Argument...arguments) {
		try {
			NamedParametersMethod defaultMethod = defaultMethodSearcher.getMethod(ruleToSearch);
			Parameter[] classes = defaultMethod.getParameters();
			
			Argument[] matchedArguments = matcher.getValuesMatchingParameters(classes, arguments);
			return new BrutauthMethod(matchedArguments, defaultMethod.getMethod(), ruleToSearch);
		} catch (NoSuchMethodException e) {
			return null;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy