public class I18NHelper
extends java.lang.Object
I18NHelper msg = I18NHelper.getInstance("javax.jdo.Bundle");
This call uses the class loader that loaded the I18NHelper class to find
the specified Bundle. The class provides two overloaded getInstance
methods allowing to specify a different class loader:
getInstance(Class cls)
looks for a bundle
called "Bundle.properties" located in the package of the specified class
object and getInstance(String bundleName,ClassLoader loader)
uses the specified class loader to find the bundle.
Subsequently, instance methods can be used to format message strings using the text from the bundle, as in
throw new JDOFatalInternalException (msg.msg("ERR_NoMetadata",
cls.getName()));
Modifier and Type | Field and Description |
---|---|
private java.util.ResourceBundle |
bundle
The bundle used by this instance of the helper.
|
private java.lang.String |
bundleName
The name of the bundle used by this instance of the helper.
|
private static java.util.Hashtable |
bundles
Bundles that have already been loaded
|
private static java.lang.String |
bundleSuffix
The unqualified standard name of a bundle.
|
private java.lang.Throwable |
failure
Throwable if ResourceBundle couldn't be loaded
|
private static java.util.Hashtable |
helpers
Helper instances that have already been created
|
private static java.util.Locale |
locale
The default locale for this VM.
|
Modifier | Constructor and Description |
---|---|
private |
I18NHelper()
Constructor
|
private |
I18NHelper(java.lang.String bundleName,
java.lang.ClassLoader loader)
Constructor for an instance bound to a bundle.
|
Modifier and Type | Method and Description |
---|---|
private void |
assertBundle()
Assert resources available
|
private void |
assertBundle(java.lang.String key)
Assert resources available
|
static I18NHelper |
getInstance(java.lang.Class cls)
An instance bound to a bundle.
|
static I18NHelper |
getInstance(java.lang.String bundleName)
An instance bound to a bundle.
|
static I18NHelper |
getInstance(java.lang.String bundleName,
java.lang.ClassLoader loader)
An instance bound to a bundle.
|
private static java.lang.String |
getMessage(java.util.ResourceBundle messages,
java.lang.String messageKey)
Returns message as
String |
private static java.lang.String |
getMessage(java.util.ResourceBundle messages,
java.lang.String messageKey,
boolean arg)
Formats message by adding a
boolean as an argument. |
private static java.lang.String |
getMessage(java.util.ResourceBundle messages,
java.lang.String messageKey,
int arg)
Formats message by adding an
int as an argument. |
private static java.lang.String |
getMessage(java.util.ResourceBundle messages,
java.lang.String messageKey,
java.lang.Object arg)
Formats message by adding an
Object argument. |
private static java.lang.String |
getMessage(java.util.ResourceBundle messages,
java.lang.String messageKey,
java.lang.Object[] msgArgs)
Formats message by adding array of arguments
|
private static java.lang.String |
getMessage(java.util.ResourceBundle messages,
java.lang.String messageKey,
java.lang.Object arg1,
java.lang.Object arg2)
Formats message by adding two
Object arguments. |
private static java.lang.String |
getMessage(java.util.ResourceBundle messages,
java.lang.String messageKey,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3)
Formats message by adding three
Object arguments. |
private static java.lang.String |
getPackageName(java.lang.String className)
Returns the package portion of the specified class.
|
java.util.ResourceBundle |
getResourceBundle()
Returns the resource bundle used by this I18NHelper.
|
private static java.lang.ClassLoader |
getSystemClassLoaderPrivileged()
Get the system class loader.
|
private static java.util.ResourceBundle |
loadBundle(java.lang.String bundleName,
java.lang.ClassLoader loader)
Load ResourceBundle by bundle name
|
java.lang.String |
msg(java.lang.String messageKey)
Message formatter
|
java.lang.String |
msg(java.lang.String messageKey,
boolean arg)
Message formatter
|
java.lang.String |
msg(java.lang.String messageKey,
int arg)
Message formatter
|
java.lang.String |
msg(java.lang.String messageKey,
java.lang.Object arg1)
Message formatter
|
java.lang.String |
msg(java.lang.String messageKey,
java.lang.Object[] args)
Message formatter
|
java.lang.String |
msg(java.lang.String messageKey,
java.lang.Object arg1,
java.lang.Object arg2)
Message formatter
|
java.lang.String |
msg(java.lang.String messageKey,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3)
Message formatter
|
private static java.util.Hashtable bundles
private static java.util.Hashtable helpers
private static java.util.Locale locale
private final java.lang.String bundleName
private java.util.ResourceBundle bundle
private java.lang.Throwable failure
private static final java.lang.String bundleSuffix
private I18NHelper()
private I18NHelper(java.lang.String bundleName, java.lang.ClassLoader loader)
bundleName
- the name of the resource bundleloader
- the class loader from which to load the resource
bundlepublic static I18NHelper getInstance(java.lang.String bundleName)
bundleName
- the name of the bundlepublic static I18NHelper getInstance(java.lang.Class cls)
null
.cls
- the class object from which to load the resource bundlepublic static I18NHelper getInstance(java.lang.String bundleName, java.lang.ClassLoader loader)
null
.bundleName
- the name of the bundleloader
- the class loader from which to load the resource
bundlepublic java.lang.String msg(java.lang.String messageKey)
messageKey
- the message keypublic java.lang.String msg(java.lang.String messageKey, java.lang.Object arg1)
messageKey
- the message keyarg1
- the first argumentpublic java.lang.String msg(java.lang.String messageKey, java.lang.Object arg1, java.lang.Object arg2)
messageKey
- the message keyarg1
- the first argumentarg2
- the second argumentpublic java.lang.String msg(java.lang.String messageKey, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
messageKey
- the message keyarg1
- the first argumentarg2
- the second argumentarg3
- the third argumentpublic java.lang.String msg(java.lang.String messageKey, java.lang.Object[] args)
messageKey
- the message keyargs
- the array of argumentspublic java.lang.String msg(java.lang.String messageKey, int arg)
messageKey
- the message keyarg
- the argumentpublic java.lang.String msg(java.lang.String messageKey, boolean arg)
messageKey
- the message keyarg
- the argumentpublic java.util.ResourceBundle getResourceBundle()
private static final java.util.ResourceBundle loadBundle(java.lang.String bundleName, java.lang.ClassLoader loader)
bundleName
- the name of the bundleloader
- the class loader from which to load the resource bundleprivate void assertBundle()
JDOFatalInternalException
- if the resource bundle could not
be loaded during construction.private void assertBundle(java.lang.String key)
key
- the message keyJDOFatalInternalException
- if the resource bundle could not
be loaded during construction.private static final java.lang.String getMessage(java.util.ResourceBundle messages, java.lang.String messageKey)
String
messages
- the resource bundlemessageKey
- the message keyprivate static final java.lang.String getMessage(java.util.ResourceBundle messages, java.lang.String messageKey, java.lang.Object[] msgArgs)
messages
- the resource bundlemessageKey
- the message keymsgArgs
- an array of arguments to substitute into the messageprivate static final java.lang.String getMessage(java.util.ResourceBundle messages, java.lang.String messageKey, java.lang.Object arg)
Object
argument.messages
- the resource bundlemessageKey
- the message keyarg
- the argumentprivate static final java.lang.String getMessage(java.util.ResourceBundle messages, java.lang.String messageKey, java.lang.Object arg1, java.lang.Object arg2)
Object
arguments.messages
- the resource bundlemessageKey
- the message keyarg1
- the first argumentarg2
- the second argumentprivate static final java.lang.String getMessage(java.util.ResourceBundle messages, java.lang.String messageKey, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
Object
arguments.messages
- the resource bundlemessageKey
- the message keyarg1
- the first argumentarg2
- the second argumentarg3
- the third argumentprivate static final java.lang.String getMessage(java.util.ResourceBundle messages, java.lang.String messageKey, int arg)
int
as an argument.messages
- the resource bundlemessageKey
- the message keyarg
- the argumentprivate static final java.lang.String getMessage(java.util.ResourceBundle messages, java.lang.String messageKey, boolean arg)
boolean
as an argument.messages
- the resource bundlemessageKey
- the message keyarg
- the argumentprivate static final java.lang.String getPackageName(java.lang.String className)
className
- the name of the class from which to extract the
packageprivate static java.lang.ClassLoader getSystemClassLoaderPrivileged()