private void assertValidators(Validator... validators) { Object target = getTarget(); for (Validator validator : validators) { if (validator != null && (target != null && !validator.supports(target.getClass()))) { throw new IllegalStateException("Invalid target for Validator [" + validator + "]: " + target); } } }
private void assertValidators(Validator... validators) { Object target = getTarget(); for (Validator validator : validators) { if (validator != null && (target != null && !validator.supports(target.getClass()))) { throw new IllegalStateException("Invalid target for Validator [" + validator + "]: " + target); } } }
logger.debug("Invoking validator [" + validator + "]"); if (!validator.supports(target.getClass())) { throw new IllegalArgumentException( "Validator [" + validator.getClass() + "] does not support [" + target.getClass() + "]");
logger.debug("Invoking validator [" + validator + "]"); if (!validator.supports(target.getClass())) { throw new IllegalArgumentException( "Validator [" + validator.getClass() + "] does not support [" + target.getClass() + "]");
private void validateAndPush(ConfigurationPropertyName name, Object target, Class<?> type) { BindingResult errors = new BeanPropertyBindingResult(target, name.toString()); Arrays.stream(this.validators).filter((validator) -> validator.supports(type)) .forEach((validator) -> validator.validate(target, errors)); if (errors.hasErrors()) { this.exceptions.push(getBindValidationException(name, errors)); } }
/** * @see Validator#validate(Object) */ @Override public void validate(T item) throws ValidationException { if (!validator.supports(item.getClass())) { throw new ValidationException("Validation failed for " + item + ": " + item.getClass().getName() + " class is not supported by validator."); } BeanPropertyBindingResult errors = new BeanPropertyBindingResult(item, "item"); validator.validate(item, errors); if (errors.hasErrors()) { throw new ValidationException("Validation failed for " + item + ": " + errorsToString(errors), new BindException(errors)); } }
@Override public void initBinder(WebDataBinder binder) { binder.setAutoGrowNestedPaths(this.autoGrowNestedPaths); if (this.directFieldAccess) { binder.initDirectFieldAccess(); } if (this.messageCodesResolver != null) { binder.setMessageCodesResolver(this.messageCodesResolver); } if (this.bindingErrorProcessor != null) { binder.setBindingErrorProcessor(this.bindingErrorProcessor); } if (this.validator != null && binder.getTarget() != null && this.validator.supports(binder.getTarget().getClass())) { binder.setValidator(this.validator); } if (this.conversionService != null) { binder.setConversionService(this.conversionService); } if (this.propertyEditorRegistrars != null) { for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) { propertyEditorRegistrar.registerCustomEditors(binder); } } }
@Override public void initBinder(WebDataBinder binder) { binder.setAutoGrowNestedPaths(this.autoGrowNestedPaths); if (this.directFieldAccess) { binder.initDirectFieldAccess(); } if (this.messageCodesResolver != null) { binder.setMessageCodesResolver(this.messageCodesResolver); } if (this.bindingErrorProcessor != null) { binder.setBindingErrorProcessor(this.bindingErrorProcessor); } if (this.validator != null && binder.getTarget() != null && this.validator.supports(binder.getTarget().getClass())) { binder.setValidator(this.validator); } if (this.conversionService != null) { binder.setConversionService(this.conversionService); } if (this.propertyEditorRegistrars != null) { for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) { propertyEditorRegistrar.registerCustomEditors(binder); } } }
/** * Fetches all validators that are registered * * @param obj the object that will be validated * @return list of compatible validators */ protected List<Validator> getValidators(Object obj) { List<Validator> matchingValidators = new ArrayList<>(); List<Validator> validators = HandlerUtil.getHandlersForType(Validator.class, obj.getClass()); for (Validator validator : validators) { if (validator.supports(obj.getClass())) { matchingValidators.add(validator); } } return matchingValidators; }
private Errors validate(String event, Object entity) { if (entity == null) { return null; } Errors errors = new ValidationErrors(entity, persistentEntitiesFactory.getObject()); for (Validator validator : getValidatorsForEvent(event)) { if (validator.supports(entity.getClass())) { LOGGER.debug("{}: {} with {}", event, entity, validator); ValidationUtils.invokeValidator(validator, entity, errors); } } if (errors.hasErrors()) { throw new RepositoryConstraintViolationException(errors); } return errors; }
logger.debug("Invoking Spring Validator '" + ClassUtils.getShortName(validator.getClass()) + "'"); if (springValidator.supports(model.getClass())) { MessageContextErrors errors = new MessageContextErrors(requestContext.getMessageContext(), modelName, model, expressionParser, messageCodesResolver, mappingResults);
protected void initAction() { if (getValidator() != null) { if (getFormObjectClass() != null && !getValidator().supports(getFormObjectClass())) { throw new IllegalArgumentException("Validator [" + getValidator() + "] does not support form object class [" + getFormObjectClass() + "]"); } // signature: public void ${validateMethodName}(${formObjectClass}, Errors) validateMethodInvoker = new DispatchMethodInvoker(getValidator(), getFormObjectClass(), Errors.class); } }
/** * Returns whether this validation supports the given class. The call is practically * being deligated to the unerlying validator. * * @param clazz The class to be validated. * @return True if this validator supports the given class, false otherwise. */ public boolean supports(Class clazz) { return validator.supports(clazz); }
@Override protected void initApplicationContext() { if (this.validators != null) { for (int i = 0; i < this.validators.length; i++) { if (this.commandClass != null && !this.validators[i].supports(this.commandClass)) throw new IllegalArgumentException("Validator [" + this.validators[i] + "] does not support command class [" + this.commandClass.getName() + "]"); } } }
public void validate(final Object target, final Errors errors) { for (final Validator validator : validators) { if (validator.supports(target.getClass())) { validator.validate(target, errors); } } }
/** * Validate the specified object using the validator registered for the object's class. */ public void validate(final Object target, final Errors errors) { for (final Validator v : this.validators) { if (v.supports(target.getClass())) { v.validate(target, errors); } } } }
public Object getValue(ProgressListener subListener) throws Exception { Object value = delegate.getValue(subListener); Errors errors = new BeanPropertyBindingResult(value, getInputId()); for (Validator v : validators) { if (v.supports(value.getClass())) { v.validate(value, errors); } } if (errors.hasErrors()) { throw new ValidationException(errors, getInputId()); } return value; }
protected void initAction() { if (getValidator() != null) { if (getFormObjectClass() != null && !getValidator().supports(getFormObjectClass())) { throw new IllegalArgumentException("Validator [" + getValidator() + "] does not support form object class [" + getFormObjectClass() + "]"); } // signature: public void ${validateMethodName}(${formObjectClass}, Errors) validateMethodInvoker = new DispatchMethodInvoker(getValidator(), getFormObjectClass(), Errors.class); } }
protected void initAction() { if (getValidator() != null) { if (getFormObjectClass() != null && !getValidator().supports(getFormObjectClass())) { throw new IllegalArgumentException("Validator [" + getValidator() + "] does not support form object class [" + getFormObjectClass() + "]"); } // signature: public void ${validateMethodName}(${formObjectClass}, Errors) validateMethodInvoker = new DispatchMethodInvoker(getValidator(), new Class[] { getFormObjectClass(), Errors.class }); } }
protected void initAction() { if (getValidator() != null) { if (getFormObjectClass() != null && !getValidator().supports(getFormObjectClass())) { throw new IllegalArgumentException("Validator [" + getValidator() + "] does not support form object class [" + getFormObjectClass() + "]"); } // signature: public void ${validateMethodName}(${formObjectClass}, Errors) validateMethodInvoker = new DispatchMethodInvoker(getValidator(), new Class[] { getFormObjectClass(), Errors.class }); } }