javax.validation.Configuration.getDefaultParameterNameProvider()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中javax.validation.Configuration.getDefaultParameterNameProvider()方法的一些代码示例,展示了Configuration.getDefaultParameterNameProvider()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getDefaultParameterNameProvider()方法的具体详情如下:
包路径:javax.validation.Configuration
类名称:Configuration
方法名:getDefaultParameterNameProvider

Configuration.getDefaultParameterNameProvider介绍

[英]Returns an implementation of the ParameterNameProviderinterface following the default ParameterNameProviderdefined in the specification:

  • returns the actual parameter names as provided in the validated executable’s definition, if the class file of the executable contains parameter name information
  • otherwise returns names in the form arg<PARAMETER_INDEX>, where PARAMETER_INDEX starts at 0 for the first parameter, e.g. arg0, arg1 etc.
    [中]返回规范中定义的默认ParameterNameProvider后面的ParameterNameProviderinterface的实现:
    *如果可执行文件的类文件包含参数名称信息,则返回已验证可执行文件定义中提供的实际参数名称
    *否则以arg<PARAMETER\u INDEX>的形式返回名称,其中第一个参数的PARAMETER\u INDEX从0开始,例如arg0、arg1等。

代码示例

代码示例来源:origin: spring-projects/spring-framework

private void configureParameterNameProvider(ParameterNameDiscoverer discoverer, Configuration<?> configuration) {
  final ParameterNameProvider defaultProvider = configuration.getDefaultParameterNameProvider();
  configuration.parameterNameProvider(new ParameterNameProvider() {
    @Override
    public List<String> getParameterNames(Constructor<?> constructor) {
      String[] paramNames = discoverer.getParameterNames(constructor);
      return (paramNames != null ? Arrays.asList(paramNames) :
          defaultProvider.getParameterNames(constructor));
    }
    @Override
    public List<String> getParameterNames(Method method) {
      String[] paramNames = discoverer.getParameterNames(method);
      return (paramNames != null ? Arrays.asList(paramNames) :
          defaultProvider.getParameterNames(method));
    }
  });
}

代码示例来源:origin: org.springframework/spring-context

private void configureParameterNameProvider(ParameterNameDiscoverer discoverer, Configuration<?> configuration) {
  final ParameterNameProvider defaultProvider = configuration.getDefaultParameterNameProvider();
  configuration.parameterNameProvider(new ParameterNameProvider() {
    @Override
    public List<String> getParameterNames(Constructor<?> constructor) {
      String[] paramNames = discoverer.getParameterNames(constructor);
      return (paramNames != null ? Arrays.asList(paramNames) :
          defaultProvider.getParameterNames(constructor));
    }
    @Override
    public List<String> getParameterNames(Method method) {
      String[] paramNames = discoverer.getParameterNames(method);
      return (paramNames != null ? Arrays.asList(paramNames) :
          defaultProvider.getParameterNames(method));
    }
  });
}

代码示例来源:origin: hibernate/hibernate-validator

private ParameterNameProvider createParameterNameProvider(Configuration<?> config) {
  BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
  String parameterNameProviderFqcn = bootstrapConfiguration.getParameterNameProviderClassName();
  if ( parameterNameProviderFqcn == null ) {
    return config.getDefaultParameterNameProvider();
  }
  @SuppressWarnings("unchecked")
  Class<? extends ParameterNameProvider> parameterNameProviderClass = (Class<? extends ParameterNameProvider>) run(
      LoadClass.action(
          parameterNameProviderFqcn,
          null
      )
  );
  return createInstance( parameterNameProviderClass );
}

代码示例来源:origin: hibernate/hibernate-validator

public ValidationExtension() {
  Configuration<?> config = Validation.byDefaultProvider().configure();
  // we use the default ParameterNameProvider here as we cannot use the injected one
  // as it hasn't been turned into a managed bean yet and might not be able to
  // return a parameter name. At this stage, we don't care about the parameter names.
  config.parameterNameProvider( config.getDefaultParameterNameProvider() );
  BootstrapConfiguration bootstrap = config.getBootstrapConfiguration();
  globalExecutableTypes = bootstrap.getDefaultValidatedExecutableTypes();
  isExecutableValidationEnabled = bootstrap.isExecutableValidationEnabled();
  validatorFactory = config.buildValidatorFactory();
  validator = validatorFactory.getValidator();
  getterPropertySelectionStrategyHelper = GetterPropertySelectionStrategyHelper.forValidationFactory( validatorFactory );
  executableHelper = new ExecutableHelper( new TypeResolutionHelper() );
}

代码示例来源:origin: org.apache.tomee/openejb-core

@Override
public ParameterNameProvider getDefaultParameterNameProvider() {
  return delegate.getDefaultParameterNameProvider();
}

代码示例来源:origin: apache/servicemix-bundles

private void configureParameterNameProvider(ParameterNameDiscoverer discoverer, Configuration<?> configuration) {
  final ParameterNameProvider defaultProvider = configuration.getDefaultParameterNameProvider();
  configuration.parameterNameProvider(new ParameterNameProvider() {
    @Override
    public List<String> getParameterNames(Constructor<?> constructor) {
      String[] paramNames = discoverer.getParameterNames(constructor);
      return (paramNames != null ? Arrays.asList(paramNames) :
          defaultProvider.getParameterNames(constructor));
    }
    @Override
    public List<String> getParameterNames(Method method) {
      String[] paramNames = discoverer.getParameterNames(method);
      return (paramNames != null ? Arrays.asList(paramNames) :
          defaultProvider.getParameterNames(method));
    }
  });
}

代码示例来源:origin: vakinge/jeesuite-libs

public CustomParameterNameProvider() {
  nameProvider = Validation.byDefaultProvider().configure().getDefaultParameterNameProvider();
}

代码示例来源:origin: org.lwapp/lwapp-dropwizard-core

public CustomParameterNameProvider() {
  nameProvider = Validation.byDefaultProvider().configure().getDefaultParameterNameProvider();
}

代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

@Test
  @SpecAssertion(section = Sections.VALIDATIONAPI_BOOTSTRAPPING_CONFIGURATION, id = "d")
  public void testGetDefaultParameterNameProviderFromConfiguration() throws Exception {
    Method method = User.class.getMethod( "setNames", String.class, String.class );
    Constructor<User> constructor = User.class.getConstructor(
        String.class,
        String.class,
        Date.class
    );

    ParameterNameProvider defaultParameterNameProvider = TestUtil.getConfigurationUnderTest()
        .getDefaultParameterNameProvider();
    assertNotNull(
        defaultParameterNameProvider,
        "getDefaultParameterNameProvider() must not return null"
    );
    assertEquals(
        defaultParameterNameProvider.getParameterNames( constructor ),
        Arrays.asList( "firstName", "lastName", "dateOfBirth" ),
        "Wrong constructor parameter names returned by default provider"
    );
    assertEquals(
        defaultParameterNameProvider.getParameterNames( method ),
        Arrays.asList( "firstName", "lastName" ),
        "Wrong method parameter names returned by default provider"
    );
  }
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator-cdi

private ParameterNameProvider createParameterNameProvider(Configuration<?> config) {
  BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
  String parameterNameProviderFqcn = bootstrapConfiguration.getParameterNameProviderClassName();
  if ( parameterNameProviderFqcn == null ) {
    return config.getDefaultParameterNameProvider();
  }
  @SuppressWarnings("unchecked")
  Class<? extends ParameterNameProvider> parameterNameProviderClass = (Class<? extends ParameterNameProvider>) run(
      LoadClass.action(
          parameterNameProviderFqcn,
          null
      )
  );
  return createInstance( parameterNameProviderClass );
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator-cdi

public ValidationExtension() {
  Configuration<?> config = Validation.byDefaultProvider().configure();
  // we use the default ParameterNameProvider here as we cannot use the injected one
  // as it hasn't been turned into a managed bean yet and might not be able to
  // return a parameter name. At this stage, we don't care about the parameter names.
  config.parameterNameProvider( config.getDefaultParameterNameProvider() );
  BootstrapConfiguration bootstrap = config.getBootstrapConfiguration();
  globalExecutableTypes = bootstrap.getDefaultValidatedExecutableTypes();
  isExecutableValidationEnabled = bootstrap.isExecutableValidationEnabled();
  validatorFactory = config.buildValidatorFactory();
  validator = validatorFactory.getValidator();
  executableHelper = new ExecutableHelper( new TypeResolutionHelper() );
}

相关文章