com.townleyenterprises.common
Class ResourceManager

java.lang.Object
  extended bycom.townleyenterprises.common.OverrideManager
      extended bycom.townleyenterprises.common.ResourceManager
All Implemented Interfaces:
ResourceProvider

public class ResourceManager
extends OverrideManager
implements ResourceProvider

This class provides a way of managing resource hierarchies independent of the locale of a resource bundle. The default resolution strategy is an instance of UseLastOverrideStrategy which should "do the right thing" in almost all of the cases.

Version:
$Id: ResourceManager.java,v 1.2 2004/08/11 16:19:39 atownley Exp $
Author:
Andrew S. Townley

Constructor Summary
ResourceManager()
          This method sets up the default resolution strategy.
 
Method Summary
 void addProvider(ResourceProvider provider)
          This method is used to add a resource provider.
 java.lang.String format(java.lang.String key, java.util.Locale locale, java.lang.Object[] args)
          This method is used to format a given message located in the resource bundle.
 java.lang.String format(java.lang.String key, java.lang.Object[] args)
          This method is used to format a given message located in the resource bundle.
 javax.swing.ImageIcon getIcon(java.lang.String key)
          This method is used to retrieve the specified image icon for the default locale.
 javax.swing.ImageIcon getIcon(java.lang.String key, java.util.Locale locale)
          This method is used to retrieve the specified image icon for the specified locale.
protected  java.util.Collection getKeys(java.lang.Object object)
          This method is used to retrieve the property keys from the specified object.
static java.lang.String[] getResourceNames(java.lang.String base, java.util.Locale locale)
          This method is used to return the possible variants of a given base resource name for the given locale.
 java.lang.String getString(java.lang.String key)
          This method will return the value for the key or the key if the value does not exist.
 java.lang.String getString(java.lang.String key, java.util.Locale locale)
          This method is used to find a given resource string based on the specified locale.
protected  java.lang.Object getValue(java.lang.Object key, java.lang.Object object)
          This method is used to retrieve the value for the specific property key given the managed object.
 void manage(java.lang.Object object)
          This method keeps track of the objects managed so that the icons can be resolved in the right order.
 
Methods inherited from class com.townleyenterprises.common.OverrideManager
get, getKeys, getNode, resolve, setOverrideStrategy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.townleyenterprises.common.ResourceProvider
getKeys
 

Constructor Detail

ResourceManager

public ResourceManager()
This method sets up the default resolution strategy.

Method Detail

getResourceNames

public static java.lang.String[] getResourceNames(java.lang.String base,
                                                  java.util.Locale locale)
This method is used to return the possible variants of a given base resource name for the given locale.

Parameters:
base - the base name
locale - the locale
Returns:
an array of possible locations for the resource, in order of most specialized to least specialized.

getString

public java.lang.String getString(java.lang.String key)
This method will return the value for the key or the key if the value does not exist.

Specified by:
getString in interface ResourceProvider
Parameters:
key - the resource string key
Returns:
the string for the key

getString

public java.lang.String getString(java.lang.String key,
                                  java.util.Locale locale)
Description copied from interface: ResourceProvider
This method is used to find a given resource string based on the specified locale.

Specified by:
getString in interface ResourceProvider
Parameters:
key - the resource string key
locale - the locale
Returns:
the string for the key

getIcon

public javax.swing.ImageIcon getIcon(java.lang.String key)
Description copied from interface: ResourceProvider
This method is used to retrieve the specified image icon for the default locale.

Specified by:
getIcon in interface ResourceProvider
Parameters:
key - the key (usually the name) of the icon
Returns:
the appropriate ImageIcon

getIcon

public javax.swing.ImageIcon getIcon(java.lang.String key,
                                     java.util.Locale locale)
Description copied from interface: ResourceProvider
This method is used to retrieve the specified image icon for the specified locale.

Specified by:
getIcon in interface ResourceProvider
Parameters:
key - the key (usually the name) of the icon
locale - the locale
Returns:
the appropriate ImageIcon

manage

public void manage(java.lang.Object object)
This method keeps track of the objects managed so that the icons can be resolved in the right order.

Overrides:
manage in class OverrideManager
Parameters:
object - the object to manage

addProvider

public void addProvider(ResourceProvider provider)
This method is used to add a resource provider. It simply deferrs to the manage(java.lang.Object) method, but it provides some type checking.

Parameters:
provider - the ResourceProvider

format

public java.lang.String format(java.lang.String key,
                               java.util.Locale locale,
                               java.lang.Object[] args)
This method is used to format a given message located in the resource bundle. The message is first retrieved and then processed by an instance of the MessageFormat class.

Parameters:
key - the message key
locale - the locale
args - the format arguments

format

public java.lang.String format(java.lang.String key,
                               java.lang.Object[] args)
This method is used to format a given message located in the resource bundle. The message is first retrieved and then processed by an instance of the MessageFormat class.

Parameters:
key - the message key
args - the format arguments

getKeys

protected java.util.Collection getKeys(java.lang.Object object)
This method is used to retrieve the property keys from the specified object. The current assumption is that all objects managed by this class will at least conform to a common interface.

Specified by:
getKeys in class OverrideManager
Parameters:
object - the object to manage
Returns:
a collection of key values

getValue

protected java.lang.Object getValue(java.lang.Object key,
                                    java.lang.Object object)
This method is used to retrieve the value for the specific property key given the managed object.

Specified by:
getValue in class OverrideManager
Parameters:
key - the key to retrieve
object - the object to manipulate
Returns:
the value for the key


Copyright © 2002-2004, Andrew S. Townley and Townley Enterprises. All Rights Reserved.
This project is hosted on http://te-code.sourceforge.net.