Class StaticMessageSource
- All Implemented Interfaces:
- HierarchicalMessageSource,- MessageSource
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
- 
Field SummaryFields inherited from class org.springframework.context.support.MessageSourceSupportlogger
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddMessage(String code, Locale locale, String msg) Associate the given message with the given code.voidaddMessages(Map<String, String> messages, Locale locale) Associate the given message values with the given keys as codes.protected MessageFormatresolveCode(String code, Locale locale) Subclasses must implement this method to resolve a message.protected StringresolveCodeWithoutArguments(String code, Locale locale) Subclasses can override this method to resolve a message without arguments in an optimized fashion, i.e.toString()Methods inherited from class org.springframework.context.support.AbstractMessageSourcegetCommonMessages, getDefaultMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessageMethods inherited from class org.springframework.context.support.MessageSourceSupportcreateMessageFormat, formatMessage, isAlwaysUseMessageFormat, renderDefaultMessage, setAlwaysUseMessageFormat
- 
Constructor Details- 
StaticMessageSourcepublic StaticMessageSource()
 
- 
- 
Method Details- 
resolveCodeWithoutArgumentsDescription copied from class:AbstractMessageSourceSubclasses can override this method to resolve a message without arguments in an optimized fashion, i.e. to resolve without involving a MessageFormat.The default implementation does use MessageFormat, through delegating to the AbstractMessageSource.resolveCode(java.lang.String, java.util.Locale)method. Subclasses are encouraged to replace this with optimized resolution.Unfortunately, java.text.MessageFormatis not implemented in an efficient fashion. In particular, it does not detect that a message pattern doesn't contain argument placeholders in the first place. Therefore, it is advisable to circumvent MessageFormat for messages without arguments.- Overrides:
- resolveCodeWithoutArgumentsin class- AbstractMessageSource
- Parameters:
- code- the code of the message to resolve
- locale- the locale to resolve the code for (subclasses are encouraged to support internationalization)
- Returns:
- the message String, or nullif not found
- See Also:
 
- 
resolveCodeDescription copied from class:AbstractMessageSourceSubclasses 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:
- resolveCodein class- AbstractMessageSource
- Parameters:
- code- the code of the message to resolve
- locale- the locale to resolve the code for (subclasses are encouraged to support internationalization)
- Returns:
- the MessageFormat for the message, or nullif not found
- See Also:
 
- 
addMessageAssociate the given message with the given code.- Parameters:
- code- the lookup code
- locale- the locale that the message should be found within
- msg- the message associated with this lookup code
 
- 
addMessagesAssociate 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 values
- locale- the locale that the messages should be found within
 
- 
toString
 
-