001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.validation; 018 019import org.springframework.lang.Nullable; 020 021/** 022 * Extended variant of the {@link Validator} interface, adding support for 023 * validation 'hints'. 024 * 025 * @author Juergen Hoeller 026 * @author Sam Brannen 027 * @since 3.1 028 */ 029public interface SmartValidator extends Validator { 030 031 /** 032 * Validate the supplied {@code target} object, which must be of a type of {@link Class} 033 * for which the {@link #supports(Class)} method typically returns {@code true}. 034 * <p>The supplied {@link Errors errors} instance can be used to report any 035 * resulting validation errors. 036 * <p><b>This variant of {@code validate()} supports validation hints, such as 037 * validation groups against a JSR-303 provider</b> (in which case, the provided hint 038 * objects need to be annotation arguments of type {@code Class}). 039 * <p>Note: Validation hints may get ignored by the actual target {@code Validator}, 040 * in which case this method should behave just like its regular 041 * {@link #validate(Object, Errors)} sibling. 042 * @param target the object that is to be validated 043 * @param errors contextual state about the validation process 044 * @param validationHints one or more hint objects to be passed to the validation engine 045 * @see javax.validation.Validator#validate(Object, Class[]) 046 */ 047 void validate(Object target, Errors errors, Object... validationHints); 048 049 /** 050 * Validate the supplied value for the specified field on the target type, 051 * reporting the same validation errors as if the value would be bound to 052 * the field on an instance of the target class. 053 * @param targetType the target type 054 * @param fieldName the name of the field 055 * @param value the candidate value 056 * @param errors contextual state about the validation process 057 * @param validationHints one or more hint objects to be passed to the validation engine 058 * @since 5.1 059 * @see javax.validation.Validator#validateValue(Class, String, Object, Class[]) 060 */ 061 default void validateValue( 062 Class<?> targetType, String fieldName, @Nullable Object value, Errors errors, Object... validationHints) { 063 064 throw new IllegalArgumentException("Cannot validate individual value for " + targetType); 065 } 066 067}