Java Code Examples for org.hibernate.validator.HibernateValidatorConfiguration#createConstraintMapping()
The following examples show how to use
org.hibernate.validator.HibernateValidatorConfiguration#createConstraintMapping() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanValidationImpl.java From cuba with Apache License 2.0 | 6 votes |
protected HibernateValidatorConfiguration getValidatorFactoryConfiguration(Locale locale) { HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class) .configure() .clockProvider(new CubaValidationTimeProvider(timeSource)) .traversableResolver(new CubaValidationTraversableResolver(metadata, entityStates)) .messageInterpolator(new CubaValidationMessagesInterpolator(messages, locale)); ConstraintMapping constraintMapping = configuration.createConstraintMapping(); //Hibernate validators doesn't support java.sql.Date. //Replace standard validators for java.util.Date with support java.sql.Date registerPastValidators(constraintMapping.constraintDefinition(Past.class)); registerPastOrPresentValidators(constraintMapping.constraintDefinition(PastOrPresent.class)); registerFutureValidators(constraintMapping.constraintDefinition(Future.class)); registerFutureOrPresentValidators(constraintMapping.constraintDefinition(FutureOrPresent.class)); configuration.addMapping(constraintMapping); return configuration; }
Example 2
Source File: BeanValidation.java From open-Autoscaler with Apache License 2.0 | 5 votes |
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; }