• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in ResourceBundle  RSS feed

 
srinibadri Srinivasan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I have a doubt with respect to custom Resource Bundle?i.e creatingo our own resource bundle class.

In the API they have specified that if you want to create custom Resource Bundle,you should extend the Resource Bundle class and then override two APIS

i.e handleGetObject() and getKeys() method...

My doubt is when this handleGetObject() and getKeys() method are invoked?I have never seen a call to these two methods in some of the sample which I have seen ...

Please clarify me on this topic....

Thanks in advance
 
Ritesh Agrawal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinivasan,

These two methods are declared abstract and need to be overridden by subclasses of ResourceBundle. The method handleGetObject is not invoked directly by implementation code. When you use getObject in your code, the handleGetObject method is internally called to retrieve the object.

Here is an excerpt from Java API Docs
---------
public final Object getObject(String key)

Gets an object for the given key from this resource bundle or one of its parents. This method first tries to obtain the object from this resource bundle using handleGetObject. If not successful, and the parent resource bundle is not null, it calls the parent's getObject method. If still not successful, it throws a MissingResourceException.
---------
Now, since you are providing the implementaion for your own ResourceBundle, only your class will know how to manage the Key/Value pairs. So it's a must that you provide a convenience method to obtain the enumeration of keys. Thus , you must override the getKeys method. This method can be used directly in other classes using your ResourceBundle and it only seems logical. Look further and you might find certain examples demonstrating the use of the getKeys method. It's analogous to keys() method provided by certain Collection classes like Hashtable.
[ August 24, 2005: Message edited by: Ritesh Agrawal ]
 
srinibadri Srinivasan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Ritesh...

Now am clear...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!