Class DefaultMessageSourceResolvable
- java.lang.Object
- org.springframework.context.support.DefaultMessageSourceResolvable
- All Implemented Interfaces:
Serializable,MessageSourceResolvable
- Direct Known Subclasses:
ObjectError
public class DefaultMessageSourceResolvable extends Object implements MessageSourceResolvable, Serializable
Spring's default implementation of theMessageSourceResolvableinterface. Offers an easy way to store all the necessary values needed to resolve a message via aMessageSource.- Since:
- 13.02.2004
- Author:
- Juergen Hoeller
- See Also:
MessageSource.getMessage(MessageSourceResolvable, java.util.Locale), Serialized Form
Constructor Summary
Constructors Constructor Description DefaultMessageSourceResolvable(String code)Create a new DefaultMessageSourceResolvable.DefaultMessageSourceResolvable(String[] codes)Create a new DefaultMessageSourceResolvable.DefaultMessageSourceResolvable(String[] codes, Object[] arguments)Create a new DefaultMessageSourceResolvable.DefaultMessageSourceResolvable(String[] codes, Object[] arguments, String defaultMessage)Create a new DefaultMessageSourceResolvable.DefaultMessageSourceResolvable(String[] codes, String defaultMessage)Create a new DefaultMessageSourceResolvable.DefaultMessageSourceResolvable(MessageSourceResolvable resolvable)Copy constructor: Create a new instance from another resolvable.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)Object[]getArguments()Return the array of arguments to be used to resolve this message.StringgetCode()Return the default code of this resolvable, that is, the last one in the codes array.String[]getCodes()Return the codes to be used to resolve this message, in the order that they should get tried.StringgetDefaultMessage()Return the default message to be used to resolve this message.inthashCode()protected StringresolvableToString()Build a default String representation for this MessageSourceResolvable: including codes, arguments, and default message.booleanshouldRenderDefaultMessage()Indicate whether the specified default message needs to be rendered for substituting placeholders and/orMessageFormatescaping.StringtoString()The default implementation exposes the attributes of this MessageSourceResolvable.
Constructor Detail
DefaultMessageSourceResolvable
public DefaultMessageSourceResolvable(String code)
Create a new DefaultMessageSourceResolvable.- Parameters:
code- the code to be used to resolve this message
DefaultMessageSourceResolvable
public DefaultMessageSourceResolvable(String[] codes)
Create a new DefaultMessageSourceResolvable.- Parameters:
codes- the codes to be used to resolve this message
DefaultMessageSourceResolvable
public DefaultMessageSourceResolvable(String[] codes, String defaultMessage)
Create a new DefaultMessageSourceResolvable.- Parameters:
codes- the codes to be used to resolve this messagedefaultMessage- the default message to be used to resolve this message
DefaultMessageSourceResolvable
public DefaultMessageSourceResolvable(String[] codes, Object[] arguments)
Create a new DefaultMessageSourceResolvable.- Parameters:
codes- the codes to be used to resolve this messagearguments- the array of arguments to be used to resolve this message
DefaultMessageSourceResolvable
public DefaultMessageSourceResolvable(@Nullable String[] codes, @Nullable Object[] arguments, @Nullable String defaultMessage)
Create a new DefaultMessageSourceResolvable.- Parameters:
codes- the codes to be used to resolve this messagearguments- the array of arguments to be used to resolve this messagedefaultMessage- the default message to be used to resolve this message
DefaultMessageSourceResolvable
public DefaultMessageSourceResolvable(MessageSourceResolvable resolvable)
Copy constructor: Create a new instance from another resolvable.- Parameters:
resolvable- the resolvable to copy from
Method Detail
getCode
@Nullable public String getCode()
Return the default code of this resolvable, that is, the last one in the codes array.
getCodes
@Nullable public String[] getCodes()
Description copied from interface:MessageSourceResolvableReturn the codes to be used to resolve this message, in the order that they should get tried. The last code will therefore be the default one.- Specified by:
getCodesin interfaceMessageSourceResolvable- Returns:
- a String array of codes which are associated with this message
getArguments
@Nullable public Object[] getArguments()
Description copied from interface:MessageSourceResolvableReturn the array of arguments to be used to resolve this message.The default implementation simply returns
null.- Specified by:
getArgumentsin interfaceMessageSourceResolvable- Returns:
- an array of objects to be used as parameters to replace placeholders within the message text
- See Also:
MessageFormat
getDefaultMessage
@Nullable public String getDefaultMessage()
Description copied from interface:MessageSourceResolvableReturn the default message to be used to resolve this message.The default implementation simply returns
null. Note that the default message may be identical to the primary message code (MessageSourceResolvable.getCodes()), which effectively enforcesAbstractMessageSource.setUseCodeAsDefaultMessage(boolean)for this particular message.- Specified by:
getDefaultMessagein interfaceMessageSourceResolvable- Returns:
- the default message, or
nullif no default
shouldRenderDefaultMessage
public boolean shouldRenderDefaultMessage()
Indicate whether the specified default message needs to be rendered for substituting placeholders and/orMessageFormatescaping.- Returns:
trueif the default message may contain argument placeholders;falseif it definitely does not contain placeholders or custom escaping and can therefore be simply exposed as-is- Since:
- 5.1.7
- See Also:
getDefaultMessage(),getArguments(),MessageSourceSupport.renderDefaultMessage(java.lang.String, java.lang.Object[], java.util.Locale)
resolvableToString
protected final String resolvableToString()
Build a default String representation for this MessageSourceResolvable: including codes, arguments, and default message.
toString
public String toString()
The default implementation exposes the attributes of this MessageSourceResolvable.To be overridden in more specific subclasses, potentially including the resolvable content through
resolvableToString().- Overrides:
toStringin classObject- See Also:
resolvableToString()