Package ch.qos.cal10n
Class MessageConveyor
- java.lang.Object
-
- ch.qos.cal10n.MessageConveyor
-
- All Implemented Interfaces:
IMessageConveyor
public class MessageConveyor extends java.lang.Object implements IMessageConveyor
The default implementation forIMessageConveyor
based on resource bundles. See alsogetMessage(Enum, Object...)
for details.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<java.lang.String,CAL10NBundle>
cache
(package private) java.util.Locale
locale
-
Constructor Summary
Constructors Constructor Description MessageConveyor(java.util.Locale locale)
TheLocale
associated with this instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getMessage(MessageParameterObj mpo)
Syntactic sugar for the case where the massage is contained in aMessageParameterObj
.<E extends java.lang.Enum<?>>
java.lang.StringgetMessage(E key, java.lang.Object... args)
Given an enum as key, find the resource bundle corresponding to this locale and return the message corresponding to the key passed as parameter (internationalized per this locale).private <E extends java.lang.Enum<?>>
CAL10NBundlelookupResourceBundleByEnumClassAndLocale(java.lang.Class<E> declaringClass)
-
-
-
Field Detail
-
locale
final java.util.Locale locale
-
cache
final java.util.Map<java.lang.String,CAL10NBundle> cache
-
-
Method Detail
-
getMessage
public <E extends java.lang.Enum<?>> java.lang.String getMessage(E key, java.lang.Object... args) throws MessageConveyorException
Given an enum as key, find the resource bundle corresponding to this locale and return the message corresponding to the key passed as parameter (internationalized per this locale). The name of the resource bundle is defined via theBaseName
annotation whereas the locale is specified in this MessageConveyor instance's constructor.- Specified by:
getMessage
in interfaceIMessageConveyor
- Type Parameters:
E
- an enum type- Parameters:
key
- an enum instance used as message keyargs
- optional arguments- Returns:
- The translated/localized message
- Throws:
MessageConveyorException
-
lookupResourceBundleByEnumClassAndLocale
private <E extends java.lang.Enum<?>> CAL10NBundle lookupResourceBundleByEnumClassAndLocale(java.lang.Class<E> declaringClass) throws MessageConveyorException
- Throws:
MessageConveyorException
-
getMessage
public java.lang.String getMessage(MessageParameterObj mpo) throws MessageConveyorException
Description copied from interface:IMessageConveyor
Syntactic sugar for the case where the massage is contained in aMessageParameterObj
.Equivalent to calling
getMessage(mpo.getKey(), mpo.getArgs());
- Specified by:
getMessage
in interfaceIMessageConveyor
- Parameters:
mpo
- The MessageParameterObj to translate- Returns:
- translated message
- Throws:
MessageConveyorException
- See Also:
IMessageConveyor.getMessage(Enum, Object...)
-
-