Package br.com.caelum.brutauth.reflection.methodsearchers

Source Code of br.com.caelum.brutauth.reflection.methodsearchers.AdaptedMethodSearcher

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;
    }
  }
}
TOP

Related Classes of br.com.caelum.brutauth.reflection.methodsearchers.AdaptedMethodSearcher

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.