Package org.marketcetera.util.log
Class I18NMessageProvider
- java.lang.Object
-
- org.marketcetera.util.log.I18NMessageProvider
-
- All Implemented Interfaces:
Serializable
public class I18NMessageProvider extends Object implements Serializable
An internationalized message provider, mapping instances ofI18NMessageonto text. The locale used for the translation is either one supplied at the time of translation, or the active locale perActiveLocale; 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
Fields Modifier and Type Field Description private static StringCORRUPTED_STOREstatic StringMESSAGE_FILE_EXTENSIONThe string added to the end of the provider ID to obtain the stream resource (file) containing the message mappings.private static StringMESSAGE_FILE_NOT_FOUNDprivate static StringMESSAGE_NOT_FOUNDprivate StringmProviderIdprivate static longserialVersionUIDprivate static StringUNEXPECTED_EXCEPTION_CONTEXTprivate static StringUNEXPECTED_EXCEPTION_TRACE
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)private StringgetBaseName()Returns the receiver's base name.StringgetProviderId()Returns the receiver's provider ID.StringgetText(Locale locale, I18NMessage message, Object... params)Returns the text of the given message in the given locale, using the receiver's map.StringgetText(I18NMessage message, Object... params)Returns the text of the given message in the active locale perActiveLocale.inthashCode()private voidinit(ClassLoader classLoader)Initializes the receiver.private voidreadObject(ObjectInputStream in)Java deserialization.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
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
-
MESSAGE_FILE_NOT_FOUND
private static final String MESSAGE_FILE_NOT_FOUND
- See Also:
- Constant Field Values
-
MESSAGE_NOT_FOUND
private static final String MESSAGE_NOT_FOUND
- See Also:
- Constant Field Values
-
UNEXPECTED_EXCEPTION_CONTEXT
private static final String UNEXPECTED_EXCEPTION_CONTEXT
- See Also:
- Constant Field Values
-
UNEXPECTED_EXCEPTION_TRACE
private static final String UNEXPECTED_EXCEPTION_TRACE
- See Also:
- Constant Field Values
-
CORRUPTED_STORE
private static final String CORRUPTED_STORE
- See Also:
- Constant Field Values
-
mProviderId
private String mProviderId
-
-
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 suffixMESSAGE_FILE_EXTENSIONto 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 suffixMESSAGE_FILE_EXTENSIONto 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
-
init
private void init(ClassLoader classLoader) throws MessageNotFoundException
Initializes the receiver.- Parameters:
classLoader- The class loader used to load the mapping file. It may be null to use the default classloader.- Throws:
MessageNotFoundException- Thrown if initialization fails.
-
getProviderId
public String getProviderId()
Returns the receiver's provider ID.- Returns:
- The ID.
-
getBaseName
private String getBaseName()
Returns the receiver's base name.- Returns:
- The base name.
-
readObject
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
Java deserialization. Reads a receiver instance from the given stream.- Parameters:
in- The stream.- Throws:
IOException- Per serialization spec.ClassNotFoundException- Per serialization spec.
-
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 perActiveLocale. 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.
-
-