Top Description Fields Constructors Methods
org.apache.derby.shared.common.i18n

public Class MessageUtil

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.error.ExceptionSeverity, org.apache.derby.shared.common.sanity.SanityManager, java.util.Locale, .ResourceBundle, .MissingResourceException, java.text.MessageFormat

Class comments here

Field Summary

Modifier and TypeField and Description
public static final String
private String
resourceBundleName

The name of the resource bundle we are using to load messages

public static final Locale

Constructor Summary

AccessConstructor and Description
public
MessageUtil(String
The base name of the resource bundle to use.
resourceBundleName
)

Create an instance of MessageUtil with a specific resource bundle.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

formatted message text
composeDefaultMessage
(String
The message to start with, which often is null
message
,
Object[]
The arguments to the message.
arguments
)

Compose a default message so that the user at least gets *something* useful rather than just a MissingResourceException, which is particularly unhelpful

private static int
countParams(String message)

Count the number of substituation parameters in the message

public static String

Returns:

the formatted message text
formatMessage
(ResourceBundle
The resource bundle to use to look for the message
bundle
,
String
The message id to use for the message
messageId
,
Object[]
The arguments for the message
arguments
,
boolean
Indicates whether a default message should be composed if the message can't be found in the resource bundle.

If composeDefault is false, this method will throw a MissingResourceException if the message could not be found.

If composeDefault is true, then if the message id is not found in the given bundle, this method composes and returns as helpful a message as possible in the format "UNKNOWN : [arg1], [arg2], ..."

composeDefault
)

Format a message given a resource bundle and a message id.

The arguments to the messages are passed via an object array.

public String

Returns:

the message text with arguments plugged in
getCompleteMessage
(String
The message handle
messageID
,
Object[]
The arguments to plug into the message
args
)

Instance method to get the complete message, using the provided resource bundle name as specified when this instance was constructed If for some reason the message could not be found, we return a default message using the message arguments

public static String

Returns:

The message for the given message id, with arguments substituted.
getCompleteMessage
(Locale
The locale to use when looking for the message. If the message is not found using this locale, we attempt to find it using the US locale (our default).
locale
,
String
The base name for the resource bundle to use.
resourceBundleName
,
String
The message identifier for this message
messageId
,
Object[]
The arguments for the message
arguments
,
boolean
If this is true, this method will compose a default message if the message could not be found in the provided resource bundles. If it is false, this method will throw a MissingResourceException if the message could not be found.
composeDefault
)

Generic routine to get a message with any number of arguments.

public static String

Returns:

the message text
getCompleteMessage
(String
The id to use to look up the message
messageId
,
String
The base name of the resource bundle to use.
resourceBundleName
,
Object[]
The arguments to the message
arguments
)

This is a wrapper for the getCompleteMessage workhorse routine using some obvious defaults, particularly for non-engine subsystems that only ever use the default locale.

public String

Returns:

the message text with arguments plugged in
getTextMessage
(String
The message handle
messageID
,
Object...
The arguments to plug into the message
args
)

Get a message with default locale.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLIENT_MESSAGE_RESOURCE_NAMEback to summary
public static final String CLIENT_MESSAGE_RESOURCE_NAME
resourceBundleNameback to summary
private String resourceBundleName

The name of the resource bundle we are using to load messages

USback to summary
public static final Locale US

Constructor Detail

MessageUtilback to summary
public MessageUtil(String resourceBundleName)

Create an instance of MessageUtil with a specific resource bundle. This assumes the default locale, which is just fine for users of this class other than the engine (which potentially has a different locale and a different resource bundle for each invocation of getCompleteMessage().

Parameters
resourceBundleName:String

The base name of the resource bundle to use.

Method Detail

composeDefaultMessageback to summary
public static String composeDefaultMessage(String message, Object[] arguments)

Compose a default message so that the user at least gets *something* useful rather than just a MissingResourceException, which is particularly unhelpful

Parameters
message:String

The message to start with, which often is null

arguments:Object[]

The arguments to the message.

Returns:String

formatted message text

countParamsback to summary
private static int countParams(String message)

Count the number of substituation parameters in the message

formatMessageback to summary
public static String formatMessage(ResourceBundle bundle, String messageId, Object[] arguments, boolean composeDefault)

Format a message given a resource bundle and a message id.

The arguments to the messages are passed via an object array. The objects in the array WILL be changed by this class. The caller should NOT get the object back from this array.

Parameters
bundle:ResourceBundle

The resource bundle to use to look for the message

messageId:String

The message id to use for the message

arguments:Object[]

The arguments for the message

composeDefault:boolean

Indicates whether a default message should be composed if the message can't be found in the resource bundle.

If composeDefault is false, this method will throw a MissingResourceException if the message could not be found.

If composeDefault is true, then if the message id is not found in the given bundle, this method composes and returns as helpful a message as possible in the format "UNKNOWN : [arg1], [arg2], ..."

Returns:String

the formatted message text

getCompleteMessageback to summary
public String getCompleteMessage(String messageID, Object[] args)

Instance method to get the complete message, using the provided resource bundle name as specified when this instance was constructed If for some reason the message could not be found, we return a default message using the message arguments

Parameters
messageID:String

The message handle

args:Object[]

The arguments to plug into the message

Returns:String

the message text with arguments plugged in

getCompleteMessageback to summary
public static String getCompleteMessage(Locale locale, String resourceBundleName, String messageId, Object[] arguments, boolean composeDefault) throws MissingResourceException

Generic routine to get a message with any number of arguments. Looks in the provided resource bundle for the message, using the specified locale and then the US locale.

Parameters
locale:Locale

The locale to use when looking for the message. If the message is not found using this locale, we attempt to find it using the US locale (our default).

resourceBundleName:String

The base name for the resource bundle to use.

messageId:String

The message identifier for this message

arguments:Object[]

The arguments for the message

composeDefault:boolean

If this is true, this method will compose a default message if the message could not be found in the provided resource bundles. If it is false, this method will throw a MissingResourceException if the message could not be found.

Returns:String

The message for the given message id, with arguments substituted.

Exceptions
MissingResourceException:
If the message could not be found and the composeDefault parameter was set to false.
getCompleteMessageback to summary
public static String getCompleteMessage(String messageId, String resourceBundleName, Object[] arguments) throws MissingResourceException

This is a wrapper for the getCompleteMessage workhorse routine using some obvious defaults, particularly for non-engine subsystems that only ever use the default locale. Get a message using the default locale. If the message is not found with the default locale, use the US locale. Do this both for the common bundle and the parent bundle. If the message is not found in common or in the parent resource bundle, return a default message composed of the message arguments.

Parameters
messageId:String

The id to use to look up the message

resourceBundleName:String

The base name of the resource bundle to use.

arguments:Object[]

The arguments to the message

Returns:String

the message text

getTextMessageback to summary
public String getTextMessage(String messageID, Object... args)

Get a message with default locale.

Parameters
messageID:String

The message handle

args:Object[]

The arguments to plug into the message

Returns:String

the message text with arguments plugged in