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

public final Class MessageService

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.error.ShutdownException, org.apache.derby.shared.common.info.JVMInfo, org.apache.derby.shared.common.reference.ModuleUtil, java.io.InputStream, .IOException, java.util.Locale, .MissingResourceException, .PropertyResourceBundle, .ResourceBundle, java.text.MessageFormat

Message Service implementation provides a mechanism for locating messages and substituting arguments for message parameters. It also provides a service for locating property values.

It uses the resource bundle mechanism for locating messages based on keys; the preferred form of resource bundle is a property file mapping keys to messages.

Field Summary

Modifier and TypeField and Description
private static final String
private static final Locale
private static BundleFinder
private static final String
private static final String
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String
formatMessage(ResourceBundle bundle, String messageId, Object[] arguments, boolean lastChance)

private static ResourceBundle
getBundle(String messageId)

private static ResourceBundle
getBundle(String resource, Locale locale)

Look up a bundle in the correct package.

public static ResourceBundle
public static ResourceBundle

Returns:

the best message bundle to localize the messages
getBundleWithEnDefault
(String
The name of the message resource
resource
,
Locale
The preferred locale
locale
)

Method to use instead of ResourceBundle.getBundle().

private static PropertyResourceBundle

Returns:

the corresponding resource bundle
getModuleResourceBundle
(final String
The name of the resource
resourceName
,
final Module
The module where it lives
module
)

Get a resource bundle from a module.

public static String

Returns:

the resulting new property name
getProperty
(String
The handle on the message
messageId
,
String
The property to append
propertyName
)

Append a property name onto the end of a message

public static String

Returns:

the text for the message with arguments plugged in
getTextMessage
(String
The message handle
messageId
,
Object...
The arguments to the message
arguments
)

Transform the message from messageID to the actual error, warning, or info message using the correct locale.

public static int

Returns:

the corresponding hash
hashString50
(String
A key to hash
key
)

Hash function to split messages into 50 files based upon the message identifier or SQLState.

private static String
localizeResourceName(String original, String localeName)

Add a directory level named locale_xx_YY to the resource name if it is not the clientmessages resource bundle.

private static ResourceBundle
lookupBundle(String resource, Locale locale)

Use the JVM to lookup a ResourceBundle

public static ResourceBundle
lookupBundleInModule(String resource, Locale locale)

Lookup the message in a Jigsaw module.

private static ResourceBundle
lookupBundleInModule(Module messageModule, String resource, String localeSuffix, boolean useEnglish, boolean useEngineModule)

Lookup a message in a given module

public static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLIENT_MESSAGESback to summary
private static final String CLIENT_MESSAGES
ENback to summary
private static final Locale EN
finderback to summary
private static BundleFinder finder
LOCALE_STUBback to summary
private static final String LOCALE_STUB
SERVER_MESSAGESback to summary
private static final String SERVER_MESSAGES
SYSINFO_MESSAGESback to summary
private static final String SYSINFO_MESSAGES
TOOLS_MESSAGESback to summary
private static final String TOOLS_MESSAGES

Constructor Detail

MessageServiceback to summary
private MessageService()

Method Detail

formatMessageback to summary
public static String formatMessage(ResourceBundle bundle, String messageId, Object[] arguments, boolean lastChance)
getBundleback to summary
private static ResourceBundle getBundle(String messageId)
getBundleback to summary
private static ResourceBundle getBundle(String resource, Locale locale)

Look up a bundle in the correct package. Returns null if the bundle can't be found.

getBundleForLocaleback to summary
public static ResourceBundle getBundleForLocale(Locale locale, String msgId)
getBundleWithEnDefaultback to summary
public static ResourceBundle getBundleWithEnDefault(String resource, Locale locale)

Method to use instead of ResourceBundle.getBundle(). This method acts like ResourceBundle.getBundle() but if the resource is not available in the requested locale, default locale or base class the one for en_US is returned.

Parameters
resource:String

The name of the message resource

locale:Locale

The preferred locale

Returns:ResourceBundle

the best message bundle to localize the messages

getModuleResourceBundleback to summary
private static PropertyResourceBundle getModuleResourceBundle(final String resourceName, final Module module)

Get a resource bundle from a module.

Parameters
resourceName:String

The name of the resource

module:Module

The module where it lives

Returns:PropertyResourceBundle

the corresponding resource bundle

getPropertyback to summary
public static String getProperty(String messageId, String propertyName)

Append a property name onto the end of a message

Parameters
messageId:String

The handle on the message

propertyName:String

The property to append

Returns:String

the resulting new property name

getTextMessageback to summary
public static String getTextMessage(String messageId, Object... arguments)

Transform the message from messageID to the actual error, warning, or info message using the correct locale.

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
messageId:String

The message handle

arguments:Object[]

The arguments to the message

Returns:String

the text for the message with arguments plugged in

hashString50back to summary
public static int hashString50(String key)

Hash function to split messages into 50 files based upon the message identifier or SQLState. We don't use String.hashCode() as it varies between releases and doesn't provide an even distribution across the 50 files.

Parameters
key:String

A key to hash

Returns:int

the corresponding hash

localizeResourceNameback to summary
private static String localizeResourceName(String original, String localeName)

Add a directory level named locale_xx_YY to the resource name if it is not the clientmessages resource bundle. So, for instance, "org.apache.derby.loc.tools.toolsmessages" becomes "org.apache.derby.loc.tools.locale_de_DE.toolsmessages".

lookupBundleback to summary
private static ResourceBundle lookupBundle(String resource, Locale locale)

Use the JVM to lookup a ResourceBundle

lookupBundleInModuleback to summary
public static ResourceBundle lookupBundleInModule(String resource, Locale locale)

Lookup the message in a Jigsaw module.

lookupBundleInModuleback to summary
private static ResourceBundle lookupBundleInModule(Module messageModule, String resource, String localeSuffix, boolean useEnglish, boolean useEngineModule)

Lookup a message in a given module

setFinderback to summary
public static void setFinder(BundleFinder theFinder)