net.lessy.util.resource
Class ResourceManager

java.lang.Object
  extended by net.lessy.util.resource.ResourceManager
All Implemented Interfaces:
MessageResolver

public class ResourceManager
extends Object
implements MessageResolver

Convenient Manager around a resource bundle. This class is a pseudo singleton. You can create more then one instance but only the last created instance can be retrieved with the getInstance-Method.

If you have only one bundle, then call the constructor once and pass the bundlename to it. From there you can always get a reference to the manager with the static getInstance-Method.

The manager can be configured through Spring by just adding it as a bean and configuring the bundlename as a constructor parameter.

Author:
Hans Lesmeister

Constructor Summary
ResourceManager(String bundleName)
          Constructor
 
Method Summary
 MessageBean createMessageBean(String key, Object... insets)
           
 String getBundleName()
          Name of the resource bundle
static ResourceManager getInstance()
          Get the one and only singleton instance.
 String getString(MessageHolder messageBean)
          Gets a string from the resource bundle.
 String getString(String key, Object... insets)
          Gets a String by it's key
 void setBundleName(String bundleName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceManager

public ResourceManager(String bundleName)
Constructor

Parameters:
bundleName - fully qualified resource name, i.e. "net.lessy.res.Resource" (without extension .properties)
Method Detail

getInstance

public static ResourceManager getInstance()
Get the one and only singleton instance.

Returns:
The instance or null if no instance exists

createMessageBean

public MessageBean createMessageBean(String key,
                                     Object... insets)

getString

public String getString(String key,
                        Object... insets)
Gets a String by it's key

Specified by:
getString in interface MessageResolver
Parameters:
key - Key of the resource string
insets - optional insets
Returns:
String from the resource. If the string can not be determined, then the key as such is returned

getString

public String getString(MessageHolder messageBean)
Gets a string from the resource bundle. The resource key and insets are taken from the passed bean

Parameters:
messageBean -
Returns:
String or null if the bean is null

getBundleName

public String getBundleName()
Name of the resource bundle

Returns:
Name which was originally passed to the constructor

setBundleName

public void setBundleName(String bundleName)


Copyright © 2012. All Rights Reserved.