001/* 002 * Copyright 2002-2017 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.context; 018 019import org.springframework.lang.Nullable; 020 021/** 022 * Interface for objects that are suitable for message resolution in a 023 * {@link MessageSource}. 024 * 025 * <p>Spring's own validation error classes implement this interface. 026 * 027 * @author Juergen Hoeller 028 * @see MessageSource#getMessage(MessageSourceResolvable, java.util.Locale) 029 * @see org.springframework.validation.ObjectError 030 * @see org.springframework.validation.FieldError 031 */ 032@FunctionalInterface 033public interface MessageSourceResolvable { 034 035 /** 036 * Return the codes to be used to resolve this message, in the order that 037 * they should get tried. The last code will therefore be the default one. 038 * @return a String array of codes which are associated with this message 039 */ 040 @Nullable 041 String[] getCodes(); 042 043 /** 044 * Return the array of arguments to be used to resolve this message. 045 * <p>The default implementation simply returns {@code null}. 046 * @return an array of objects to be used as parameters to replace 047 * placeholders within the message text 048 * @see java.text.MessageFormat 049 */ 050 @Nullable 051 default Object[] getArguments() { 052 return null; 053 } 054 055 /** 056 * Return the default message to be used to resolve this message. 057 * <p>The default implementation simply returns {@code null}. 058 * Note that the default message may be identical to the primary 059 * message code ({@link #getCodes()}), which effectively enforces 060 * {@link org.springframework.context.support.AbstractMessageSource#setUseCodeAsDefaultMessage} 061 * for this particular message. 062 * @return the default message, or {@code null} if no default 063 */ 064 @Nullable 065 default String getDefaultMessage() { 066 return null; 067 } 068 069}