org.apache.commons.resources.impl
Class ResourceBundleResources

java.lang.Object
  extended by org.apache.commons.resources.impl.ResourcesBase
      extended by org.apache.commons.resources.impl.ResourceBundleResources
All Implemented Interfaces:
Serializable, Resources

public class ResourceBundleResources
extends ResourcesBase

Concrete implementation of Resources that wraps a set (one per Locale) of java.util.ResourceBundle instances that share a common base name.

See Also:
Serialized Form

Constructor Summary
ResourceBundleResources(String name, String base)
          Create a new Resources instance with the specified logical name and bundle base name.
 
Method Summary
 String getBase()
          Return the fully qualified base name of the ResourceBundle instances we are wrapping.
protected  ResourceBundle getBundle(Locale locale)
          Return the appropriate ResourceBundle instance that corresponds to the specified locale parameter.
protected  ClassLoader getClassLoader()
          Return the ClassLoader for which we are mapping ResourceBundle instances.
 Iterator getKeys()
          Return an Iterator over the defined keys in this Resources instance.
 Object getObject(String key, Locale locale)
          Return the content for the specified key as an Object, localized based on the specified locale.
 
Methods inherited from class org.apache.commons.resources.impl.ResourcesBase
destroy, getBufferSize, getBytes, getInputStream, getName, getReader, getString, init, isReturnNull, setBufferSize, setReturnNull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceBundleResources

public ResourceBundleResources(String name,
                               String base)

Create a new Resources instance with the specified logical name and bundle base name.

Parameters:
name - Logical name of the new instance
base - Fully qualified base name of the ResourceBundle instances to be wrapped
Method Detail

getBase

public String getBase()

Return the fully qualified base name of the ResourceBundle instances we are wrapping.

Returns:
The base name of this resources instance.

getKeys

public Iterator getKeys()

Return an Iterator over the defined keys in this Resources instance.

Specified by:
getKeys in interface Resources
Specified by:
getKeys in class ResourcesBase
Returns:
The keys contained in this resources instance.

getObject

public Object getObject(String key,
                        Locale locale)

Return the content for the specified key as an Object, localized based on the specified locale.

Specified by:
getObject in interface Resources
Specified by:
getObject in class ResourcesBase
Parameters:
key - Identifier for the requested content
locale - Locale with which to localize retrieval, or null for the default Locale
Returns:
content for a specified key.
Throws:
ResourcesException - if an error occurs retrieving or returning the requested content
ResourcesKeyException - if the no value for the specified key was found, and isReturnNull() returns false

getBundle

protected ResourceBundle getBundle(Locale locale)
                            throws MissingResourceException

Return the appropriate ResourceBundle instance that corresponds to the specified locale parameter. The first time a particular bundle is requested, cache it so that subsequent requests will operate more quickly.

Parameters:
locale - Locale with which to localize retrieval, or null for the default Locale
Returns:
The Resource Bundle corresponding to the locale and time zone.
Throws:
MissingResourceException - if the requested Resourcebundle cannot be acquired

getClassLoader

protected ClassLoader getClassLoader()

Return the ClassLoader for which we are mapping ResourceBundle instances.

Returns:
The Class Loader for the resource bundle.


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.