本文整理匯總了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;
}