org.apache.commons.resources.impl
Class ResourceBundleResources

java.lang.Object
  |
  +--org.apache.commons.resources.impl.ResourcesBase
        |
        +--org.apache.commons.resources.impl.ResourceBundleResources
All Implemented Interfaces:
Resources, Serializable

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. The timeZone argument is ignored in all resource getter method implementations.

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
 void destroy()
          This method must be called when the manager of this resource decides that it's no longer needed.
 String getBase()
          Return the fully qualified base name of the ResourceBundle instances we are wrapping.
protected  ResourceBundle getBundle(Locale locale, TimeZone timeZone)
          Return the appropriate ResourceBundle instance that corresponds to the specified locale and timeZone parameters.
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, TimeZone timeZone)
          Return the content for the specified key as an Object, localized based on the specified locale and/or timeZone.
 void init()
          This must be called to initialize the data content of this Resources instance, before any of the getXxx() methods are called.
 
Methods inherited from class org.apache.commons.resources.impl.ResourcesBase
getBufferSize, getBytes, getInputStream, getName, getReader, getString, 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

init

public void init()
          throws ResourcesException

This must be called to initialize the data content of this Resources instance, before any of the getXxx() methods are called.

Overrides:
init in class ResourcesBase
Throws:
ResourcesException - if an error occurs during initialization

destroy

public void destroy()
             throws ResourcesException

This method must be called when the manager of this resource decides that it's no longer needed. After this method is called, no further calls to any of the getXxx() methods are allowed.

Overrides:
destroy in class ResourcesBase
Throws:
ResourcesException - if an error occurs during finalization

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.

Overrides:
getKeys in class ResourcesBase
Returns:
The keys contained in this resources instance.

getObject

public Object getObject(String key,
                        Locale locale,
                        TimeZone timeZone)

Return the content for the specified key as an Object, localized based on the specified locale and/or timeZone.

Overrides:
getObject in class ResourcesBase
Parameters:
key - Identifier for the requested content
locale - Locale with which to localize retrieval, or null for the default Locale
timeZone - TimeZone with which to localize retrieval, or null for the default TimeZone
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,
                                   TimeZone timeZone)
                            throws MissingResourceException

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

The default implementation of this method unconditionally ignores the timeZone argument.

Parameters:
locale - Locale with which to localize retrieval, or null for the default Locale
timeZone - TimeZone with which to localize retrieval, or null for the default TimeZone
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 © 2002-2005 The Apache Software Foundation. All Rights Reserved.