com.tivoli.jflt
Class LogCatalogSupport

java.lang.Object
  |
  +--com.tivoli.jflt.LogCatalogSupport

public class LogCatalogSupport
extends java.lang.Object
implements LogCatalog

It provides an implemenation of the LogCatalog interface. LogCatalogSupport formats messages for the Java Flexible Logging Toolkit according to the current locale.

One way to define the messages is through a PropertyResourceBundle file, backed up by a Properties file. See the following example:


 # {0} is the name of a file.
 # {1} is the detailed error message created when the file is open
 ERR_FILE_OPEN=Unable to open file {0}: {1}
 

To configure a message catalog, pass it the base name of the resource bundle. For example, if your base file was com.mycompany.Msgs.properties you would write:


 LogCatalog catalog = new LogCatalogSupport();
 catalog.setMessageCatalog("com.mycompany.Msgs");
 

Version:
1.2
Author:
Cosimo Vampo, Raimondo Castino

Constructor Summary
LogCatalogSupport()
          Creates a LogCatalog.
 
Method Summary
 java.lang.String formatMessage(java.lang.String msg, java.lang.Object[] aobj)
          Formats a message by inserting an array of run-time objects into a pattern, according to the rules of the java.util.MessageFormat class.
 java.lang.String getMessage(java.lang.String key)
          Gets a message with no inserts from the catalog.
 java.lang.String getMessage(java.lang.String key, java.lang.Object obj)
          Gets a message with one insert from the catalog.
 java.lang.String getMessage(java.lang.String key, java.lang.Object[] objects)
          Gets a message with an array of inserts from the catalog.
 java.lang.String getMessage(java.lang.String key, java.lang.Object obj1, java.lang.Object obj2)
          Gets a message with two inserts from the catalog.
 java.lang.String getMessageCatalog()
          Gets the message catalog name.
 void setMessageCatalog(java.lang.String file)
          Sets the message catalog name for this catalog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogCatalogSupport

public LogCatalogSupport()
Creates a LogCatalog.
Method Detail

setMessageCatalog

public void setMessageCatalog(java.lang.String file)
Sets the message catalog name for this catalog. Usually this name is the base name of a resource bundle or the name of a file containing the messages in some specific format.
Specified by:
setMessageCatalog in interface LogCatalog
Parameters:
file - The base name of the ResourceBundle which contains the messages. If null, the current value is not changed.

getMessageCatalog

public java.lang.String getMessageCatalog()
Gets the message catalog name.
Specified by:
getMessageCatalog in interface LogCatalog
Returns:
The message catalog name for this catalog

getMessage

public java.lang.String getMessage(java.lang.String key)
Gets a message with no inserts from the catalog.
Specified by:
getMessage in interface LogCatalog
Parameters:
key - The key name of this message
Returns:
The formatted message from the catalog.

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.lang.Object obj)
Gets a message with one insert from the catalog.
Specified by:
getMessage in interface LogCatalog
Parameters:
key - The key name of this message
obj - An element to be inserted into the message
Returns:
The formatted message from the catalog.

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.lang.Object obj1,
                                   java.lang.Object obj2)
Gets a message with two inserts from the catalog.
Specified by:
getMessage in interface LogCatalog
Parameters:
key - The key name of this message
obj1 - An element to be inserted into the message
obj2 - An element to be inserted into the message
Returns:
The formatted message from the catalog.

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.lang.Object[] objects)
Gets a message with an array of inserts from the catalog.
Specified by:
getMessage in interface LogCatalog
Parameters:
key - The key name of this message
objects - An array of elements to be inserted into the message
Returns:
The formatted message from the catalog.

formatMessage

public java.lang.String formatMessage(java.lang.String msg,
                                      java.lang.Object[] aobj)
Formats a message by inserting an array of run-time objects into a pattern, according to the rules of the java.util.MessageFormat class.

The following code shows an example on how to use this method:


 LogCatalogSupport catalog = new LogCatalogSupport(MyResourceBundle);
 String my_msg = catalog.formatMessage("My name is {0}.", "Mimmo");
 
Parameters:
msg - The message pattern.
aobj - An array of elements to be inserted into the message.
Returns:
The formatted message.