com.ge.research.app
Class ResourceDiscoveryUtil

java.lang.Object
  extended bycom.ge.research.app.ResourceDiscoveryUtil

public abstract class ResourceDiscoveryUtil
extends java.lang.Object

This abstract class provides utility methods and behaviors for finding and loading resources for a class. For unqualified resources it implements the desired search order of the class's default resource directory, then the classpath root directory. For all resources loaded, the locale specific resource name is identified for each property within the resource.

Version:
$Revision: 1.2 $ $Date: 2006/09/12 13:24:50 $
Author:
garbiras
Created on:
June 12, 2006

Field Summary
static java.lang.String PACKAGE_DELIMITER
          Constant for the delimiter for package name syntax
static java.lang.String RESOURCES_DIRNAME
          Constant for the best practice package name for the location of resources and properties
 
Constructor Summary
ResourceDiscoveryUtil()
           
 
Method Summary
static java.lang.String getClassUnqualifiedName(java.lang.Class c)
          Constructs the resource path string for the given class.
static java.lang.String getResourcePackage(java.lang.Class c)
          Constructs the resource path string for the given class.
static void loadClassResources(java.lang.Class theClass, java.util.Properties props, java.lang.String bundleName, LocaleNegotiator localeNegotiator)
          Attempts to load in properties found in a resource bundle specified by bundleName.
static java.util.Map loadClassResources(java.lang.Class theClass, java.util.Properties props, java.lang.String bundleName, LocaleNegotiator localeNegotiator, boolean createKeysToBundleMap)
          Attempts to load in properties found in a resource bundle specified by bundleName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PACKAGE_DELIMITER

public static final java.lang.String PACKAGE_DELIMITER
Constant for the delimiter for package name syntax

See Also:
Constant Field Values

RESOURCES_DIRNAME

public static final java.lang.String RESOURCES_DIRNAME
Constant for the best practice package name for the location of resources and properties

See Also:
Constant Field Values
Constructor Detail

ResourceDiscoveryUtil

public ResourceDiscoveryUtil()
Method Detail

getResourcePackage

public static java.lang.String getResourcePackage(java.lang.Class c)
Constructs the resource path string for the given class. A class's resource path is defined as the class's package appended with RESOURCES_DIRNAME

Parameters:
c - the class to construct the resource package for
Returns:
the resource package for the class; the empty string if the class is null.

getClassUnqualifiedName

public static java.lang.String getClassUnqualifiedName(java.lang.Class c)
Constructs the resource path string for the given class. A class's resource path is defined as the class's package appended with RESOURCES_DIRNAME

Parameters:
c - the class to construct the resource package for
Returns:
the resource package for the class; the empty string if the class is null.

loadClassResources

public static final void loadClassResources(java.lang.Class theClass,
                                            java.util.Properties props,
                                            java.lang.String bundleName,
                                            LocaleNegotiator localeNegotiator)
Attempts to load in properties found in a resource bundle specified by bundleName. It first tries to load the bundleName resource by appending the current class's resource package name (com.ge.research.app.ResourceDiscoveryUtil#THIS_CLASS_RESOURCES_PACKAGE) to the bundleName. If such a resource is found, the properties are copied into a new Properties object. Then attempts to load in properties found for the baseName as a resource (unmodified). If such a resource is found, the properties are copied into the Properties object. if a resource is found in both steps, properties within the unmodified baseName resource override any other matching properties found elsewhere. A Map pairing the property names found to locale specific resources they were found in is returned by this method.

Parameters:
props - the Properties object in which to put the resource properties found
bundleName - the name of the resource to load
localeNegotiator - the locale resolution class to use
Returns:
A Map of each property found to the locale specific resource it was found in
See Also:
com.ge.research.app.ResourceDiscoveryUtil#loadClassResources(java.util.Properties, java.lang.String, com.ge.research.app.LocaleNegotiator, java.util.logging.Level)

loadClassResources

public static final java.util.Map loadClassResources(java.lang.Class theClass,
                                                     java.util.Properties props,
                                                     java.lang.String bundleName,
                                                     LocaleNegotiator localeNegotiator,
                                                     boolean createKeysToBundleMap)
Attempts to load in properties found in a resource bundle specified by bundleName. It first tries to load the bundleName resource by appending the current class's resource package name (com.ge.research.app.ResourceDiscoveryUtil#THIS_CLASS_RESOURCES_PACKAGE) to the bundleName. If such a resource is found, the properties are copied into a new Properties object. Then attempts to load in properties found for the baseName as a resource (unmodified). If such a resource is found, the properties are copied into the Properties object. if a resource is found in both steps, properties within the unmodified baseName resource override any other matching properties found elsewhere. A Map pairing the property names found to locale specific resources they were found in is returned by this method.

Parameters:
props - the Properties object in which to put the resource properties found
bundleName - the name of the resource to load
localeNegotiator - the locale resolution class to use
Returns:
A Map of each property found to the locale specific resource it was found in
See Also:
com.ge.research.app.ResourceDiscoveryUtil#loadClassResources(java.util.Properties, java.lang.String, com.ge.research.app.LocaleNegotiator, java.util.logging.Level)