Save This Page
Home » spring-framework-2.5.4 » org.springframework » context » support » [javadoc | source]
org.springframework.context.support
public class: ResourceBundleMessageSource [javadoc | source]
java.lang.Object
   org.springframework.context.support.AbstractMessageSource
      org.springframework.context.support.ResourceBundleMessageSource

All Implemented Interfaces:
    BeanClassLoaderAware, HierarchicalMessageSource

org.springframework.context.MessageSource implementation that accesses resource bundles using specified basenames. This class relies on the underlying JDK's java.util.ResourceBundle implementation, in combination with the JDK's standard message parsing provided by java.text.MessageFormat .

This MessageSource caches both the accessed ResourceBundle instances and the generated MessageFormats for each message. It also implements rendering of no-arg messages without MessageFormat, as supported by the AbstractMessageSource base class. The caching provided by this MessageSource is significantly faster than the built-in caching of the java.util.ResourceBundle class.

Unfortunately, java.util.ResourceBundle caches loaded bundles forever: Reloading a bundle during VM execution is not possible. As this MessageSource relies on ResourceBundle, it faces the same limitation. Consider ReloadableResourceBundleMessageSource for an alternative that is capable of refreshing the underlying bundle files.

Fields inherited from org.springframework.context.support.AbstractMessageSource:
logger
Method from org.springframework.context.support.ResourceBundleMessageSource Summary:
doGetBundle,   getBundleClassLoader,   getMessageFormat,   getResourceBundle,   resolveCode,   resolveCodeWithoutArguments,   setBasename,   setBasenames,   setBeanClassLoader,   setBundleClassLoader,   toString
Methods from org.springframework.context.support.AbstractMessageSource:
createMessageFormat,   formatMessage,   getDefaultMessage,   getMessage,   getMessage,   getMessage,   getMessageFromParent,   getMessageInternal,   getParentMessageSource,   isAlwaysUseMessageFormat,   isUseCodeAsDefaultMessage,   renderDefaultMessage,   resolveArguments,   resolveCode,   resolveCodeWithoutArguments,   setAlwaysUseMessageFormat,   setParentMessageSource,   setUseCodeAsDefaultMessage
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.context.support.ResourceBundleMessageSource Detail:
 protected ResourceBundle doGetBundle(String basename,
    Locale locale) throws MissingResourceException 
    Obtain the resource bundle for the given basename and Locale.
 protected ClassLoader getBundleClassLoader() 
    Return the ClassLoader to load resource bundles with.

    Default is the containing BeanFactory's bean ClassLoader.

 protected MessageFormat getMessageFormat(ResourceBundle bundle,
    String code,
    Locale locale) throws MissingResourceException 
    Return a MessageFormat for the given bundle and code, fetching already generated MessageFormats from the cache.
 protected ResourceBundle getResourceBundle(String basename,
    Locale locale) 
    Return a ResourceBundle for the given basename and code, fetching already generated MessageFormats from the cache.
 protected MessageFormat resolveCode(String code,
    Locale locale) 
    Resolves the given message code as key in the registered resource bundles, using a cached MessageFormat instance per message code.
 protected String resolveCodeWithoutArguments(String code,
    Locale locale) 
    Resolves the given message code as key in the registered resource bundles, returning the value found in the bundle as-is (without MessageFormat parsing).
 public  void setBasename(String basename) 
    Set a single basename, following java.util.ResourceBundle conventions: essentially, a fully-qualified classpath location. 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 web application's WAR structure. They can also be held in jar files on the class path.

    Note that ResourceBundle names are effectively classpath locations: As a consequence, the JDK's standard ResourceBundle treats dots as package separators. This means that "test.theme" is effectively equivalent to "test/theme", just like it is for programmatic java.util.ResourceBundle usage.

 public  void setBasenames(String[] basenames) 
    Set an array of basenames, each following java.util.ResourceBundle conventions: essentially, a fully-qualified classpath location. If it doesn't contain a package qualifier (such as org.mypackage), it will be resolved from the classpath root.

    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.

    Note that ResourceBundle names are effectively classpath locations: As a consequence, the JDK's standard ResourceBundle treats dots as package separators. This means that "test.theme" is effectively equivalent to "test/theme", just like it is for programmatic java.util.ResourceBundle usage.

 public  void setBeanClassLoader(ClassLoader classLoader) 
 public  void setBundleClassLoader(ClassLoader classLoader) 
 public String toString() 
    Show the configuration of this MessageSource.