org.marketcetera.util.log
Class I18NMessageProvider

java.lang.Object
  extended by org.marketcetera.util.log.I18NMessageProvider
All Implemented Interfaces:
Serializable

public class I18NMessageProvider
extends Object
implements Serializable

An internationalized message provider, mapping instances of I18NMessage onto text. The locale used for the translation is either one supplied at the time of translation, or the active locale per ActiveLocale; if the chosen locale does not provide a message, the default JVM locale and root locale (in that order) are used as fallbacks.

Message providers can be serialized. However, upon deserialization, they are not guaranteed to have the same classloader as during serialization, and hence may be unable to access the same message files as were available during serialization. If this happens, deserialization will fail.

Since:
0.5.0
Version:
$Id: I18NMessageProvider.java 16154 2012-07-14 16:34:05Z colin $
Author:
tlerios@marketcetera.com
See Also:
Serialized Form

Field Summary
static String MESSAGE_FILE_EXTENSION
          The string added to the end of the provider ID to obtain the stream resource (file) containing the message mappings.
 
Constructor Summary
I18NMessageProvider(String providerId)
          Creates a new message provider with the given ID.
I18NMessageProvider(String providerId, ClassLoader classLoader)
          Creates a new message provider with the given ID.
 
Method Summary
 boolean equals(Object other)
           
 String getProviderId()
          Returns the receiver's provider ID.
 String getText(I18NMessage message, Object... params)
          Returns the text of the given message in the active locale per ActiveLocale.
 String getText(Locale locale, I18NMessage message, Object... params)
          Returns the text of the given message in the given locale, using the receiver's map.
 int hashCode()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_FILE_EXTENSION

public static final String MESSAGE_FILE_EXTENSION
The string added to the end of the provider ID to obtain the stream resource (file) containing the message mappings.

See Also:
Constant Field Values
Constructor Detail

I18NMessageProvider

public I18NMessageProvider(String providerId,
                           ClassLoader classLoader)
Creates a new message provider with the given ID. The provider ID is combined with the suffix MESSAGE_FILE_EXTENSION to form the name of a mapping file. The file should be retrievable as a resource via the given class loader, and its format should be that used by Apache Commons i18n.

Parameters:
providerId - The provider ID.
classLoader - The class loader used to load the mapping file. It may be null to use the default classloader.

I18NMessageProvider

public I18NMessageProvider(String providerId)
Creates a new message provider with the given ID. The provider ID is combined with the suffix MESSAGE_FILE_EXTENSION to form the name of a mapping file. The file should be retrievable as a resource via the default class loader, and its format should be that used by Apache Commons i18n.

Parameters:
providerId - The provider ID.
Method Detail

getProviderId

public String getProviderId()
Returns the receiver's provider ID.

Returns:
The ID.

getText

public String getText(Locale locale,
                      I18NMessage message,
                      Object... params)
Returns the text of the given message in the given locale, using the receiver's map. The given parameters are used to instantiate parameterized messages.

Parameters:
locale - The locale.
message - The message.
params - The message parameters.
Returns:
Returns the text. If the message cannot be found, an error is logged, and a simple form of the message comprising its IDs and parameters is returned.

getText

public String getText(I18NMessage message,
                      Object... params)
Returns the text of the given message in the active locale per ActiveLocale. The given parameters are used to instantiate parameterized messages.

Parameters:
message - The message.
params - The message parameters.
Returns:
Returns the text. If the message cannot be found, an error is logged, and a simple form of the message comprising its IDs and parameters is returned.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object


Copyright © 2012. All Rights Reserved.