|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.support.AbstractMessageSource org.springframework.context.support.ResourceBundleMessageSource
public class ResourceBundleMessageSource
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.
setBasenames(java.lang.String[])
,
ReloadableResourceBundleMessageSource
,
ResourceBundle
Field Summary |
---|
Fields inherited from class org.springframework.context.support.AbstractMessageSource |
---|
logger |
Constructor Summary | |
---|---|
ResourceBundleMessageSource()
|
Method Summary | |
---|---|
protected MessageFormat |
getMessageFormat(ResourceBundle bundle,
String code,
Locale locale)
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)
Subclasses must implement this method to resolve a message. |
protected String |
resolveCodeWithoutArguments(String code,
Locale locale)
Subclasses can override this method to resolve a message without arguments in an optimized fashion, i.e. to resolve a message without involving a MessageFormat. |
void |
setBasename(String basename)
Set a single basename, following ResourceBundle conventions: It is a fully-qualified classname. |
void |
setBasenames(String[] basenames)
Set an array of basenames, each following ResourceBundle conventions. |
void |
setClassLoader(ClassLoader classLoader)
Set the ClassLoader to load resource bundles with, or null for using the thread context class loader on actual access (applying to the thread that does the "getMessage" call). |
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 |
---|
public ResourceBundleMessageSource()
Method Detail |
---|
public void setBasename(String basename)
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.
basename
- the single basenamesetBasenames(java.lang.String[])
,
ResourceBundle
public void setBasenames(String[] basenames)
Note that message definitions in a previous resource bundle will override ones in a later bundle, due to the sequential lookup.
basenames
- an array of basenamessetBasename(java.lang.String)
,
ResourceBundle
public void setClassLoader(ClassLoader classLoader)
protected String resolveCodeWithoutArguments(String code, Locale locale)
AbstractMessageSource
The default implementation does use MessageFormat,
through delegating to the resolveCode
method.
Subclasses are encouraged to replace this with optimized resolution.
Unfortunately, java.text.MessageFormat
is 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's advisable to circumvent
MessageFormat completely for messages without arguments.
resolveCodeWithoutArguments
in class AbstractMessageSource
code
- the code of the message to resolvelocale
- the Locale to resolve the code for
(subclasses are encouraged to support internationalization)
AbstractMessageSource.resolveCode(java.lang.String, java.util.Locale)
,
MessageFormat
protected MessageFormat resolveCode(String code, Locale locale)
AbstractMessageSource
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.
resolveCode
in class AbstractMessageSource
code
- the code of the message to resolvelocale
- the Locale to resolve the code for
(subclasses are encouraged to support internationalization)
AbstractMessageSource.resolveCodeWithoutArguments(java.lang.String, java.util.Locale)
protected ResourceBundle getResourceBundle(String basename, Locale locale)
basename
- the basename of the ResourceBundlelocale
- the Locale to find the ResourceBundle for
protected MessageFormat getMessageFormat(ResourceBundle bundle, String code, Locale locale) throws MissingResourceException
bundle
- the ResourceBundle to work oncode
- the message code to retrievelocale
- the Locale to use to build the MessageFormat
MissingResourceException
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |