Class BundleResourceLoader
- java.lang.Object
-
- net.sf.jguiraffe.resources.impl.bundle.BundleResourceLoader
-
- All Implemented Interfaces:
ResourceLoader
public class BundleResourceLoader extends Object implements ResourceLoader
A specialized implementation of the
ResourceLoader
interface that make use of the default Java resource bundles.This class uses the passed in
Locale
and resource group name (which is interpreted as string) to find a corresponding resource bundle. For this bundle a wrapping object is returned that implements theResourceGroup
interface.When creating an instance a
ClassLoaderProvider
and a class loader name can be provided. If set, the resource bundle is loaded using the class loader specified this way.- Version:
- $Id: BundleResourceLoader.java 211 2012-07-10 19:49:13Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description BundleResourceLoader()
Creates a new instance ofBundleResourceLoader
without a specialClassLoaderProvider
; a default one is created.BundleResourceLoader(ClassLoaderProvider clp, String clName)
Creates a new instance ofBundleResourceLoader
and initializes it with the given class loader provider and the class loader name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ResourceGroup
createGroup(String name, Locale locale)
Creates aResourceGroup
object from the specified bundle.String
getClassLoaderName()
Returns the name of the class loader used for resolving resource bundles.ClassLoaderProvider
getClassLoaderProvider()
Returns theClassLoaderProvider
used by this object.protected String
keyForGroup(Locale locale, Object name)
Constructs a key for the given combination of a locale and a group name.ResourceGroup
loadGroup(Locale locale, Object name)
Loads the specified resource group from a resource bundle.
-
-
-
Constructor Detail
-
BundleResourceLoader
public BundleResourceLoader()
Creates a new instance ofBundleResourceLoader
without a specialClassLoaderProvider
; a default one is created.
-
BundleResourceLoader
public BundleResourceLoader(ClassLoaderProvider clp, String clName)
Creates a new instance ofBundleResourceLoader
and initializes it with the given class loader provider and the class loader name.- Parameters:
clp
- theClassLoaderProvider
; can be null, then a default instance is createdclName
- the name of the class loader to use; can be null, then the default class loader of theClassLoaderProvider
is used- Since:
- 1.2
-
-
Method Detail
-
getClassLoaderProvider
public ClassLoaderProvider getClassLoaderProvider()
Returns theClassLoaderProvider
used by this object. Note: This method never returns null; if no class loader provider was passed to the constructor, a default instance is returned.- Returns:
- the
ClassLoaderProvider
- Since:
- 1.2
-
getClassLoaderName
public String getClassLoaderName()
Returns the name of the class loader used for resolving resource bundles.- Returns:
- the class loader name (may be null)
- Since:
- 1.2
-
loadGroup
public ResourceGroup loadGroup(Locale locale, Object name)
Loads the specified resource group from a resource bundle.- Specified by:
loadGroup
in interfaceResourceLoader
- Parameters:
locale
- theLocale
name
- the group's name- Returns:
- the found resource group
- Throws:
MissingResourceException
- if the group cannot be found
-
keyForGroup
protected String keyForGroup(Locale locale, Object name)
Constructs a key for the given combination of a locale and a group name. This key is used for storing a group in the cache after it was created.- Parameters:
locale
- the localename
- the group's name- Returns:
- a key for this group
-
createGroup
protected ResourceGroup createGroup(String name, Locale locale) throws MissingResourceException
Creates aResourceGroup
object from the specified bundle.- Parameters:
locale
- theLocale
name
- the group's name- Returns:
- the new resource group
- Throws:
MissingResourceException
- if the bundle cannot be found
-
-