ResourceBundleProviderpublic abstract class AbstractResourceBundleProvider extends Object implements ResourceBundleProvider
AbstractResourceBundleProvider is an abstract class for helping
implement the ResourceBundleProvider interface.
Resource bundles can be packaged in a named module separated from
the caller module loading the resource bundle, i.e. the module
calling ResourceBundle.getBundle(String). For the caller module
to load a resource bundle "com.example.app.MyResources"
from another module and a service interface named
"com.example.app.MyResourcesProvider",
the bundle provider module can provide the implementation class
as follows:
import com.example.app.MyResourcesProvider; class MyResourcesProviderImpl extends AbstractResourceBundleProvider implements MyResourcesProvider {@Override public ResourceBundle getBundle(String baseName, Locale locale) { // this module only provides bundles in french if (locale.equals(Locale.FRENCH)) { return super.getBundle(baseName, locale); } return null; }}
| Modifier | Constructor | Description |
|---|---|---|
protected |
AbstractResourceBundleProvider() |
Constructs an
AbstractResourceBundleProvider with the
"java.properties" format. |
protected |
AbstractResourceBundleProvider(String... formats) |
Constructs an
AbstractResourceBundleProvider with the specified
formats. |
| Modifier and Type | Method | Description |
|---|---|---|
ResourceBundle |
getBundle(String baseName,
Locale locale) |
Returns a
ResourceBundle for the given baseName and
locale. |
protected String |
toBundleName(String baseName,
Locale locale) |
Returns the bundle name for the given
baseName and
locale. |
protected AbstractResourceBundleProvider()
AbstractResourceBundleProvider with the
"java.properties" format. This constructor is equivalent to
AbstractResourceBundleProvider("java.properties").protected AbstractResourceBundleProvider(String... formats)
AbstractResourceBundleProvider with the specified
formats. The getBundle(String, Locale) method looks up
resource bundles for the given formats. formats must
be "java.class" or "java.properties".formats - the formats to be used for loading resource bundlesNullPointerException - if the given formats is nullIllegalArgumentException - if the given formats is not
"java.class" or "java.properties".protected String toBundleName(String baseName, Locale locale)
baseName and
locale. This method is called from the default implementation of the
getBundle(String, Locale) method.ResourceBundle.Control.toBundleName(String, Locale).baseName - the base name of the resource bundle, a fully qualified
class namelocale - the locale for which a resource bundle should be loadedpublic ResourceBundle getBundle(String baseName, Locale locale)
ResourceBundle for the given baseName and
locale. This method calls the
toBundleName method to get the
bundle name for the baseName and locale. The formats
specified by the constructor will be searched to find the resource
bundle.getBundle in interface ResourceBundleProviderbaseName - the base bundle name of the resource bundle, a fully
qualified class name.locale - the locale for which the resource bundle should be instantiatedResourceBundle of the given baseName and locale,
or null if no resource bundle is foundNullPointerException - if baseName or locale is nullUncheckedIOException - if any IO exception occurred during resource
bundle loading Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved.
DRAFT 9-Ubuntu+0-9b143-1ubuntu1