[brailleblaster] Re: Where should properties files go?

  • From: Michael Whapples <mwhapples@xxxxxxx>
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Mon, 06 Dec 2010 10:40:19 +0000

Hello,
For these properties files the path you specify is relative to the path of the ClassLoader use in ResourceBundle.getBundle. If you use ResourceBundle.getBundle(baseName, locale) then this will use the ClassLoader this.getClass().getClassLoader(). This will result in the properties file being found relative to the base of the package structure and can be within a jar.

So as an example the English UK file which has menu messages might be called MenuMessages_en_GB.properties and might be placed in a directory which would relate to the package org.brailleblaster.i18n. This would mean that the baseName would be org.brailleblaster.i18n.MenuMessages.

As to how ResourceBundle and the getBundle method works, it would be an example of a factory pattern http://www.javaworld.com/javaworld/javaqa/2001-05/02-qa-0511-factory.html. It is worth noting that article doesn't go very far, but the factory method can make decisions based on parameters passed in. So while ResourceBundle is abstract, you may still make use of its static methods and instances of subclasses can appear as a type ResourceBundle due to polymorphism, meaning you need never know what specific type is being used.

Michael Whapples
On 06/12/10 08:59, John J. Boyer wrote:
It looks like ResourceBundle.getBundle will look first for a subclass
with a given candidate name and then for a properties file with this
name. Where should such properties files go? Would it be acceptable to
place them in a subdirectory of brailleblaster called propertiesfiles?
Since ResourceBundle is an abstract class, it canot be instantiated. I'm
rather puzzled about how all this fits together.

John



Other related posts: