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

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

package br.com.caelum.brutauth.reflection.methodsearchers;

import java.lang.reflect.Method;

import javax.inject.Inject;

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

public class VarArgsMethodSearcher implements MethodSearcher {

  private DefaultMethodSearcher defaultMethodSearcher;

  @Deprecated // CDI eyes only
  public VarArgsMethodSearcher() {}

  @Inject
  public VarArgsMethodSearcher(DefaultMethodSearcher defaultMethodSearcher) {
    this.defaultMethodSearcher = defaultMethodSearcher;
  }

  @Override
  public BrutauthMethod search(CustomBrutauthRule ruleToSearch,
      Object... withArgs) {
    try {
      Method defaultMethod = defaultMethodSearcher.getMethod(ruleToSearch);
      return new BrutauthMethod(fakeVarArgs(withArgs), defaultMethod, ruleToSearch);
    } catch (NoSuchMethodException e) {
      return null;
    }
  }

  private Object[] fakeVarArgs(Object[] args) {
    if(args == null) return fakeVarArgs(new Object[]{args});
    return new Object[]{args};
  }
}
TOP

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

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.