當前位置: 首頁>>代碼示例>>Java>>正文


Java ConstraintValidator.isValid方法代碼示例

本文整理匯總了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);
        }
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:14,代碼來源:MinijaxValidator.java

示例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>");
        }
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:14,代碼來源:MinijaxValidator.java

示例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>");
        }
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:14,代碼來源:MinijaxValidator.java

示例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>");
        }
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:14,代碼來源:MinijaxValidator.java

示例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>");
        }
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:14,代碼來源:MinijaxValidator.java

示例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());
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:12,代碼來源:MinijaxValidator.java

示例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;
}
 
開發者ID:ManfredTremmel,項目名稱:gwt-bean-validators,代碼行數:40,代碼來源:AbstractGwtSpecificValidator.java

示例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;
}
 
開發者ID:CDS-INSPIRE,項目名稱:InSpider,代碼行數:34,代碼來源:ValidCollectionValidator.java


注:本文中的javax.validation.ConstraintValidator.isValid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。