com.ge.research.app
Class LocaleNegotiator

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

public class LocaleNegotiator
extends java.lang.Object

This class is used to manage the discovery and loading of locale specific resources, based upon the supplied preferences of a single Locale to use or an ordered Enumeration of preferred Locales to use. If the LocaleNegotiator is constructed with an Enumeration of Locale objects, when loading resources, it attempts to find the best match of available resources based upon all of the specified Locales, with regard to their specified relative preferences.

Version:
$Revision: 1.1 $ $Date: 2006/08/11 00:17:42 $
Author:
garbiras
Created on:
June 6, 2006

Field Summary
protected  java.util.logging.Logger logger
          Logging utility for this class
 
Constructor Summary
LocaleNegotiator()
          Constructs a LocaleNegotiator object for the JVM default Locale and the ClassLoader of this class.
LocaleNegotiator(java.util.Enumeration locales)
          Constructs a LocaleNegotiator object for the specified Locales within the Enumeration and the ClassLoader of this class.
LocaleNegotiator(java.util.Locale locale)
          Constructs a LocaleNegotiator object for the specified Locale and the ClassLoader of this class.
 
Method Summary
 boolean equals(java.lang.Object o)
          A LocaleNegotiator is considered equal to another LocaleNegotiator if the com.ge.research.app.LocaleNegotiator#locales property are the same Enumeration of Locales.
protected  java.util.Locale getLocale()
          Returns the Locale to use to find and load resources.
protected  java.util.Enumeration getLocales()
          Returns the ordered set of preferred Locales to use to find and load resources
 java.util.ResourceBundle getResourceBundle(java.lang.String baseName)
          Attempts to find the best match of a locale specific resource for argument baseName given the preferred Locales specified in the com.ge.research.app.LocaleNegotiator#locales property or by the com.ge.research.app.LocaleNegotiator#locale property.
protected  int scoreMatch(java.util.Locale locale1, java.util.Locale locale2)
          Compares two Locale objects to each other and generates a score representing their similarity.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Sets the ClassLoader to use when attempting to find and load resource bundles.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final java.util.logging.Logger logger
Logging utility for this class

Constructor Detail

LocaleNegotiator

public LocaleNegotiator()
Constructs a LocaleNegotiator object for the JVM default Locale and the ClassLoader of this class.

See Also:
setClassLoader(java.lang.ClassLoader)

LocaleNegotiator

public LocaleNegotiator(java.util.Locale locale)
Constructs a LocaleNegotiator object for the specified Locale and the ClassLoader of this class.

See Also:
LocaleNegotiator()

LocaleNegotiator

public LocaleNegotiator(java.util.Enumeration locales)
Constructs a LocaleNegotiator object for the specified Locales within the Enumeration and the ClassLoader of this class.

See Also:
LocaleNegotiator()
Method Detail

equals

public boolean equals(java.lang.Object o)
A LocaleNegotiator is considered equal to another LocaleNegotiator if the com.ge.research.app.LocaleNegotiator#locales property are the same Enumeration of Locales. Or if both locales properties are null then the objects are equivalent if their com.ge.research.app.LocaleNegotiator#locale properties are equal.


getResourceBundle

public java.util.ResourceBundle getResourceBundle(java.lang.String baseName)
                                           throws java.lang.IllegalArgumentException,
                                                  java.util.MissingResourceException
Attempts to find the best match of a locale specific resource for argument baseName given the preferred Locales specified in the com.ge.research.app.LocaleNegotiator#locales property or by the com.ge.research.app.LocaleNegotiator#locale property.

Parameters:
baseName - the base name (without locale information) of the resource to find the locale specific instance of
Returns:
the locale specific instance of the resource specified by the argument baseName. The locale specific instance is resolved by the procedure defined by ResourceBundle.getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader)
Throws:
java.lang.IllegalArgumentException - if the baseName argument is null or the empty string
java.util.MissingResourceException - if no resource bundle for the argument baseName can be found using the procedure for resolving locale specific resources set forth by ResourceBundle.getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader)
See Also:
ResourceBundle.getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader)

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Sets the ClassLoader to use when attempting to find and load resource bundles. If ClassLoader is null then the ClassLoader of this class is used by default.

Parameters:
classLoader - the ClassLoader to use when loading resource bundles

getLocale

protected final java.util.Locale getLocale()
Returns the Locale to use to find and load resources. If the com.ge.research.app.LocaleNegotiator#locales property is set, the com.ge.research.app.LocaleNegotiator#locale property is meaningless.

Returns:
the Locale to use to find and load resources, unless the locales property is set.

getLocales

protected final java.util.Enumeration getLocales()
Returns the ordered set of preferred Locales to use to find and load resources

Returns:
the ordered set of preferred Locales to use to find and load resources

scoreMatch

protected final int scoreMatch(java.util.Locale locale1,
                               java.util.Locale locale2)
Compares two Locale objects to each other and generates a score representing their similarity. A score of 0 indicates they share no properties; A score of 1 indicates they share the same language component; A score of 2 indicates they share the same language and country component; A score of 3 indicates they share the same language, country, and variant components and are thus fully equivalent.

Parameters:
locale1 - the first Locale object to compare
locale2 - the second Locale object to compare
Returns:
a score (0-3) indicating the similarity of the two locales