net.sf.clirr.core
Class MessageTranslator

java.lang.Object
  extended by net.sf.clirr.core.MessageTranslator

public final class MessageTranslator
extends java.lang.Object

Class which is capable of translating a Message object into a localised string.


Field Summary
static java.lang.String DFLT_RESOURCE_NAME
          The default base name of the resource bundle from which message descriptions are read.
 
Constructor Summary
MessageTranslator()
          This is a singleton class; to get an instance of this class, use the getInstance method.
 
Method Summary
 void checkComplete(java.util.Collection messages)
          Verify that the resource bundle for the currently set locale has a translation string available for every message object in the provided collection.
 java.lang.String getDesc(Message msg)
          Given a Message object (containing a unique message id), look up that id in the appropriate resource bundle (properties file) for the set locale and return the text string associated with that message id.
 void setLocale(java.util.Locale locale)
          Define the local language etc.
 void setResourceName(java.lang.String resourceName)
          Define the base name of the properties file that message translations are to be read from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DFLT_RESOURCE_NAME

public static final java.lang.String DFLT_RESOURCE_NAME
The default base name of the resource bundle from which message descriptions are read.

Constructor Detail

MessageTranslator

public MessageTranslator()
This is a singleton class; to get an instance of this class, use the getInstance method.

Method Detail

setLocale

public void setLocale(java.util.Locale locale)
Define the local language etc. Future calls to the getDesc method will attempt to use a properties file which is appropriate to that locale to look the message descriptions up in.

Parameters:
locale - may be a valid Locale object, or null to indicate that the default locale is to be used.

setResourceName

public void setResourceName(java.lang.String resourceName)
Define the base name of the properties file that message translations are to be read from.


checkComplete

public void checkComplete(java.util.Collection messages)
Verify that the resource bundle for the currently set locale has a translation string available for every message object in the provided collection. This method is expected to be called from the unit tests, so that if a developer adds a new message the unit tests will fail until translations are also available for that new message.

Throws:
java.util.MissingResourceException - if there is a registered message for which no description is present in the current locale's resources.

getDesc

public java.lang.String getDesc(Message msg)
Given a Message object (containing a unique message id), look up that id in the appropriate resource bundle (properties file) for the set locale and return the text string associated with that message id.

Message ids in the properties file should be prefixed with an 'm', eg "m1000", "m5003".

Throws:
java.util.MissingResourceException - if there is no entry in the message translation resource bundle for the specified message.


Copyright © 2003-2005 Lars Kühne. All Rights Reserved.