javax.jdo.spi

## Class I18NHelper

- java.lang.Object
- - javax.jdo.spi.I18NHelper

-     public class I18NHelper
      extends Object

  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

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static 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.
    `ResourceBundle` | `getResourceBundle()` Returns the resource bundle used by this I18NHelper.
    `String` | `msg(String messageKey)` Message formatter
    `String` | `msg(String messageKey, boolean arg)` Message formatter
    `String` | `msg(String messageKey, int arg)` Message formatter
    `String` | `msg(String messageKey, Object arg1)` Message formatter
    `String` | `msg(String messageKey, Object[] args)` Message formatter
    `String` | `msg(String messageKey, Object arg1, Object arg2)` Message formatter
    `String` | `msg(String messageKey, Object arg1, Object arg2, Object arg3)` Message formatter

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getInstance

          public static I18NHelper getInstance(String bundleName)

      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

          public static I18NHelper getInstance(Class cls)

      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 be `null`.
      Parameters:
        `cls` - the class object from which to load the resource bundle
      Returns:
        the helper instance bound to the bundle

    - #### getInstance

          public static I18NHelper getInstance(String bundleName,
                                               ClassLoader loader)

      An instance bound to a bundle. This method uses the specified class loader to find the bundle. Note, the specified class loader must not be `null`.
      Parameters:
        `bundleName` - the name of the bundle
        `loader` - the class loader from which to load the resource bundle
      Returns:
        the helper instance bound to the bundle

    - #### msg

          public String msg(String messageKey)

      Message formatter
      Parameters:
        `messageKey` - the message key
      Returns:
        the resolved message text

    - #### msg

          public String msg(String messageKey,
                            Object arg1)

      Message formatter
      Parameters:
        `messageKey` - the message key
        `arg1` - the first argument
      Returns:
        the resolved message text

    - #### msg

          public String msg(String messageKey,
                            Object arg1,
                            Object arg2)

      Message formatter
      Parameters:
        `messageKey` - the message key
        `arg1` - the first argument
        `arg2` - the second argument
      Returns:
        the resolved message text

    - #### msg

          public String msg(String messageKey,
                            Object arg1,
                            Object arg2,
                            Object arg3)

      Message formatter
      Parameters:
        `messageKey` - the message key
        `arg1` - the first argument
        `arg2` - the second argument
        `arg3` - the third argument
      Returns:
        the resolved message text

    - #### msg

          public String msg(String messageKey,
                            Object[] args)

      Message formatter
      Parameters:
        `messageKey` - the message key
        `args` - the array of arguments
      Returns:
        the resolved message text

    - #### msg

          public String msg(String messageKey,
                            int arg)

      Message formatter
      Parameters:
        `messageKey` - the message key
        `arg` - the argument
      Returns:
        the resolved message text

    - #### msg

          public String msg(String messageKey,
                            boolean arg)

      Message formatter
      Parameters:
        `messageKey` - the message key
        `arg` - the argument
      Returns:
        the resolved message text

    - #### getResourceBundle

          public ResourceBundle getResourceBundle()

      Returns the resource bundle used by this I18NHelper.
      Returns:
        the associated resource bundle
      Since:
        1.1

Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.