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