Package javax.jdo.spi
Class I18NHelper
java.lang.Object
javax.jdo.spi.I18NHelper
Helper class for constructing messages from bundles. The intended usage
of this class is to construct a new instance bound to a bundle, as in
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()));
- Since:
- 1.0.1
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ResourceBundle
The bundle used by this instance of the helper.private final String
The name of the bundle used by this instance of the helper.private static Hashtable
Bundles that have already been loadedprivate static final String
The unqualified standard name of a bundle.private Throwable
Throwable if ResourceBundle couldn't be loadedprivate static Hashtable
Helper instances that have already been createdprivate static Locale
The default locale for this VM. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Constructorprivate
I18NHelper
(String bundleName, ClassLoader loader) Constructor for an instance bound to a bundle. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Assert resources availableprivate void
assertBundle
(String key) Assert resources availablestatic I18NHelper
getInstance
(Class cls) An instance bound to a bundle.static I18NHelper
getInstance
(String bundleName) An instance bound to a bundle.static I18NHelper
getInstance
(String bundleName, ClassLoader loader) An instance bound to a bundle.private static final String
getMessage
(ResourceBundle messages, String messageKey) Returns message asString
private static final String
getMessage
(ResourceBundle messages, String messageKey, boolean arg) Formats message by adding aboolean
as an argument.private static final String
getMessage
(ResourceBundle messages, String messageKey, int arg) Formats message by adding anint
as an argument.private static final String
getMessage
(ResourceBundle messages, String messageKey, Object arg) Formats message by adding anObject
argument.private static final String
getMessage
(ResourceBundle messages, String messageKey, Object[] msgArgs) Formats message by adding array of argumentsprivate static final String
getMessage
(ResourceBundle messages, String messageKey, Object arg1, Object arg2) Formats message by adding twoObject
arguments.private static final String
getMessage
(ResourceBundle messages, String messageKey, Object arg1, Object arg2, Object arg3) Formats message by adding threeObject
arguments.private static final String
getPackageName
(String className) Returns the package portion of the specified class.Returns the resource bundle used by this I18NHelper.private static ClassLoader
Get the system class loader.private static final ResourceBundle
loadBundle
(String bundleName, ClassLoader loader) Load ResourceBundle by bundle nameMessage formatterMessage formatterMessage formatterMessage formatterMessage formatterMessage formatterMessage formatter
-
Field Details
-
bundles
Bundles that have already been loaded -
helpers
Helper instances that have already been created -
locale
The default locale for this VM. -
bundleName
The name of the bundle used by this instance of the helper. -
bundle
The bundle used by this instance of the helper. -
failure
Throwable if ResourceBundle couldn't be loaded -
bundleSuffix
The unqualified standard name of a bundle.- See Also:
-
-
Constructor Details
-
I18NHelper
private I18NHelper()Constructor -
I18NHelper
Constructor for an instance bound to a bundle.- Parameters:
bundleName
- the name of the resource bundleloader
- the class loader from which to load the resource bundle
-
-
Method Details
-
getInstance
An instance bound to a bundle. This method uses the current class loader to find the bundle.- Parameters:
bundleName
- the name of the bundle- Returns:
- the helper instance bound to the bundle
-
getInstance
An instance bound to a bundle. This method figures out the bundle name for the class object's package and uses the class' class loader to find the bundle. Note, the specified class object must not benull
.- Parameters:
cls
- the class object from which to load the resource bundle- Returns:
- the helper instance bound to the bundle
-
getInstance
An instance bound to a bundle. This method uses the specified class loader to find the bundle. Note, the specified class loader must not benull
.- Parameters:
bundleName
- the name of the bundleloader
- the class loader from which to load the resource bundle- Returns:
- the helper instance bound to the bundle
-
msg
Message formatter- Parameters:
messageKey
- the message key- Returns:
- the resolved message text
-
msg
Message formatter- Parameters:
messageKey
- the message keyarg1
- the first argument- Returns:
- the resolved message text
-
msg
Message formatter- Parameters:
messageKey
- the message keyarg1
- the first argumentarg2
- the second argument- Returns:
- the resolved message text
-
msg
Message formatter- Parameters:
messageKey
- the message keyarg1
- the first argumentarg2
- the second argumentarg3
- the third argument- Returns:
- the resolved message text
-
msg
Message formatter- Parameters:
messageKey
- the message keyargs
- the array of arguments- Returns:
- the resolved message text
-
msg
Message formatter- Parameters:
messageKey
- the message keyarg
- the argument- Returns:
- the resolved message text
-
msg
Message formatter- Parameters:
messageKey
- the message keyarg
- the argument- Returns:
- the resolved message text
-
getResourceBundle
Returns the resource bundle used by this I18NHelper.- Returns:
- the associated resource bundle
- Since:
- 1.1
-
loadBundle
Load ResourceBundle by bundle name- Parameters:
bundleName
- the name of the bundleloader
- the class loader from which to load the resource bundle- Returns:
- the ResourceBundle
-
assertBundle
private void assertBundle()Assert resources available- Throws:
JDOFatalInternalException
- if the resource bundle could not be loaded during construction.- Since:
- 1.1
-
assertBundle
Assert resources available- Parameters:
key
- the message key- Throws:
JDOFatalInternalException
- if the resource bundle could not be loaded during construction.- Since:
- 1.0.2
-
getMessage
Returns message asString
- Parameters:
messages
- the resource bundlemessageKey
- the message key- Returns:
- the resolved message text
-
getMessage
private static final String getMessage(ResourceBundle messages, String messageKey, Object[] msgArgs) Formats message by adding array of arguments- Parameters:
messages
- the resource bundlemessageKey
- the message keymsgArgs
- an array of arguments to substitute into the message- Returns:
- the resolved message text
-
getMessage
Formats message by adding anObject
argument.- Parameters:
messages
- the resource bundlemessageKey
- the message keyarg
- the argument- Returns:
- the resolved message text
-
getMessage
private static final String getMessage(ResourceBundle messages, String messageKey, Object arg1, Object arg2) Formats message by adding twoObject
arguments.- Parameters:
messages
- the resource bundlemessageKey
- the message keyarg1
- the first argumentarg2
- the second argument- Returns:
- the resolved message text
-
getMessage
private static final String getMessage(ResourceBundle messages, String messageKey, Object arg1, Object arg2, Object arg3) Formats message by adding threeObject
arguments.- Parameters:
messages
- the resource bundlemessageKey
- the message keyarg1
- the first argumentarg2
- the second argumentarg3
- the third argument- Returns:
- the resolved message text
-
getMessage
Formats message by adding anint
as an argument.- Parameters:
messages
- the resource bundlemessageKey
- the message keyarg
- the argument- Returns:
- the resolved message text
-
getMessage
Formats message by adding aboolean
as an argument.- Parameters:
messages
- the resource bundlemessageKey
- the message keyarg
- the argument- Returns:
- the resolved message text
-
getPackageName
Returns the package portion of the specified class.- Parameters:
className
- the name of the class from which to extract the package- Returns:
- package portion of the specified class
-
getSystemClassLoaderPrivileged
Get the system class loader. This must be done in a doPrivileged block because of security.
-