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

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

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

Configuration.buildValidatorFactory介绍

[英]Build a ValidatorFactory implementation.
[中]构建验证器工厂实现。

代码示例

代码示例来源:origin: jersey/jersey

@Override
  public ValidatorFactory get() {
    return config.buildValidatorFactory();
  }
}

代码示例来源:origin: apache/incubator-dubbo

@SuppressWarnings({"unchecked", "rawtypes"})
public JValidator(URL url) {
  this.clazz = ReflectUtils.forName(url.getServiceInterface());
  String jvalidation = url.getParameter("jvalidation");
  ValidatorFactory factory;
  if (jvalidation != null && jvalidation.length() > 0) {
    factory = Validation.byProvider((Class) ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory();
  } else {
    factory = Validation.buildDefaultValidatorFactory();
  }
  this.validator = factory.getValidator();
  this.methodClassMap = new ConcurrentHashMap<String, Class>();
}

代码示例来源:origin: apache/incubator-dubbo

@SuppressWarnings({"unchecked", "rawtypes"})
public JValidator(URL url) {
  this.clazz = ReflectUtils.forName(url.getServiceInterface());
  String jvalidation = url.getParameter("jvalidation");
  ValidatorFactory factory;
  if (jvalidation != null && jvalidation.length() > 0) {
    factory = Validation.byProvider((Class) ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory();
  } else {
    factory = Validation.buildDefaultValidatorFactory();
  }
  this.validator = factory.getValidator();
  this.methodClassMap = new ConcurrentHashMap<String, Class>();
}

代码示例来源:origin: javax.validation/validation-api

/**
 * Builds and returns a {@link ValidatorFactory} instance based on the
 * default Bean Validation provider and following the XML configuration.
 * <p>
 * The provider list is resolved using the default validation provider resolver
 * logic.
 * <p>
 * The code is semantically equivalent to
 * {@code Validation.byDefaultProvider().configure().buildValidatorFactory()}.
 *
 * @return {@code ValidatorFactory} instance
 *
 * @throws NoProviderFoundException if no Bean Validation provider was found
 * @throws ValidationException if a Bean Validation provider was found but the
 * {@code ValidatorFactory} cannot be built
 */
public static ValidatorFactory buildDefaultValidatorFactory() {
  return byDefaultProvider().configure().buildValidatorFactory();
}

代码示例来源:origin: wildfly/wildfly

private ValidatorFactory initFactory() {
  final ClassLoader oldTCCL = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
  try {
    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
    if (configuration == null) {
      return Validation.byDefaultProvider().providerResolver(new WildFlyProviderResolver()).configure()
          .buildValidatorFactory();
    } else {
      return configuration.buildValidatorFactory();
    }
  } finally {
    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTCCL);
  }
}

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

this.validatorFactory = configuration.buildValidatorFactory();
setTargetValidator(this.validatorFactory.getValidator());

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

this.validatorFactory = configuration.buildValidatorFactory();
setTargetValidator(this.validatorFactory.getValidator());

代码示例来源:origin: wildfly/wildfly

private ValidatorFactory initFactory() {
  final ClassLoader oldTCCL = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
  try {
    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
    return Validation.byDefaultProvider().providerResolver(new WildFlyProviderResolver()).configure()
        .buildValidatorFactory();
  } finally {
    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTCCL);
  }
}

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

public StatisticalValidationState() {
  ValidatorFactory factory = null;
  final Configuration<?> configuration = Validation.byDefaultProvider().configure();
  try ( InputStream mappingStream = StatisticalValidation.class.getResourceAsStream( "mapping.xml" ) ) {
    configuration.addMapping( mappingStream );
    factory = configuration.buildValidatorFactory();
    assertThat( factory ).isNotNull();
  }
  catch (IOException e) {
    throw new IllegalStateException( "Mappings cannot be read. Validation factory cannot be configured correctly.", e );
  }
  validator = factory.getValidator();
  entitiesUnderTest = IntStream.rangeClosed( 0, NUMBER_OF_TEST_ENTITIES )
      .mapToObj( index -> new TestEntity( index % 10 ) )
      .collect( Collectors.toList() );
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Build and return a <code>ValidatorFactory</code> instance based on the
 * default Bean Validation provider.
 * <p/>
 * The provider list is resolved using the default validation provider
 * resolver logic.
 * <p/>
 * The code is semantically equivalent to
 * <code>Validation.byDefaultProvider().configure().buildValidatorFactory()</code>
 * 
 * @return <code>ValidatorFactory</code> instance.
 * 
 * @throws ValidationException if the ValidatorFactory cannot be built
 */
public static ValidatorFactory buildDefaultValidatorFactory() {
 return byDefaultProvider().configure().buildValidatorFactory();
}

代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common

public ValidationInterceptor(MessageInterpolator messageInterpolator) {
  // Yes, this cast is unnecessary in Java 6, but seems to be required in Java 5
  this.factory = ((Configuration) Validation.byDefaultProvider().configure().messageInterpolator(messageInterpolator)).buildValidatorFactory();
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
public <T> void beforeMethodInvoke(SwaggerInvocation invocation, SwaggerProducerOperation producerOperation,
  Object[] args)
  throws ConstraintViolationException {
 if (null == executableValidator) {
  ValidatorFactory factory =
    Validation.byDefaultProvider()
      .configure()
      .parameterNameProvider(new DefaultParameterNameProvider())
      .buildValidatorFactory();
  executableValidator = factory.getValidator().forExecutables();
 }
 Set<ConstraintViolation<Object>> violations =
   executableValidator.validateParameters(producerOperation.getProducerInstance(),
     producerOperation.getProducerMethod(),
     args,
     Default.class);
 if (violations.size() > 0) {
  LOGGER.warn("Parameter validation failed : " + violations.toString());
  throw new ConstraintViolationException(violations);
 }
}

代码示例来源: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: hibernate/hibernate-validator

@Override
public ValidatorFactory create(CreationalContext<ValidatorFactory> ctx) {
  Configuration<?> config = getConfiguration();
  config.constraintValidatorFactory( createConstraintValidatorFactory( config ) );
  config.messageInterpolator( createMessageInterpolator( config ) );
  config.traversableResolver( createTraversableResolver( config ) );
  config.parameterNameProvider( createParameterNameProvider( config ) );
  config.clockProvider( createClockProvider( config ) );
  addValueExtractorBeans( config );
  return config.buildValidatorFactory();
}

代码示例来源:origin: actframework/actframework

private void ensureFactoryValidator() {
  if (validator != null) {
    return;
  }
  if (factory == null) {
    factory = config.buildValidatorFactory();
  }
  validator = factory.getValidator();
}

代码示例来源:origin: caelum/vraptor

@PostConstruct
public void buildFactory() {
instance = Validation.byDefaultProvider().configure()
  .constraintValidatorFactory(constraintValidatorFactory).buildValidatorFactory();
logger.debug("Initializing Bean Validation (1.1 supported)");
}

代码示例来源:origin: caelum/vraptor

@PostConstruct
public void buildFactory() {
  factory = Validation.byDefaultProvider()
    .configure()
    .messageInterpolator(interpolator)
    .buildValidatorFactory();
logger.debug("Initializing Bean Validation (1.0 supported)");
}

代码示例来源:origin: apache/cxf

public BeanValidationProvider(ValidationConfiguration cfg) {
  try {
    Configuration<?> factoryCfg = Validation.byDefaultProvider().configure();
    initFactoryConfig(factoryCfg, cfg);
    factory = factoryCfg.buildValidatorFactory();
  } catch (final ValidationException ex) {
    LOG.severe("Bean Validation provider can not be found, no validation will be performed");
    throw ex;
  }
}

代码示例来源:origin: torakiki/sejda

private DefaultValidationContext() {
  Configuration<?> validationConfig = Validation.byDefaultProvider().configure();
  if (new DefaultSejdaContext().isIgnoreXmlConfiguration()) {
    validationConfig.ignoreXmlConfiguration();
  }
  ValidatorFactory factory = validationConfig.buildValidatorFactory();
  validator = factory.getValidator();
}

代码示例来源:origin: org.seedstack.seed/seed-core

private GlobalValidatorFactory() {
  validatorFactory = Validation.byDefaultProvider()
      .configure()
      .parameterNameProvider(new ReflectionParameterNameProvider())
      .messageInterpolator(new SeedMessageInterpolator())
      .buildValidatorFactory();
}

相关文章