本文整理汇总了Java中javax.validation.ConstraintValidator.isValid方法的典型用法代码示例。如果您正苦于以下问题:Java ConstraintValidator.isValid方法的具体用法?Java ConstraintValidator.isValid怎么用?Java ConstraintValidator.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.validation.ConstraintValidator
的用法示例。
在下文中一共展示了ConstraintValidator.isValid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validatePropertyConstraints
import javax.validation.ConstraintValidator; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T> void validatePropertyConstraints(
final MinijaxConstraintValidatorContext<T> context,
final PropertyDescriptor property,
final Object value) {
for (final ConstraintDescriptor constraint : property.getConstraintDescriptors()) {
final ConstraintValidator validator = ((MinijaxConstraintDescriptor) constraint).getValidator();
if (!validator.isValid(value, context)) {
context.buildViolation(constraint, value);
}
}
}
示例2: validateList
import javax.validation.ConstraintValidator; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T> void validateList(
final MinijaxConstraintValidatorContext<T> context,
final ConstraintDescriptor constraint,
final ConstraintValidator validator,
final List list) {
for (int i = 0; i < list.size(); i++) {
if (!validator.isValid(list.get(i), context)) {
context.buildViolation(constraint, list.get(i), "[" + i + "].<list element>");
}
}
}
示例3: validateIterable
import javax.validation.ConstraintValidator; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T> void validateIterable(
final MinijaxConstraintValidatorContext<T> context,
final ConstraintDescriptor constraint,
final ConstraintValidator validator,
final Iterable iterable) {
for (final Object element : iterable) {
if (!validator.isValid(element, context)) {
context.buildViolation(constraint, element, "[].<iterable element>");
}
}
}
示例4: validateMapKeys
import javax.validation.ConstraintValidator; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T> void validateMapKeys(
final MinijaxConstraintValidatorContext<T> context,
final ConstraintDescriptor constraint,
final ConstraintValidator validator,
final Map<?, ?> map) {
for (final Object element : map.keySet()) {
if (!validator.isValid(element, context)) {
context.buildViolation(constraint, element, "<K>[].<map key>");
}
}
}
示例5: validateMapValues
import javax.validation.ConstraintValidator; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T> void validateMapValues(
final MinijaxConstraintValidatorContext<T> context,
final ConstraintDescriptor constraint,
final ConstraintValidator validator,
final Map<?, ?> map) {
for (final Entry<?, ?> entry : map.entrySet()) {
if (!validator.isValid(entry.getValue(), context)) {
context.buildViolation(constraint, entry.getValue(), "[" + entry.getKey() + "].<map value>");
}
}
}
示例6: validateOptional
import javax.validation.ConstraintValidator; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T> void validateOptional(
final MinijaxConstraintValidatorContext<T> context,
final ConstraintDescriptor constraint,
final ConstraintValidator validator,
final Optional optional) {
if (optional.isPresent() && !validator.isValid(optional.get(), context)) {
context.buildViolation(constraint, optional.get());
}
}
示例7: validate
import javax.validation.ConstraintValidator; //导入方法依赖的package包/类
/**
* Perform the actual validation of a single {@link ConstraintValidator}.
* <p>
* As a side effect {@link ConstraintViolation}s may be added to {@code violations}.
* </p>
*
* @return true if there was any constraint violations
*/
protected <A extends Annotation, T, V> boolean validate(final GwtValidationContext<T> context,
final Set<ConstraintViolation<T>> violations, final G object, final V value,
final ConstraintValidator<A, ? super V> validator,
final ConstraintDescriptorImpl<A> constraintDescriptor, final Class<?>... groups) {
validator.initialize(constraintDescriptor.getAnnotation());
final ConstraintValidatorContextImpl<A, V> constraintValidatorContext =
context.createConstraintValidatorContext(constraintDescriptor);
final List<Class<?>> groupsList = Arrays.asList(groups);
final ValidationGroupsMetadata validationGroupsMetadata =
context.getValidator().getValidationGroupsMetadata();
final Set<Class<?>> constraintGroups = constraintDescriptor.getGroups();
// check groups requested are in the set of constraint groups (including the implicit group)
if (!this.containsAny(groupsList, constraintGroups)
&& !groupsList.contains(this.getConstraints(validationGroupsMetadata).getElementClass())) {
return false;
}
if (!validator.isValid(value, constraintValidatorContext)) {
this.addViolations(//
context, //
violations, //
object, //
value, //
constraintDescriptor, //
constraintValidatorContext);
return true;
}
return false;
}
示例8: isValid
import javax.validation.ConstraintValidator; //导入方法依赖的package包/类
@Override
public boolean isValid(List<?> entries,
ConstraintValidatorContext context) {
boolean valid = true;
if(entries == null){
return valid;
}
if(ArrayUtils.getLength(constraints) != ArrayUtils.getLength(messages)){
throw new ConstraintDeclarationException("Number of messages must be the same as number of constraints");
}
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
ConstraintValidatorFactory constraintValidatorFactory = validatorFactory.getConstraintValidatorFactory();
for(Object element : entries) {
for(Class<?> constraint : constraints) {
Constraint constraintAnnotation = constraint.getAnnotation(Constraint.class);
Class<? extends ConstraintValidator<?, ?>>[] constraintValidators = constraintAnnotation.validatedBy();
for (int i = 0; i < constraintValidators.length; i++) {
ConstraintValidator constraintValidator = constraintValidatorFactory.getInstance(constraintValidators[i]);
if(!constraintValidator.isValid(element, context)){
context.buildConstraintViolationWithTemplate(messages[i]).addConstraintViolation().disableDefaultConstraintViolation();
valid = false;
}
}
}
}
return valid;
}