Posted by joconner
on March 21, 2007 at 2:53 PM PDT
Can you imagine your app being up for 299 straight days without a hitch...something perhaps to brag about...but now you have to bring it down because you want to change a single localized resource bundle that's stuck in the JRE cache?
Storing localized resources for your Java applications usually means creating a
.properties file or a
ResourceBundle subclass. You don't usually have a lot of control over how the resources are cached or how they're stored.
Here's an example. The enforced caching of resources was a common complaint for server applications. Can you imagine your app being up for 299 straight days without a hitch...something perhaps to brag about...but now you have to bring it down because you want to change a single localized resource bundle that's stuck in the JRE cache?
Now you don't have to bring down an application to update resources. You have more control over how your applications cache resource bundles. You no longer have to store them as
ResourceBundle subclasses either. If you want an XML format, sure, you can have it. Don't like files at all? Want to retrieve the resources from a db? You can have that too. Oh, you don't like storing bundles with locale prefixes (MyBundle_fr, MyBundle_en_US, etc)? OK. You don't have to anymore.
How is that possible? Why is
ResourceBundle so flexible now? It's all about control, which you now have. That's
ResourceBundle.Control actually. This new class allows you to control practically every aspect of how bundles are searched, loaded, and cached. Create your own
Controlsubclass, provide it to the
ResourceBundle.getBundle method, and now you're in the driver's seat. The new class provides several methods that you can override to affect caching, naming, searching, defaults, fallbacks, etc. You control it all.
You can read about
ResourceBundle.Control in its online javadocs . Or check out this and other new internationalization features in Java SE 6 by reading International Enhancements in Java SE 6 . Let me know what you like in that overview, and maybe I can cover it in more detail here.