• Post Reply Bookmark Topic Watch Topic
  • New Topic

"Standard" way to use ResourceBundles  RSS feed

 
David Nemeskey
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am curious what is the "standard" way to use ResourceBundles. I am creating a GUI application right now, and I came up with the following. There are two problems: access (1) and usage (2):

1:
The javadoc says that ResourceBundles MIGHT be cached. As it turns out, the Sun implementation IS cached, but it is not obligatory. So creating it each time with getBundle() may lead to problems.

It can be created once, and passed around as parameters. But I don't know if it is a good idea to put it into the API everywhere like this.

I can make it static / use a singleton. It only allows for 1 Locale at a time, but it is okay for me now. But there may be a problem if it cannot be instantiated (no bundles exist, etc).

2:
Then there is the problem of MissingResourceException: it should be caught "just in case", but should I litter my code with try {} catch-es? I thought of subclassing it, but it is not possible due to the package-level access methods in ResourceBundle. So I thought of creating a wrapper object, which just returns the key or null if I call it with an invalid key. I think this makes the application more robust.

Thanks,
David
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!