Java Doc for ReloadableResourceBundleMessageSource.java in  » J2EE » spring-framework-2.0.6 » org » springframework » context » support » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.context.support 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.context.support.AbstractMessageSource
      org.springframework.context.support.ReloadableResourceBundleMessageSource

ReloadableResourceBundleMessageSource
public class ReloadableResourceBundleMessageSource extends AbstractMessageSource implements ResourceLoaderAware(Code)
org.springframework.context.MessageSource implementation that accesses resource bundles using specified basenames. This class uses java.util.Properties instances as its custom data structure for messages, loading them via a org.springframework.util.PropertiesPersister strategy: The default strategy is capable of loading properties files with a specific character encoding, if desired.

In contrast to ResourceBundleMessageSource , this class supports reloading of properties files through the ReloadableResourceBundleMessageSource.setCacheSeconds "cacheSeconds" setting, and also through programmatically clearing the properties cache. Since application servers typically cache all files loaded from the classpath, it is necessary to store resources somewhere else (for example, in the "WEB-INF" directory of a web app). Otherwise changes of files in the classpath will not be reflected in the application.

Note that the base names set as ReloadableResourceBundleMessageSource.setBasenames "basenames" property are treated in a slightly different fashion than the "basenames" property of ResourceBundleMessageSource . It follows the basic ResourceBundle rule of not specifying file extension or language codes, but can refer to any Spring resource location (instead of being restricted to classpath resources). With a "classpath:" prefix, resources can still be loaded from the classpath, but "cacheSeconds" values other than "-1" (caching forever) will not work in this case.

This MessageSource implementation is usually slightly faster than ResourceBundleMessageSource , which builds on java.util.ResourceBundle - in the default mode, i.e. when caching forever. With "cacheSeconds" set to 1, message lookup takes about twice as long - with the benefit that changes in individual properties files are detected with a maximum delay of 1 second. Higher "cacheSeconds" values usually do not make a significant difference.

This MessageSource can easily be used outside of an org.springframework.context.ApplicationContext : It will use a org.springframework.core.io.DefaultResourceLoader as default, simply getting overridden with the ApplicationContext's resource loader if running in a context. It does not have any other specific dependencies.

Thanks to Thomas Achleitner for providing the initial implementation of this message source!
author:
   Juergen Hoeller
See Also:   ReloadableResourceBundleMessageSource.setCacheSeconds
See Also:   ReloadableResourceBundleMessageSource.setBasenames
See Also:   ReloadableResourceBundleMessageSource.setDefaultEncoding
See Also:   ReloadableResourceBundleMessageSource.setFileEncodings
See Also:   ReloadableResourceBundleMessageSource.setPropertiesPersister
See Also:   ReloadableResourceBundleMessageSource.setResourceLoader
See Also:   org.springframework.util.DefaultPropertiesPersister
See Also:   org.springframework.core.io.DefaultResourceLoader
See Also:   ResourceBundleMessageSource
See Also:   java.util.ResourceBundle


Inner Class :protected class PropertiesHolder



Method Summary
protected  ListcalculateAllFilenames(String basename, Locale locale)
     Calculate all filenames for the given bundle basename and Locale.
protected  ListcalculateFilenamesForLocale(String basename, Locale locale)
     Calculate the filenames for the given bundle basename and Locale, appending language code, country code, and variant code.
public  voidclearCache()
     Clear the resource bundle cache.
public  voidclearCacheIncludingAncestors()
     Clear the resource bundle caches of this MessageSource and all its ancestors.
protected  PropertiesHoldergetMergedProperties(Locale locale)
     Get a PropertiesHolder that contains the actually visible properties for a Locale, after merging all specified resource bundles. Either fetches the holder from the cache or freshly loads it.

Only used when caching resource bundle contents forever, i.e. with cacheSeconds < 0.

protected  PropertiesHoldergetProperties(String filename)
     Get a PropertiesHolder for the given filename, either from the cache or freshly loaded.
protected  PropertiesloadProperties(Resource resource, String filename)
     Load the properties from the given resource.
protected  PropertiesHolderrefreshProperties(String filename, PropertiesHolder propHolder)
     Refresh the PropertiesHolder for the given bundle filename.
protected  MessageFormatresolveCode(String code, Locale locale)
     Resolves the given message code as key in the retrieved bundle files, using a cached MessageFormat instance per message code.
protected  StringresolveCodeWithoutArguments(String code, Locale locale)
     Resolves the given message code as key in the retrieved bundle files, returning the value found in the bundle as-is (without MessageFormat parsing).
public  voidsetBasename(String basename)
     Set a single basename, following the basic ResourceBundle convention of not specifying file extension or language codes, but in contrast to ResourceBundleMessageSource referring to a Spring resource location: e.g.
public  voidsetBasenames(String[] basenames)
     Set an array of basenames, each following the basic ResourceBundle convention of not specifying file extension or language codes, but in contrast to ResourceBundleMessageSource referring to a Spring resource location: e.g.
public  voidsetCacheSeconds(int cacheSeconds)
     Set the number of seconds to cache loaded properties files.
  • Default is "-1", indicating to cache forever (just like java.util.ResourceBundle).
  • A positive number will cache loaded properties files for the given number of seconds.
public  voidsetDefaultEncoding(String defaultEncoding)
     Set the default charset to use for parsing properties files.
public  voidsetFallbackToSystemLocale(boolean fallbackToSystemLocale)
     Set whether to fall back to the system Locale if no files for a specific Locale have been found.
public  voidsetFileEncodings(Properties fileEncodings)
     Set per-file charsets to use for parsing properties files.

Only applies to classic properties files, not to XML files.
Parameters:
  fileEncodings - Properties with filenames as keys and charsetnames as values.

public  voidsetPropertiesPersister(PropertiesPersister propertiesPersister)
     Set the PropertiesPersister to use for parsing properties files.
public  voidsetResourceLoader(ResourceLoader resourceLoader)
     Set the ResourceLoader to use for loading bundle properties files.

The default is a DefaultResourceLoader.

public  StringtoString()
    



Method Detail
calculateAllFilenames
protected List calculateAllFilenames(String basename, Locale locale)(Code)
Calculate all filenames for the given bundle basename and Locale. Will calculate filenames for the given Locale, the system Locale (if applicable), and the default file.
Parameters:
  basename - the basename of the bundle
Parameters:
  locale - the locale the List of filenames to check
See Also:   ReloadableResourceBundleMessageSource.setFallbackToSystemLocale
See Also:   ReloadableResourceBundleMessageSource.calculateFilenamesForLocale



calculateFilenamesForLocale
protected List calculateFilenamesForLocale(String basename, Locale locale)(Code)
Calculate the filenames for the given bundle basename and Locale, appending language code, country code, and variant code. E.g.: basename "messages", Locale "de_AT_oo" -> "messages_de_AT_OO", "messages_de_AT", "messages_de".
Parameters:
  basename - the basename of the bundle
Parameters:
  locale - the locale the List of filenames to check



clearCache
public void clearCache()(Code)
Clear the resource bundle cache. Subsequent resolve calls will lead to reloading of the properties files.



clearCacheIncludingAncestors
public void clearCacheIncludingAncestors()(Code)
Clear the resource bundle caches of this MessageSource and all its ancestors.
See Also:   ReloadableResourceBundleMessageSource.clearCache



getMergedProperties
protected PropertiesHolder getMergedProperties(Locale locale)(Code)
Get a PropertiesHolder that contains the actually visible properties for a Locale, after merging all specified resource bundles. Either fetches the holder from the cache or freshly loads it.

Only used when caching resource bundle contents forever, i.e. with cacheSeconds < 0. Therefore, merged properties are always cached forever.




getProperties
protected PropertiesHolder getProperties(String filename)(Code)
Get a PropertiesHolder for the given filename, either from the cache or freshly loaded.
Parameters:
  filename - the bundle filename (basename + Locale) the current PropertiesHolder for the bundle



loadProperties
protected Properties loadProperties(Resource resource, String filename) throws IOException(Code)
Load the properties from the given resource.
Parameters:
  resource - the resource to load from
Parameters:
  filename - the original bundle filename (basename + Locale) the populated Properties instance
throws:
  IOException - if properties loading failed



refreshProperties
protected PropertiesHolder refreshProperties(String filename, PropertiesHolder propHolder)(Code)
Refresh the PropertiesHolder for the given bundle filename. The holder can be null if not cached before, or a timed-out cache entry (potentially getting re-validated against the current last-modified timestamp).
Parameters:
  filename - the bundle filename (basename + Locale)
Parameters:
  propHolder - the current PropertiesHolder for the bundle



resolveCode
protected MessageFormat resolveCode(String code, Locale locale)(Code)
Resolves the given message code as key in the retrieved bundle files, using a cached MessageFormat instance per message code.



resolveCodeWithoutArguments
protected String resolveCodeWithoutArguments(String code, Locale locale)(Code)
Resolves the given message code as key in the retrieved bundle files, returning the value found in the bundle as-is (without MessageFormat parsing).



setBasename
public void setBasename(String basename)(Code)
Set a single basename, following the basic ResourceBundle convention of not specifying file extension or language codes, but in contrast to ResourceBundleMessageSource referring to a Spring resource location: e.g. "WEB-INF/messages" for "WEB-INF/messages.properties", "WEB-INF/messages_en.properties", etc.

As of Spring 1.2.2, XML properties files are also supported: e.g. "WEB-INF/messages" will find and load "WEB-INF/messages.xml", "WEB-INF/messages_en.xml", etc as well. Note that this will only work on JDK 1.5+.
Parameters:
  basename - the single basename
See Also:   ReloadableResourceBundleMessageSource.setBasenames
See Also:   org.springframework.core.io.ResourceEditor
See Also:   java.util.ResourceBundle




setBasenames
public void setBasenames(String[] basenames)(Code)
Set an array of basenames, each following the basic ResourceBundle convention of not specifying file extension or language codes, but in contrast to ResourceBundleMessageSource referring to a Spring resource location: e.g. "WEB-INF/messages" for "WEB-INF/messages.properties", "WEB-INF/messages_en.properties", etc.

As of Spring 1.2.2, XML properties files are also supported: e.g. "WEB-INF/messages" will find and load "WEB-INF/messages.xml", "WEB-INF/messages_en.xml", etc as well. Note that this will only work on JDK 1.5+.

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:   ReloadableResourceBundleMessageSource.setBasename
See Also:   java.util.ResourceBundle




setCacheSeconds
public void setCacheSeconds(int cacheSeconds)(Code)
Set the number of seconds to cache loaded properties files.
  • Default is "-1", indicating to cache forever (just like java.util.ResourceBundle).
  • A positive number will cache loaded properties files for the given number of seconds. This is essentially the interval between refresh checks. Note that a refresh attempt will first check the last-modified timestamp of the file before actually reloading it; so if files don't change, this interval can be set rather low, as refresh attempts will not actually reload.
  • A value of "0" will check the last-modified timestamp of the file on every message access. Do not use this in a production environment!



setDefaultEncoding
public void setDefaultEncoding(String defaultEncoding)(Code)
Set the default charset to use for parsing properties files. Used if no file-specific charset is specified for a file.

Default is none, using the java.util.Properties default encoding.

Only applies to classic properties files, not to XML files.
Parameters:
  defaultEncoding - the default charset
See Also:   ReloadableResourceBundleMessageSource.setFileEncodings
See Also:   org.springframework.util.PropertiesPersister.load




setFallbackToSystemLocale
public void setFallbackToSystemLocale(boolean fallbackToSystemLocale)(Code)
Set whether to fall back to the system Locale if no files for a specific Locale have been found. Default is "true"; if this is turned off, the only fallback will be the default file (e.g. "messages.properties" for basename "messages").

Falling back to the system Locale is the default behavior of java.util.ResourceBundle. However, this is often not desirable in an application server environment, where the system Locale is not relevant to the application at all: Set this flag to "false" in such a scenario.




setFileEncodings
public void setFileEncodings(Properties fileEncodings)(Code)
Set per-file charsets to use for parsing properties files.

Only applies to classic properties files, not to XML files.
Parameters:
  fileEncodings - Properties with filenames as keys and charsetnames as values. Filenames have to match the basename syntax,with optional locale-specific appendices: e.g. "WEB-INF/messages"or "WEB-INF/messages_en".
See Also:   ReloadableResourceBundleMessageSource.setBasenames
See Also:   org.springframework.util.PropertiesPersister.load




setPropertiesPersister
public void setPropertiesPersister(PropertiesPersister propertiesPersister)(Code)
Set the PropertiesPersister to use for parsing properties files.

The default is a DefaultPropertiesPersister.
See Also:   org.springframework.util.DefaultPropertiesPersister




setResourceLoader
public void setResourceLoader(ResourceLoader resourceLoader)(Code)
Set the ResourceLoader to use for loading bundle properties files.

The default is a DefaultResourceLoader. Will get overridden by the ApplicationContext if running in a context, as it implements the ResourceLoaderAware interface. Can be manually overridden when running outside of an ApplicationContext.
See Also:   org.springframework.core.io.DefaultResourceLoader
See Also:   org.springframework.context.ResourceLoaderAware




toString
public String toString()(Code)



Fields inherited from org.springframework.context.support.AbstractMessageSource
final protected Log logger(Code)(Java Doc)

Methods inherited from org.springframework.context.support.AbstractMessageSource
protected MessageFormat createMessageFormat(String msg, Locale locale)(Code)(Java Doc)
protected String formatMessage(String msg, Object[] args, Locale locale)(Code)(Java Doc)
protected String getDefaultMessage(String code)(Code)(Java Doc)
final public String getMessage(String code, Object[] args, String defaultMessage, Locale locale)(Code)(Java Doc)
final public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException(Code)(Java Doc)
final public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException(Code)(Java Doc)
protected String getMessageFromParent(String code, Object[] args, Locale locale)(Code)(Java Doc)
protected String getMessageInternal(String code, Object[] args, Locale locale)(Code)(Java Doc)
public MessageSource getParentMessageSource()(Code)(Java Doc)
protected boolean isAlwaysUseMessageFormat()(Code)(Java Doc)
protected boolean isUseCodeAsDefaultMessage()(Code)(Java Doc)
protected String renderDefaultMessage(String defaultMessage, Object[] args, Locale locale)(Code)(Java Doc)
protected Object[] resolveArguments(Object[] args, Locale locale)(Code)(Java Doc)
abstract protected MessageFormat resolveCode(String code, Locale locale)(Code)(Java Doc)
protected String resolveCodeWithoutArguments(String code, Locale locale)(Code)(Java Doc)
public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat)(Code)(Java Doc)
public void setParentMessageSource(MessageSource parent)(Code)(Java Doc)
public void setUseCodeAsDefaultMessage(boolean useCodeAsDefaultMessage)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.