Class StaticMessageSource

  extended by
      extended by
          extended by
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.

Rod Johnson, Juergen Hoeller

Field Summary
Fields inherited from class
Constructor Summary
Method Summary
 void addMessage(String code, Locale locale, String msg)
          Associate the given message with the given code.
 void addMessages(Map messages, Locale locale)
          Associate the given message values with the given keys as codes.
protected  MessageFormat resolveCode(String code, Locale locale)
          Subclasses must implement this method to resolve a message.
 String toString()
Methods inherited from class
getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, renderDefaultMessage, resolveArguments, resolveCodeWithoutArguments, setParentMessageSource, setUseCodeAsDefaultMessage
Methods inherited from class
createMessageFormat, formatMessage, isAlwaysUseMessageFormat, setAlwaysUseMessageFormat
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public StaticMessageSource()
Method Detail


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 resolveCodeWithoutArguments javadoc for details.

Specified by:
resolveCode in class AbstractMessageSource
code - the code of the message to resolve
locale - the Locale to resolve the code for (subclasses are encouraged to support internationalization)
the MessageFormat for the message, or null if not found
See Also:
AbstractMessageSource.resolveCodeWithoutArguments(String, java.util.Locale)


public void addMessage(String code,
                       Locale locale,
                       String msg)
Associate the given message with the given code.

code - the lookup code
locale - the locale that the message should be found within
msg - the message associated with this lookup code


public void addMessages(Map messages,
                        Locale locale)
Associate the given message values with the given keys as codes.

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


public String toString()
toString in class Object

Copyright © 2002-2008 The Spring Framework.