AbstractResourceBundleProvider is an abstract class that provides
the basic support for a provider implementation class for
ResourceBundleProvider.
Resource bundles can be packaged in one or more
named modules, service provider modules. The consumer of the
resource bundle is the one calling ResourceBundle#getBundle(String).
In order for the consumer module to load a resource bundle
"com.example.app.MyResources" provided by another module,
it will use the service loader
mechanism. A service interface named "com.example.app.spi.MyResourcesProvider"
must be defined and a service provider module will provide an
implementation class of "com.example.app.spi.MyResourcesProvider"
as follows:
import com.example.app.spi.MyResourcesProvider; class MyResourcesProviderImpl extends AbstractResourceBundleProvider implements MyResourcesProvider { public MyResourcesProviderImpl() { super("java.properties"); } // this provider maps the resource bundle to per-language package protected String toBundleName(String baseName, Locale locale) { return "p." + locale.getLanguage() + "." + baseName; } public ResourceBundle getBundle(String baseName, Locale locale) { // this module only provides bundles in French if (locale.equals(Locale.FRENCH)) { return super.getBundle(baseName, locale); } // otherwise return null return null; } }
Refer to ResourceBundleProvider for details.
Resource Bundles and Named Modules
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final String | |
| private final String[] | |
| private static final JavaUtilResourceBundleAccess |
| Access | Constructor and Description |
|---|---|
| protected | AbstractResourceBundleProvider()
Constructs an |
| protected | AbstractResourceBundleProvider(String...
the formats to be used for loading resource bundles formats)Constructs an |
| Modifier and Type | Method and Description |
|---|---|
| public ResourceBundle | Returns: ResourceBundle of the given baseName and
locale, or null if no resource bundle is foundthe base bundle name of the resource bundle, a fully
qualified class name. baseName, Locale the locale for which the resource bundle should be instantiated locale)Implements java. Returns a |
| private ResourceBundle | |
| private static ResourceBundle | |
| private static ResourceBundle | |
| protected String | Returns: the bundle name for the resource bundlethe base name of the resource bundle, a fully qualified
class name baseName, Locale the locale for which a resource bundle should be loaded locale)Returns the bundle name for the given |
| private static String |
| FORMAT_CLASS | back to summary |
|---|---|
| private static final String FORMAT_CLASS | |
| FORMAT_PROPERTIES | back to summary |
|---|---|
| private static final String FORMAT_PROPERTIES | |
| formats | back to summary |
|---|---|
| private final String[] formats | |
| RB_ACCESS | back to summary |
|---|---|
| private static final JavaUtilResourceBundleAccess RB_ACCESS | |
| AbstractResourceBundleProvider | back to summary |
|---|---|
| protected AbstractResourceBundleProvider() Constructs an | |
| AbstractResourceBundleProvider | back to summary |
|---|---|
| protected AbstractResourceBundleProvider(String... formats) Constructs an
| |
| getBundle | back to summary |
|---|---|
| public ResourceBundle getBundle(String baseName, Locale locale) Implements java. Returns a Implementation Note The default implementation of this method calls the
| |
| getBundle0 | back to summary |
|---|---|
| private ResourceBundle getBundle0(Module module, String bundleName) | |
| loadPropertyResourceBundle | back to summary |
|---|---|
| private static ResourceBundle loadPropertyResourceBundle(Module module, String bundleName) throws IOException | |
| loadResourceBundle | back to summary |
|---|---|
| private static ResourceBundle loadResourceBundle(Module module, String bundleName) | |
| toBundleName | back to summary |
|---|---|
| protected String toBundleName(String baseName, Locale locale) Returns the bundle name for the given API Note A resource bundle provider may package its resource bundles in the same package as the base name of the resource bundle if the package is not split among other named modules. If there are more than one bundle providers providing the resource bundle of a given base name, the resource bundles can be packaged with per-language grouping or per-region grouping to eliminate the split packages. For example, if This method is called from the default implementation of the
Implementation Note The default implementation of this method is the same as the
implementation of
| |
| toResourceName | back to summary |
|---|---|
| private static String toResourceName(String bundleName, String suffix) | |