Class RASMessageCatalog
- java.lang.Object
-
- com.ibm.ras.RASMessageCatalog
-
Deprecated.As of WAS 6.0, recommend using java.util.logging
public class RASMessageCatalog extends java.lang.ObjectRASMessageCatalogformats messages within the RAS system according to the current locale (that is, in the desired language). The text associated with any RAS message is kept in ajava.util.ResourceBundle. Each message text is associated with a "key," which is, essentially, a name for the message text.RASMessageCatalogformats the message text using ajava.text.MessageFormatobject. One way to define the messages is through aPropertyResourceBundlefile, backed up by aPropertiesfile. Here is a sample:# {0} is the name of a file. # {1} is the detailed message created when the file creation error # occurred ERR_FILE_WRITER=Unable to create a FileWriter for {0}: {1} # {0} is a text string naming the missing message key. ERR_MISSING_KEY=Message key {0} was not found in any searched catalog. ERR_SOCKET=Unable to connect to the RAS Log Server.To create a message catalog, pass it the base name of the resource bundle. For example, if your base file wascom.ibm.ras.RASMsgs.propertiesyou would code:RASMessageCatalog msgCat = new RASMessageCatalog("com.ibm.ras.RASMsgs");Use theRASMessageCatalog.getMessagemethods to retrieve the message text in the desired locale. Java will look for the proper translation of this file according to the supplied or default locale. For example, it might first search forRASMsgs_en_GB.properties, thenRASMsgs_en.propertiesand, finallyRASMsgs.properties.RASMessageCatalogprovides a debug mode, which makes it easy to determine if messages are retrieved from locale-specific resource bundles. When debug mode is enabled throughsetDebug, messages returned from aRASMessageCatalogare enclosed in square brackets ("[ ]").By default, debug mode is disabled. In addition to
setDebug, the debug mode may be altered by creating a file,RASMessageCatalog/catalog.propertiesand placing it in the root of any directory in your Java CLASSPATH. For applets, it may also be placed in a JAR or CAB file. To enable debug mode, this properties file must contain the propertydebug=true. The propertydebug=falsewill disable debug mode.When used as part of the RAS Toolkit, it is not necessary for an application to create a
RASMessageCatalog. If national language support is required elsewhere,RASMessageCatalogprovides many useful features.
-
-
Constructor Summary
Constructors Constructor and Description RASMessageCatalog(java.util.ResourceBundle bundle)Deprecated.Creates aRASMessageCatalog.RASMessageCatalog(java.util.ResourceBundle bundle, java.util.Locale loc)Deprecated.Creates aRASMessageCatalog.RASMessageCatalog(java.lang.String baseName)Deprecated.Creates aRASMessageCatalogusing the default locale.RASMessageCatalog(java.lang.String baseName, java.util.Locale loc)Deprecated.Creates aRASMessageCatalog.
-
Method Summary
Methods Modifier and Type Method and Description chargetChar(java.lang.String key)Deprecated.Gets the first character of a message.java.util.LocalegetLocale()Deprecated.Gets the locale used by theRASMessageCatalog.java.lang.StringgetMessage(java.lang.String key)Deprecated.Gets a message with no inserts from the catalog.java.lang.StringgetMessage(java.lang.String key, java.lang.Object insert1)Deprecated.Gets a message with one insert from the catalog.java.lang.StringgetMessage(java.lang.String key, java.lang.Object[] inserts)Deprecated.Gets a message with an array of inserts from the catalog.java.lang.StringgetMessage(java.lang.String key, java.lang.Object insert1, java.lang.Object insert2)Deprecated.Gets a message with two inserts from the catalog.java.lang.StringgetMsg(java.lang.String key, java.lang.Object[] inserts)Deprecated.Gets a message with an array of inserts from the catalog.booleanisDebug()Deprecated.Determines if theRASMessageCatalogis in debug mode.voidsetDebug(boolean flag)Deprecated.Sets theRASMessageCatalogdebug mode.voidsetLocale(java.util.Locale loc)Deprecated.Sets the locale to be used by theRASMessageCatalog.
-
-
-
Constructor Detail
-
RASMessageCatalog
public RASMessageCatalog(java.lang.String baseName) throws java.util.MissingResourceExceptionDeprecated.Creates aRASMessageCatalogusing the default locale.- Parameters:
baseName- The base name of theResourceBundlewhich contains the messages.- Throws:
java.util.MissingResourceException- This exception is thrown if theResourceBundlecannot be loaded.
-
RASMessageCatalog
public RASMessageCatalog(java.lang.String baseName, java.util.Locale loc) throws java.util.MissingResourceExceptionDeprecated.Creates aRASMessageCatalog.- Parameters:
baseName- The base name of theResourceBundlewhich contains the messages.loc- The locale with which the messages should be displayed.- Throws:
java.util.MissingResourceException- This exception is thrown if theResourceBundlecannot be loaded.
-
RASMessageCatalog
public RASMessageCatalog(java.util.ResourceBundle bundle)
Deprecated.Creates aRASMessageCatalog.- Parameters:
bundle- TheResourceBundlewhich contains the messages.
-
RASMessageCatalog
public RASMessageCatalog(java.util.ResourceBundle bundle, java.util.Locale loc)Deprecated.Creates aRASMessageCatalog.Note: Use of this constructor may cause unexpected behavior if the locale of the
ResourceBundleis not the same as the locale parameter.- Parameters:
bundle- TheResourceBundlewhich contains the messages.loc- The locale with which the messages should be displayed.
-
-
Method Detail
-
getLocale
public java.util.Locale getLocale()
Deprecated.Gets the locale used by theRASMessageCatalog.- Returns:
- The message catalog locale. If a locale has not been set, the
default
Locale.getDefaultis returned.
-
setLocale
public void setLocale(java.util.Locale loc)
Deprecated.Sets the locale to be used by theRASMessageCatalog.Note: Use of this method may cause unexpected behavior if the
RASMessageCatalogwas created with one of the constructors that takes aResourceBundleas a parameter. In this case, theRASMessageCatalogcannot recreate theResourceBundlein the new locale.- Parameters:
loc- The new locale. If this locale isnull, the current locale is not changed.
-
isDebug
public boolean isDebug()
Deprecated.Determines if theRASMessageCatalogis in debug mode. In debug mode, messages retrieved viagetMessageorgetMsgare enclosed in brackets, "[This is a test]," for example. This makes it easy to identify those messages which do not come from locale-specific message bundles.By default, debug mode is disabled.
- Returns:
trueif debug mode is enabled, orfalseotherwise.
-
setDebug
public void setDebug(boolean flag)
Deprecated.Sets theRASMessageCatalogdebug mode. In debug mode, messages retrieved viagetMessageorgetMsgare enclosed in brackets, "[This is a test]," for example. This makes it easy to identify those messages which do not come from locale-specific message bundles.By default, debug mode is disabled.
- Parameters:
flag-trueto enable debug mode, orfalseotherwise.
-
getMessage
public java.lang.String getMessage(java.lang.String key) throws java.util.MissingResourceExceptionDeprecated.Gets a message with no inserts from the catalog.- Parameters:
key- The key name of this message.- Returns:
- The formatted message from the catalog.
- Throws:
java.util.MissingResourceException- This exception is thrown if a message with the given key cannot be found in the message catalog.
-
getMessage
public java.lang.String getMessage(java.lang.String key, java.lang.Object insert1) throws java.util.MissingResourceExceptionDeprecated.Gets a message with one insert from the catalog.- Parameters:
key- The key name of this message.insert1- An element to be inserted into the message.- Returns:
- The formatted message from the catalog.
- Throws:
java.util.MissingResourceException- This exception is thrown if a message with the given key cannot be found in the message catalog.
-
getMessage
public java.lang.String getMessage(java.lang.String key, java.lang.Object insert1, java.lang.Object insert2) throws java.util.MissingResourceExceptionDeprecated.Gets a message with two inserts from the catalog.- Parameters:
key- The key name of this message.insert1- An element to be inserted into the message.insert2- An element to be inserted into the message.- Returns:
- The formatted message from the catalog.
- Throws:
java.util.MissingResourceException- This exception is thrown if a message with the given key cannot be found in the message catalog.
-
getMessage
public java.lang.String getMessage(java.lang.String key, java.lang.Object[] inserts) throws java.util.MissingResourceExceptionDeprecated.Gets a message with an array of inserts from the catalog.- Parameters:
key- The key name of this message.inserts- An array of elements to be inserted into the message.- Returns:
- The formatted message from the catalog.
- Throws:
java.util.MissingResourceException- This exception is thrown if a message with the given key cannot be found in the message catalog.
-
getMsg
public java.lang.String getMsg(java.lang.String key, java.lang.Object[] inserts)Deprecated.Gets a message with an array of inserts from the catalog. This convenience method returns an error message if the requested key was not found in this catalog. No exception is thrown.- Parameters:
key- The key name of this message.inserts- An array of elements to be inserted into the message.- Returns:
- The formatted message from the catalog.
-
getChar
public char getChar(java.lang.String key)
Deprecated.Gets the first character of a message. This method is used to retrieve a character to be used as a mnemonic in a Swing user interface. (This is the underlined character which activates a button, for example, when you press Alt-character.)Typically, one would define two strings in a message file. For example:
CANCEL=Cancel CANCEL_MNEMONIC=a
The first string is the label to go on a button. The second is the mnemonic character. The methodgetMessage("CANCEL")will return the button label, whilegetChar("CANCEL_MNEMONIC")will return the mnemonic character.- Parameters:
key- The key name of the message.- Returns:
- The mnemonic character.
- Throws:
java.util.MissingResourceException- This exception is thrown if a message with the given key cannot be found in the message catalog.
-
-