APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.org.apache.xml.internal.serializer.utils

public final Class Messages

extends Object
Class Inheritance
Imports
java.util.Locale, .ResourceBundle, jdk.xml.internal.SecuritySupport

A utility class for issuing error messages. A user of this class normally would create a singleton instance of this class, passing the name of the message class on the constructor. For example: static Messages x = new Messages("org.package.MyMessages"); Later the message is typically generated this way if there are no substitution arguments: String msg = x.createMessage(org.package.MyMessages.KEY_ONE, null); If there are arguments substitutions then something like this: String filename = ...; String directory = ...; String msg = x.createMessage(org.package.MyMessages.KEY_TWO, new Object[] {filename, directory) ); The constructor of an instance of this class must be given the class name of a class that extends java.util.ListResourceBundle ("org.package.MyMessages" in the example above). The name should not have any language suffix which will be added automatically by this utility class. The message class ("org.package.MyMessages") must define the abstract method getContents() that is declared in its base class, for example: public Object[][] getContents() {return contents;} It is suggested that the message class expose its message keys like this: public static final String KEY_ONE = "KEY1"; public static final String KEY_TWO = "KEY2"; . . . and used through their names (KEY_ONE ...) rather than their values ("KEY1" ...). The field contents (returned by getContents() should be initialized something like this: public static final Object[][] contents = { { KEY_ONE, "Something has gone wrong!" }, { KEY_TWO, "The file ''{0}'' does not exist in directory ''{1}''." }, . . . { KEY_N, "Message N" } } Where that section of code with the KEY to Message mappings (where the message classes 'contents' field is initialized) can have the Message strings translated in an alternate language in a errorResourceClass with a language suffix. This class is not a public API, it is only public because it is used in com.sun.org.apache.xml.internal.serializer.

Field Summary

Modifier and TypeField and Description
private final Locale
m_locale

The local object to use.

private ResourceBundle
m_resourceBundle

The language specific resource object for messages.

private String
m_resourceBundleName

The class name of the error message string table with no language suffix.

Constructor Summary

AccessConstructor and Description
pack-priv
Messages(String
the class name of the ListResourceBundle that the instance of this class is associated with and will use when creating messages. The class name is without a language suffix. If the value passed is null then loadResourceBundle(errorResourceClass) needs to be called explicitly before any messages are created.
resourceBundle
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public final String

Returns:

The formatted message string.
createMessage
(String
The key for the message text.
msgKey
,
Object[]
The arguments to be used as replacement text in the message created.
args
)

Creates a message from the specified key and replacement arguments, localized to the given locale.

private final String

Returns:

The formatted message string.
createMsg
(ResourceBundle
The resource bundle to use.
fResourceBundle
,
String
The message key to use.
msgKey
,
Object[]
The arguments to be used as replacement text in the message created.
args
)

Creates a message from the specified key and replacement arguments, localized to the given locale.

private Locale

Returns:

non-null reference to Locale object.
getLocale
()

Get the Locale object that is being used.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

m_localeback to summary
private final Locale m_locale

The local object to use.

m_resourceBundleback to summary
private ResourceBundle m_resourceBundle

The language specific resource object for messages.

m_resourceBundleNameback to summary
private String m_resourceBundleName

The class name of the error message string table with no language suffix.

Constructor Detail

Messagesback to summary
pack-priv Messages(String resourceBundle)

Constructor.

Parameters
resourceBundle:String

the class name of the ListResourceBundle that the instance of this class is associated with and will use when creating messages. The class name is without a language suffix. If the value passed is null then loadResourceBundle(errorResourceClass) needs to be called explicitly before any messages are created.

Method Detail

createMessageback to summary
public final String createMessage(String msgKey, Object[] args)

Creates a message from the specified key and replacement arguments, localized to the given locale.

Parameters
msgKey:String

The key for the message text.

args:Object[]

The arguments to be used as replacement text in the message created.

Returns:String

The formatted message string.

createMsgback to summary
private final String createMsg(ResourceBundle fResourceBundle, String msgKey, Object[] args)

Creates a message from the specified key and replacement arguments, localized to the given locale.

Parameters
fResourceBundle:ResourceBundle

The resource bundle to use.

msgKey:String

The message key to use.

args:Object[]

The arguments to be used as replacement text in the message created.

Returns:String

The formatted message string.

getLocaleback to summary
private Locale getLocale()

Get the Locale object that is being used.

Returns:Locale

non-null reference to Locale object.