Java Reference
In-Depth Information
Example 10•22: GUIResourceBundle.java (continued)
throws MissingResourceException
{
this.root = root;
this.bundle = ResourceBundle.getBundle(bundleName);
}
/**
* Create a PropertyResourceBundle from the specified stream and then
* create a GUIResourceBundle wrapper for it
**/
public GUIResourceBundle(Object root, InputStream propertiesStream)
throws IOException
{
this.root = root;
this.bundle = new PropertyResourceBundle(propertiesStream);
}
/**
* Create a PropertyResourceBundle from the specified properties file and
* then create a GUIResourceBundle wrapper for it.
**/
public GUIResourceBundle(Object root, File propertiesFile)
throws IOException
{
this(root, new FileInputStream(propertiesFile));
}
/** This is one of the abstract methods of ResourceBundle */
public Enumeration getKeys() { return bundle.getKeys(); }
/** This is the other abstract method of ResourceBundle */
protected Object handleGetObject(String key)
throws MissingResourceException
{
return bundle.getObject(key); // simply defer to the wrapped bundle
}
/** This is a property accessor method for our root object */
public Object getRoot() { return root; }
/**
* This method is like the inherited getString() method, except that
* when the named resource is not found, it returns the specified default
* instead of throwing an exception
**/
public String getString(String key, String defaultValue) {
try { return bundle.getString(key); }
catch(MissingResourceException e) { return defaultValue; }
}
/**
* Look up the named resource and parse it as a list of strings separated
* by spaces, tabs, or commas.
**/
public java.util.List getStringList(String key)
throws MissingResourceException
{
String s = getString(key);
Search WWH ::




Custom Search