org.springframework.context.support
Class StaticMessageSource
java.lang.Object
org.springframework.context.support.MessageSourceSupport
org.springframework.context.support.AbstractMessageSource
org.springframework.context.support.StaticMessageSource
- All Implemented Interfaces:
- HierarchicalMessageSource, MessageSource
public class StaticMessageSource
- extends AbstractMessageSource
Simple implementation of MessageSource
which allows messages to be registered programmatically.
This MessageSource supports basic internationalization.
Intended for testing rather than for use in production systems.
- Author:
- Rod Johnson, Juergen Hoeller
Methods inherited from class org.springframework.context.support.AbstractMessageSource |
getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, renderDefaultMessage, resolveArguments, resolveCodeWithoutArguments, setParentMessageSource, setUseCodeAsDefaultMessage |
StaticMessageSource
public StaticMessageSource()
resolveCode
protected MessageFormat resolveCode(String code,
Locale locale)
- Description copied from class:
AbstractMessageSource
- Subclasses must implement this method to resolve a message.
Returns a MessageFormat instance rather than a message String,
to allow for appropriate caching of MessageFormats in subclasses.
Subclasses are encouraged to provide optimized resolution
for messages without arguments, not involving MessageFormat.
See the AbstractMessageSource.resolveCodeWithoutArguments(java.lang.String, java.util.Locale)
javadoc for details.
- Specified by:
resolveCode
in class AbstractMessageSource
- Parameters:
code
- the code of the message to resolvelocale
- the Locale to resolve the code for
(subclasses are encouraged to support internationalization)
- Returns:
- the MessageFormat for the message, or
null
if not found - See Also:
AbstractMessageSource.resolveCodeWithoutArguments(String, java.util.Locale)
addMessage
public void addMessage(String code,
Locale locale,
String msg)
- Associate the given message with the given code.
- Parameters:
code
- the lookup codelocale
- the locale that the message should be found withinmsg
- the message associated with this lookup code
addMessages
public void addMessages(Map<String,String> messages,
Locale locale)
- Associate the given message values with the given keys as codes.
- Parameters:
messages
- the messages to register, with messages codes
as keys and message texts as valueslocale
- the locale that the messages should be found within
toString
public String toString()
- Overrides:
toString
in class Object