| Interface identifying instances capable of being localized
using a ScarabLocalizationTool instance.
In order to localize throwables, one could reuse the following pattern:
public class MyLocalizedThrowable extends MyThrowableClass implements Localizable
{
// may be null
private ScarabLocalizationTool localizer;
// Set the localizer to be used in later calls to
Localizable.getLocalizedMessage() // @param theLocalizer the localizer (may be null )
public void setLocalizer(final ScarabLocalizationTool theLocalizer)
{
localizer = theLocalizer;
}
// Return the localized message for that throwable, if a localizer
// was defined using
Localizable.setLocalizer(ScarabLocalizationTool) // @return the localized message.
public String getLocalizedMessage()
{
// we effectively implement an IoC pattern, made necessary by
// the design of the Throwable base class
if (localizer != null)
{
return toString(localizer);
}
else
{
return super.getLocalizedMessage();
}
}
}
This should be particularly thought when one subclasses instances from a
different framework, because that framework may be or may become localized
one day.
version: $Id: Localizable.java 9104 2004-05-10 21:04:51Z dabbous $ author: Hussayn Dabbous |