001/* 002 * Copyright 2002-2012 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 019/** 020 * Strategy interface for building message codes from validation error codes. 021 * Used by DataBinder to build the codes list for ObjectErrors and FieldErrors. 022 * 023 * <p>The resulting message codes correspond to the codes of a 024 * MessageSourceResolvable (as implemented by ObjectError and FieldError). 025 * 026 * @author Juergen Hoeller 027 * @since 1.0.1 028 * @see DataBinder#setMessageCodesResolver 029 * @see ObjectError 030 * @see FieldError 031 * @see org.springframework.context.MessageSourceResolvable#getCodes() 032 */ 033public interface MessageCodesResolver { 034 035 /** 036 * Build message codes for the given error code and object name. 037 * Used for building the codes list of an ObjectError. 038 * @param errorCode the error code used for rejecting the object 039 * @param objectName the name of the object 040 * @return the message codes to use 041 */ 042 String[] resolveMessageCodes(String errorCode, String objectName); 043 044 /** 045 * Build message codes for the given error code and field specification. 046 * Used for building the codes list of an FieldError. 047 * @param errorCode the error code used for rejecting the value 048 * @param objectName the name of the object 049 * @param field the field name 050 * @param fieldType the field type (may be {@code null} if not determinable) 051 * @return the message codes to use 052 */ 053 String[] resolveMessageCodes(String errorCode, String objectName, String field, Class<?> fieldType); 054 055}