Java 类org.hibernate.validator.HibernateValidatorConfiguration 实例源码

项目:adeptj-modules    文件:BeanValidationActivator.java   
@Override
public void start(BundleContext context) throws Exception {
    HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class)
            .configure();
    configuration.parameterNameProvider(new ReflectionParameterNameProvider());
    configuration.messageInterpolator(new LocaleSpecificMessageInterpolator(configuration
            .getDefaultMessageInterpolator()));
    validatorFactory = configuration.buildValidatorFactory();
    Dictionary<String, Object> props = new Hashtable<>();
    props.put(Constants.SERVICE_VENDOR, "AdeptJ");
    props.put(Constants.SERVICE_DESCRIPTION, "AdeptJ ValidatorService");
    servRegValidatorService = context.registerService(ValidatorService.class,
            new OSGiBeanValidatorService(this.validatorFactory.getValidator(),
                    configuration.getBootstrapConfiguration()),
            props);
}
项目:nest-old    文件:ValidatorFactoryImpl513.java   
/**
 * Returns a list with {@link ValidatedValueUnwrapper}s configured via the
 * {@link HibernateValidatorConfiguration#VALIDATED_VALUE_HANDLERS}
 * property.
 *
 * @param properties
 *            the properties used to bootstrap the factory
 *
 * @return a list with property-configured {@link ValidatedValueUnwrapper}s;
 *         May be empty but never {@code null}
 */
private List<ValidatedValueUnwrapper<?>> getPropertyConfiguredValidatedValueHandlers(Map<String, String> properties) {
    String propertyValue = properties.get(HibernateValidatorConfiguration.VALIDATED_VALUE_HANDLERS);

    if (propertyValue == null || propertyValue.isEmpty()) {
        return Collections.emptyList();
    }

    String[] handlerNames = propertyValue.split(",");
    List<ValidatedValueUnwrapper<?>> handlers = newArrayList(handlerNames.length);

    for (String handlerName : handlerNames) {
        @SuppressWarnings("unchecked")
        Class<? extends ValidatedValueUnwrapper<?>> handlerType = (Class<? extends ValidatedValueUnwrapper<?>>) run(LoadClass
                .action(handlerName, ValidatorFactoryImpl513.class));
        handlers.add(run(NewInstance.action(handlerType, "validated value handler class")));
    }

    return handlers;
}
项目:nest-old    文件:HibernateValidationConfigurationInitializer.java   
/**
 * create hibernate validation configuration
 * 
 * @return
 */
protected HibernateValidatorConfiguration createConfiguration() {
    HibernateValidatorConfiguration configuration = null;
    if (this.isIgnoreClassHierarchy()) {
        ValidationProviderResolver resolver = new ValidationProviderResolver() {
            /**
             * (non-Javadoc)
             * 
             * @see javax.validation.ValidationProviderResolver#getValidationProviders()
             */
            @Override
            public List<ValidationProvider<?>> getValidationProviders() {
                List<ValidationProvider<?>> providers = new ArrayList<ValidationProvider<?>>(1);
                providers.add(new HibernateValidator513());
                return providers;
            }
        };
        configuration = Validation.byProvider(HibernateValidator513.class).providerResolver(resolver).configure();
    } else {
        configuration = Validation.byProvider(HibernateValidator.class).configure();
    }
    configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(
            MESSAGES)));
    return configuration;
}
项目:javase-study    文件:SysRoleValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysRole.class)
            .property("roleName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .constraint(new PatternDef().regexp("^(?!root$).+$").message(
                    "may not be root"))
            .property("roleCode", ElementType.FIELD)
            .constraint(new NotNullDef()).constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysRouteUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysRoute.class)
            .property("routeId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("name", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("url", ElementType.FIELD)
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysMenuValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysMenu.class)
            .property("menuName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .property("menuPath", ElementType.FIELD)
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"))
            .property("parentId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("icon", ElementType.FIELD)
            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysUserUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysUser.class)
            .property("userId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("username", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(3))
            .constraint(new PatternDef().regexp("[a-zA-Z][0-9a-zA-Z_]*")
                    .message("{msg.error.validation.username.pattern}"))
            .property("password", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .property("fullName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("email", ElementType.FIELD).constraint(new EmailDef())
            .constraint(new SizeDef().max(64));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysRoleUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping.type(SysRole.class).property("roleId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("roleName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new PatternDef().regexp("^(?!root$).+$").message("may not be root"))
            .property("roleCode", ElementType.FIELD)

            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysUserValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysUser.class)
            .property("username", ElementType.FIELD)
            .constraint(new NotNullDef())
            .constraint(new SizeDef().max(16).min(3))
            .constraint(new PatternDef().regexp("[a-zA-Z][0-9a-zA-Z_]*")
                    .message("{msg.error.validation.username.pattern}"))
            .property("password", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef())
            .property("fullName", ElementType.FIELD)
            .constraint(new NotNullDef()).constraint(new SizeDef().max(32))
            .property("email", ElementType.FIELD)
            .constraint(new SizeDef().max(64)).constraint(new EmailDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:PasswordValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping.type(ChangePasswordVo.class)
            .property("oldpassword", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef())
            .property("newpassword", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef())
            .property("retypepassword", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysMenuUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysMenu.class)
            .property("menuId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("menuName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("menuPath", ElementType.FIELD)
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"))
            .property("icon", ElementType.FIELD)
            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysRouteValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysRoute.class)
            .property("name", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .property("url", ElementType.FIELD)
            .constraint(new NotNullDef())
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysJobUpdateValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping.type(SysJob.class).property("jobId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("clazzName", ElementType.FIELD).constraint(new NullDef())
            .property("jobName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("cron", ElementType.FIELD)
            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysJobValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysJob.class)
            .property("clazzName", ElementType.FIELD)
            .constraint(new NotNullDef())
            .constraint(new SizeDef().max(64))
            .constraint(new PatternDef().regexp("[a-zA-Z.]+")
                    .message("{msg.error.validation.className.pattern}"))
            .property("jobName", ElementType.FIELD)
            .constraint(new SizeDef().max(32)).constraint(new NotNullDef())
            .property("cron", ElementType.FIELD)
            .constraint(new SizeDef().max(32)).constraint(new NotNullDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:javase-study    文件:SysDictValidator.java   
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysDict.class)
            .property("dictCode", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .constraint(new PatternDef().regexp("[0-9a-zA-Z_]+").message(
                    "{msg.error.validation.dictCode.pattern}"))
            .property("dictName", ElementType.FIELD)
            .constraint(new SizeDef().max(32)).constraint(new NotNullDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
项目:jooby    文件:Hbv.java   
@Override
public void configure(final Env env, final Config config, final Binder binder) {
  HibernateValidatorConfiguration configuration = byProvider(HibernateValidator.class)
      .configure();

  if (config.hasPath("hibernate.validator")) {
    config.getConfig("hibernate.validator").root().forEach((k, v) -> {
      configuration.addProperty("hibernate.validator." + k, v.unwrapped().toString());
    });
  }

  if (configurer != null) {
    configurer.accept(configuration, config);
  }

  binder.bind(HibernateValidatorConfiguration.class).toInstance(configuration);

  binder.bind(Validator.class).toProvider(HbvFactory.class).asEagerSingleton();

  env.lifeCycle(HbvFactory.class);

  Multibinder.newSetBinder(binder, Parser.class).addBinding()
      .toInstance(new HbvParser(predicate));
}
项目:jooby    文件:HbvTest.java   
@SuppressWarnings("unchecked")
@Test
public void defaultsWithConfigurer() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, HibernateValidatorConfiguration.class,
      Consumer.class)
          .expect(hibernateValiConf)
          .expect(noproperties)
          .expect(validatorProvider)
          .expect(hvparser)
          .expect(unit -> {
            Consumer<HibernateValidatorConfiguration> configurer = unit.get(Consumer.class);

            configurer.accept(unit.get(HibernateValidatorConfiguration.class));
          })
          .expect(onStop)
          .run(unit -> {
            new Hbv()
                .doWith(unit.get(Consumer.class))
                .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
          });
}
项目:jooby    文件:HbvTest.java   
@SuppressWarnings("unchecked")
@Test
public void defaultsWithFulleConfigurer() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, HibernateValidatorConfiguration.class,
      BiConsumer.class)
          .expect(hibernateValiConf)
          .expect(noproperties)
          .expect(validatorProvider)
          .expect(hvparser)
          .expect(unit -> {
            BiConsumer<HibernateValidatorConfiguration, Config> configurer = unit
                .get(BiConsumer.class);

            configurer.accept(unit.get(HibernateValidatorConfiguration.class),
                unit.get(Config.class));
          })
          .expect(onStop)
          .run(unit -> {
            new Hbv()
                .doWith(unit.get(BiConsumer.class))
                .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
          });
}
项目:jooby    文件:HbvFactoryTest.java   
@Test
public void start() throws Exception {
  new MockUnit(HibernateValidatorConfiguration.class, Injector.class, ValidatorFactory.class,
      Validator.class)
      .expect(constructor)
      .expect(start)
      .run(unit -> {
        HbvFactory hbvFactory = new HbvFactory(
            unit.get(HibernateValidatorConfiguration.class),
            unit.get(Injector.class)
            );
        hbvFactory.start();

        assertEquals(unit.get(Validator.class), hbvFactory.get());
      });
}
项目:jooby    文件:HbvFactoryTest.java   
@Test
public void stop() throws Exception {
  new MockUnit(HibernateValidatorConfiguration.class, Injector.class, ValidatorFactory.class,
      Validator.class)
      .expect(constructor)
      .expect(start)
      .expect(unit -> {
        ValidatorFactory validatorFactory = unit.get(ValidatorFactory.class);
        validatorFactory.close();
      })
      .run(unit -> {
        HbvFactory hbvFactory = new HbvFactory(
            unit.get(HibernateValidatorConfiguration.class),
            unit.get(Injector.class)
            );
        hbvFactory.start();
        hbvFactory.stop();
        // ignored
        hbvFactory.stop();
      });
}
项目:infobip-bean-validation    文件:CustomLocalValidatorFactoryBean.java   
@Override
protected void postProcessConfiguration(Configuration<?> configuration) {
    super.postProcessConfiguration(configuration);
    HibernateValidatorConfiguration hibernateConfiguration = (HibernateValidatorConfiguration) configuration;

    ConstraintMapping constraintMapping = hibernateConfiguration.createConstraintMapping();
    validators.forEach(validator -> addConstraint(constraintMapping, validator));
    hibernateConfiguration.addMapping(constraintMapping);

    hibernateValidatorConfigurationStrategy.accept(hibernateConfiguration);
}
项目:validator-web    文件:HibernateValidation.java   
@Override
public void initialize(ValidationContext context) {
    context.setValidatorDelegate(this);

    HibernateValidatorConfiguration configure = javax.validation.Validation.byProvider(HibernateValidator.class).configure();
    if (context instanceof ValidationContext.Accessor) {
        configure.failFast(((ValidationContext.Accessor) context).isFailFast());
    }
    ValidatorFactory factory = configure.buildValidatorFactory();
    validator = factory.getValidator();
}
项目:open-Autoscaler    文件:BeanValidation.java   
public static HibernateValidatorConfiguration getPolicyTriggerRange(HibernateValidatorConfiguration config) {

         Map<String, Map<String, Map<String, Map<String, String>>>> mulit_range = Constants.getTriggerRangeByTriggerType();
         logger.debug("mulit trigger range: " + mulit_range.toString());
         for (String class_type : mulit_range.keySet()){
             Map<String, Map<String, Map<String, String>>> range = mulit_range.get(class_type);
             Class<?> class_obj=null;
             if (class_type.equals("trigger_Memory")) //only one metricType supported now
                 class_obj = PolicyTrigger.class;
             for (String key : range.keySet()) {
                 Map<String, Map<String, String>> value = range.get(key);
                 for(String value_key : value.keySet()){
                     Map<String, String> value_item = value.get(value_key);
                     ConstraintMapping mapping = config.createConstraintMapping();
                     if (value_key.endsWith("Min")){
                         mapping.type(class_obj).property(key, ElementType.FIELD).constraint( new MinDef().value(Integer.parseInt(value_item.get("value"))).message(value_item.get("message")));
                     }
                     else if(value_key.endsWith("Max")){
                         mapping.type(class_obj).property(key, ElementType.FIELD).constraint( new MaxDef().value(Integer.parseInt(value_item.get("value"))).message(value_item.get("message")));
                     }
                     else if(value_key.endsWith("NotNull")){
                         mapping.type(class_obj).property(key, ElementType.FIELD).constraint( new NotNullDef().message(value_item.get("message")));
                     }
                     config.addMapping( mapping );
                 }
             }
         }
         return config;
    }
项目:open-Autoscaler    文件:BeanValidation.java   
public static JsonNode parsePolicy(String jsonString, Map<String, String> service_info, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
     List<String> violation_message = new ArrayList<String>();
     ObjectNode result = new_mapper.createObjectNode();
     result.put("valid", false);
     logger.info("received policy : " + jsonString); //debug
     new_mapper.readValue(jsonString, Policy.class); //for syntax error check
     String transfered_json = TransferedPolicy.packServiceInfo(jsonString, service_info);
     logger.info("transfered policy after update with service_information : " + transfered_json); //debug
     TransferedPolicy policy = new_mapper.readValue(transfered_json, TransferedPolicy.class);
     logger.info("we get policy as " + (Obj2Map(policy)).toString());//debug
     //additional data manipulation and check again
     policy = policy.setMaxInstCount();
     HibernateValidatorConfiguration config = BeanValidation.getPolicyRange();
     ValidatorFactory vf = config.buildValidatorFactory();
     Locale locale = LocaleUtil.getLocale(httpServletRequest);
     MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
     Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
     Set<ConstraintViolation<TransferedPolicy>> set = validator.validate(policy);
     if (set.size() > 0 ){
         for (ConstraintViolation<TransferedPolicy> constraintViolation : set) {
             violation_message.add(constraintViolation.getMessage());
         }
         result.set("violation_message", new_mapper.valueToTree(violation_message));
         return result;
     }

     String new_json = policy.transformInput();
     logger.info("policy before trigger back : " + new_json); //debug
     new_json = TransferedPolicy.unpackServiceInfo(new_json, service_info);
     result.put("valid", true);
     logger.info("send out policy: " + new_json); //debug
     result.put("new_json", new_json);
     return result;
}
项目:cuba    文件:BeanValidationImpl.java   
@Override
public Validator getValidator(@Nullable ConstraintMapping constraintMapping, ValidationOptions options) {
    checkNotNullArgument(options);

    if (constraintMapping == null
            && options.getFailFast() == null
            && options.getLocale() != null) {
        return getValidatorWithDefaultFactory(options.getLocale());
    }

    Locale locale;
    if (options.getLocale() != null) {
        locale = options.getLocale();
    } else {
        locale = getCurrentLocale();
    }

    HibernateValidatorConfiguration configuration = getValidatorFactoryConfiguration(locale);
    if (options.getFailFast() != null) {
        configuration.failFast(options.getFailFast());
    }
    if (constraintMapping != null) {
        configuration.addMapping(constraintMapping);
    }

    ValidatorFactory factory = configuration.buildValidatorFactory();
    return factory.getValidator();
}
项目:cuba    文件:BeanValidationImpl.java   
protected Validator getValidatorWithDefaultFactory(Locale locale) {
    ValidatorFactory validatorFactoryFromCache = validatorFactoriesCache.get(locale);
    if (validatorFactoryFromCache != null) {
        return validatorFactoryFromCache.getValidator();
    }

    HibernateValidatorConfiguration configuration = getValidatorFactoryConfiguration(locale);
    ValidatorFactory factory = configuration.buildValidatorFactory();

    validatorFactoriesCache.put(locale, factory);

    return factory.getValidator();
}
项目:cuba    文件:BeanValidationImpl.java   
protected HibernateValidatorConfiguration getValidatorFactoryConfiguration(Locale locale) {
    @SuppressWarnings("UnnecessaryLocalVariable")
    HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class)
            .configure()
            .timeProvider(new CubaValidationTimeProvider(timeSource))
            .traversableResolver(new CubaValidationTraversableResolver(metadata, entityStates))
            .messageInterpolator(new CubaValidationMessagesInterpolator(messages, locale));

    return configuration;
}
项目:nest-old    文件:ValidatorFactoryImpl513.java   
private boolean checkPropertiesForFailFast(Map<String, String> properties, boolean programmaticConfiguredFailFast) {
    boolean failFast = programmaticConfiguredFailFast;
    String failFastPropValue = properties.get(HibernateValidatorConfiguration.FAIL_FAST);
    if (failFastPropValue != null) {
        boolean tmpFailFast = Boolean.valueOf(failFastPropValue);
        if (programmaticConfiguredFailFast && !tmpFailFast) {
            throw log.getInconsistentFailFastConfigurationException();
        }
        failFast = tmpFailFast;
    }
    return failFast;
}
项目:jooby    文件:Hbv.java   
/**
 * Setup a configurer callback.
 *
 * @param configurer Configurer callback.
 * @return This module.
 */
public Hbv doWith(final Consumer<HibernateValidatorConfiguration> configurer) {
  requireNonNull(configurer, "Configurer callback is required.");
  this.configurer = (hvc, conf) -> {
    configurer.accept(hvc);
  };
  return this;
}
项目:jooby    文件:HbvTest.java   
@Test
public void defaults() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, HibernateValidatorConfiguration.class)
      .expect(hibernateValiConf)
      .expect(noproperties)
      .expect(validatorProvider)
      .expect(hvparser)
      .expect(onStop)
      .run(unit -> {
        new Hbv()
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
项目:jooby    文件:HbvTest.java   
@Test
public void defaultsWithProperties() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, HibernateValidatorConfiguration.class)
      .expect(hibernateValiConf)
      .expect(properties)
      .expect(validatorProvider)
      .expect(hvparser)
      .expect(onStop)
      .run(unit -> {
        new Hbv()
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
项目:jooby    文件:HbvFactoryTest.java   
@Test
public void defaults() throws Exception {
  new MockUnit(HibernateValidatorConfiguration.class, Injector.class)
      .expect(constructor)
      .run(unit -> {
        new HbvFactory(
            unit.get(HibernateValidatorConfiguration.class),
            unit.get(Injector.class)
          );
        });
}
项目:wisdom    文件:HibernateValidatorService.java   
/**
 * Initializes the validator, and registers it as an OSGi service (if the bundle context is set).
 *
 * @return the validator.
 */
@Validate
public Validator initialize() {
    // configure and build an instance of ValidatorFactory
    ProviderSpecificBootstrap<HibernateValidatorConfiguration> validationBootStrap = javax.validation.Validation
            .byProvider(HibernateValidator.class);

    // bootstrap to properly resolve in an OSGi environment
    validationBootStrap.providerResolver(new HibernateValidationProviderResolver());

    HibernateValidatorConfiguration configure = validationBootStrap.configure().messageInterpolator(interpolator);
    interpolator.setDefaultInterpolator(configure.getDefaultMessageInterpolator());

    // now that we've done configuring the ValidatorFactory, let's build it
    ValidatorFactory validatorFactory = configure.buildValidatorFactory();

    // retrieve a unique validator.
    Validator validator = validatorFactory.getValidator();

    // Register the validator.
    if (context != null) {
        registration = context.registerService(Validator.class, new WrappedValidator(validator), null);
        factoryRegistration = context.registerService(ValidatorFactory.class, validatorFactory, null);
    }

    return validator;
}
项目:dropwizard-vavr    文件:VavrBundle.java   
/**
 * Creates a new {@link HibernateValidatorConfiguration} with all the custom {@link
 * org.hibernate.validator.spi.valuehandling.ValidatedValueUnwrapper} registered.
 */
private static HibernateValidatorConfiguration newValidatorConfiguration() {
    return Validators.newConfiguration()
            .addValidatedValueHandler(new ValueValidatedValueUnwrapper());
}
项目:open-Autoscaler    文件:BeanValidation.java   
public static HibernateValidatorConfiguration getPolicyRange() throws JsonParseException, JsonMappingException, IOException{
    HibernateValidatorConfiguration config = Validation.byProvider( HibernateValidator.class ).configure();

    config = getPolicyTriggerRange(config);
    return config;
}
项目:nest-old    文件:HibernateBeanValidator.java   
/**
 * get configuration
 * 
 * @return
 */
protected HibernateValidatorConfiguration getConfiguration() {
    IValidationConfiguration configuration = this.getBeanDescriptor().getContext()
            .getInitializedData(IValidationConfigurationInitializer.KEY);
    return configuration.getRealConfiguration();
}
项目:jooby    文件:HbvFactory.java   
@Inject
public HbvFactory(final HibernateValidatorConfiguration conf, final Injector injector) {
  this.conf = requireNonNull(conf, "Validation config is required.");

  conf.constraintValidatorFactory(new HbvConstraintValidatorFactory(injector));
}
项目:hibernate-demos    文件:AbstractValidationTest.java   
@Before
public void setUp() {
    final Configuration<HibernateValidatorConfiguration> configuration = Validation.byProvider( HibernateValidator.class ).configure();
    validator = configuration.buildValidatorFactory().getValidator();
}
项目:hibernate-demos    文件:AbstractValidationTest.java   
@Before
public void setUp() {
    final Configuration<HibernateValidatorConfiguration> configuration = Validation.byProvider( HibernateValidator.class ).configure();
    validator = configuration.buildValidatorFactory().getValidator();
}
项目:open-data-service    文件:OdsApplication.java   
@Override
@Context
public void run(OdsConfig configuration, Environment environment) {
    Injector injector = Guice.createInjector(
            new MonitoringModule(environment.metrics()),
            new ConfigModule(configuration),
            new ProcessorModule(),
            new DbModule(configuration.getCouchDb()),
            new NotificationsModule(),
            new DataModule(),
            new AuthModule(configuration.getAuth()));

    // start data grabbing
    environment.lifecycle().manage(injector.getInstance(DataSourceManager.class));
    environment.jersey().getResourceConfig().register(MultiPartFeature.class);
    environment.jersey().getResourceConfig().register(injector.getInstance(AuthBinder.class));
    environment.jersey().register(injector.getInstance(DataSourceApi.class));
    environment.jersey().register(injector.getInstance(DataApi.class));
    environment.jersey().register(injector.getInstance(ProcessorChainApi.class));
    environment.jersey().register(injector.getInstance(DataViewApi.class));
    environment.jersey().register(injector.getInstance(NotificationApi.class));
    environment.jersey().register(injector.getInstance(PluginApi.class));
    environment.jersey().register(injector.getInstance(ProcessorSpecificationApi.class));
    environment.jersey().register(injector.getInstance(VersionApi.class));
    environment.jersey().register(injector.getInstance(UserApi.class));
    environment.jersey().register(PropertyFilteringMessageBodyWriter.class);
    environment.jersey().register(new DbExceptionMapper());
    environment.jersey().register(new JsonExceptionMapper());
    environment.jersey().register(new UnauthorizedExceptionMapper());
    environment.jersey().register(new NotFoundExceptionMapper());

    // setup users
    setupDefaultUsers(injector.getInstance(UserManager.class), configuration.getAuth().getUsers());

    // setup health checks
    environment.healthChecks().register(DbHealthCheck.class.getSimpleName(), injector.getInstance(DbHealthCheck.class));
    environment.healthChecks().register(PegelOnlineHealthCheck.class.getSimpleName(), injector.getInstance(PegelOnlineHealthCheck.class));
    environment.healthChecks().register(DataSourceHealthCheck.class.getSimpleName(), injector.getInstance(DataSourceHealthCheck.class));
    environment.healthChecks().register(FilterChainHealthCheck.class.getSimpleName(), injector.getInstance(FilterChainHealthCheck.class));
    environment.healthChecks().register(DataHealthCheck.class.getSimpleName(), injector.getInstance(DataHealthCheck.class));
    environment.healthChecks().register(CepsClientHealthCheck.class.getSimpleName(), injector.getInstance(CepsClientHealthCheck.class));

    // configure administration
    DropwizardResourceConfig jerseyConfig = new DropwizardResourceConfig(environment.metrics());
    JerseyContainerHolder jerseyContainerHolder = new JerseyContainerHolder(new ServletContainer(jerseyConfig));
    jerseyConfig.register(injector.getInstance(AdminFilterChainApi.class));
    environment.admin().addServlet("admin resources", jerseyContainerHolder.getContainer()).addMapping("/admin/*");

    // setup validation for external classes
    HibernateValidatorConfiguration validatorContext = Validation.byProvider(HibernateValidator.class).configure();
    ConstraintMapping mapping = validatorContext.createConstraintMapping();
    mapping.type(ProcessorReferenceChainDescription.class).constraint(new GenericConstraintDef<>(ValidChainReference.class));

    // setup Guice DI for hibernate validator
    environment.setValidator(validatorContext.addMapping(mapping)
            .constraintValidatorFactory(new GuiceConstraintValidatorFactory(injector))
            .buildValidatorFactory()
            .getValidator());
}