org.springframework.context.support
Class ResourceBundleMessageSource

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

public class ResourceBundleMessageSource
extends AbstractMessageSource

MessageSource that accesses the ResourceBundles with the specified basenames. This class relies on the underlying JDK's java.util.ResourceBundle implementation.

Unfortunately, java.util.ResourceBundle caches loaded bundles indefinitely. Reloading a bundle during VM execution is not possible by any means. As this MessageSource relies on ResourceBundle, it faces the same limitation. Consider ReloadableResourceBundleMessageSource for an alternative.

Author:
Rod Johnson, Juergen Hoeller
See Also:
setBasenames(java.lang.String[]), ReloadableResourceBundleMessageSource, ResourceBundle

Field Summary
 
Fields inherited from class org.springframework.context.support.AbstractMessageSource
logger
 
Constructor Summary
ResourceBundleMessageSource()
           
 
Method Summary
protected  java.text.MessageFormat getMessageFormat(java.util.ResourceBundle bundle, java.lang.String code, java.util.Locale locale)
          Return a MessageFormat for the given bundle and code, fetching already generated MessageFormats from the cache.
protected  java.text.MessageFormat resolve(java.lang.String basename, java.lang.String code, java.util.Locale locale)
          Return a MessageFormat for the given bundle basename, message code, and Locale.
protected  java.text.MessageFormat resolveCode(java.lang.String code, java.util.Locale locale)
          Subclasses must implement this method to resolve a message.
 void setBasename(java.lang.String basename)
          Set a single basename, following ResourceBundle conventions: It is a fully-qualified classname.
 void setBasenames(java.lang.String[] basenames)
          Set an array of basenames, each following ResourceBundle conventions.
 java.lang.String toString()
          Show the configuration of this MessageSource.
 
Methods inherited from class org.springframework.context.support.AbstractMessageSource
createMessageFormat, getMessage, getMessage, getMessage, getMessageInternal, getParentMessageSource, resolveArguments, setParentMessageSource, setUseCodeAsDefaultMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceBundleMessageSource

public ResourceBundleMessageSource()
Method Detail

setBasename

public void setBasename(java.lang.String basename)
Set a single basename, following ResourceBundle conventions: It is a fully-qualified classname. If it doesn't contain a package qualifier (such as org.mypackage), it will be resolved from the classpath root.

Messages will normally be held in the /lib or /classes directory of a WAR. They can also be held in Jars on the class path. For example, a Jar in an application's manifest classpath could contain messages for the application.

Parameters:
basename - the single basename
See Also:
setBasenames(java.lang.String[]), ResourceBundle

setBasenames

public void setBasenames(java.lang.String[] basenames)
Set an array of basenames, each following ResourceBundle conventions. The associated resource bundles will be checked sequentially when resolving a message code.

Note that message definitions in a previous resource bundle will override ones in a later bundle, due to the sequential lookup.

Parameters:
basenames - an array of basenames
See Also:
setBasename(java.lang.String), ResourceBundle

resolveCode

protected final java.text.MessageFormat resolveCode(java.lang.String code,
                                                    java.util.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.

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

resolve

protected java.text.MessageFormat resolve(java.lang.String basename,
                                          java.lang.String code,
                                          java.util.Locale locale)
Return a MessageFormat for the given bundle basename, message code, and Locale.

Parameters:
basename - the basename of the bundle
code - the message code to retrieve
locale - the Locale to resolve for
Returns:
the resulting MessageFormat

getMessageFormat

protected java.text.MessageFormat getMessageFormat(java.util.ResourceBundle bundle,
                                                   java.lang.String code,
                                                   java.util.Locale locale)
                                            throws java.util.MissingResourceException
Return a MessageFormat for the given bundle and code, fetching already generated MessageFormats from the cache.

Parameters:
bundle - the ResourceBundle to work on
code - the message code to retrieve
locale - the Locale to use to build the MessageFormat
Returns:
the resulting MessageFormat
Throws:
java.util.MissingResourceException

toString

public java.lang.String toString()
Show the configuration of this MessageSource.



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