org.springframework.context.support
Class StaticMessageSource

java.lang.Object
  extended byorg.springframework.context.support.AbstractMessageSource
      extended byorg.springframework.context.support.StaticMessageSource
All Implemented Interfaces:
HierarchicalMessageSource, MessageSource

public class StaticMessageSource
extends AbstractMessageSource

Simple implementation of MessageSource that allows messages to be held in a Java object, and added programmatically. This MessageSource supports internationalization.

Intended for testing rather than use in production systems.

Author:
Rod Johnson, Juergen Hoeller

Field Summary
 
Fields inherited from class org.springframework.context.support.AbstractMessageSource
logger
 
Constructor Summary
StaticMessageSource()
           
 
Method Summary
 void addMessage(String code, Locale locale, String message)
          Associate the given message with the given code.
protected  MessageFormat resolveCode(String code, Locale locale)
          Subclasses must implement this method to resolve a message.
 String toString()
           
 
Methods inherited from class org.springframework.context.support.AbstractMessageSource
createMessageFormat, getMessage, getMessage, getMessage, getMessageInternal, getParentMessageSource, resolveArguments, resolveCodeWithoutArguments, setParentMessageSource, setUseCodeAsDefaultMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StaticMessageSource

public StaticMessageSource()
Method Detail

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

Specified by:
resolveCode in 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 null if not found
See Also:
AbstractMessageSource.resolveCodeWithoutArguments(java.lang.String, java.util.Locale)

addMessage

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

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

toString

public String toString()


Copyright (C) 2003-2004 The Spring Framework Project.