Class AbstractResourceBundleProvider
- All Implemented Interfaces:
ResourceBundleProvider
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.
- Since:
- 9
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs anAbstractResourceBundleProviderwith the "java.properties" format.protectedAbstractResourceBundleProvider(String... formats) Constructs anAbstractResourceBundleProviderwith the specifiedformats. -
Method Summary
Modifier and TypeMethodDescriptionReturns aResourceBundlefor the givenbaseNameandlocale.protected StringtoBundleName(String baseName, Locale locale) Returns the bundle name for the givenbaseNameandlocalethat this provider provides.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
AbstractResourceBundleProvider
protected AbstractResourceBundleProvider()Constructs anAbstractResourceBundleProviderwith the "java.properties" format. This constructor is equivalent toAbstractResourceBundleProvider("java.properties"). -
AbstractResourceBundleProvider
Constructs anAbstractResourceBundleProviderwith the specifiedformats. ThegetBundle(String, Locale)method looks up resource bundles for the givenformats.formatsmust be "java.class" or "java.properties".- Parameters:
formats- the formats to be used for loading resource bundles- Throws:
NullPointerException- if the givenformatsis nullIllegalArgumentException- if the givenformatsis not "java.class" or "java.properties".
-
-
Method Details
-
toBundleName
Returns the bundle name for the givenbaseNameandlocalethat this provider provides.- 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
baseNameis"p.resources.Bundle"then the resource bundle name of"p.resources.Bundle"ofLocale("ja", "", "XX")andLocale("en")could be"p.resources.ja.Bundle_ja_ _XX"and"p.resources.Bundle_en"respectively.This method is called from the default implementation of the
getBundle(String, Locale)method. - Implementation Note:
- The default implementation of this method is the same as the
implementation of
ResourceBundle.Control.toBundleName(String, Locale). - Parameters:
baseName- the base name of the resource bundle, a fully qualified class namelocale- the locale for which a resource bundle should be loaded- Returns:
- the bundle name for the resource bundle
-
getBundle
Returns aResourceBundlefor the givenbaseNameandlocale.- Specified by:
getBundlein interfaceResourceBundleProvider- Implementation Note:
- The default implementation of this method calls the
toBundleNamemethod to get the bundle name for thebaseNameandlocaleand finds the resource bundle of the bundle name local in the module of this provider. It will only search the formats specified when this provider was constructed. - Parameters:
baseName- the base bundle name of the resource bundle, a fully qualified class name.locale- the locale for which the resource bundle should be instantiated- Returns:
ResourceBundleof the givenbaseNameandlocale, ornullif no resource bundle is found- Throws:
NullPointerException- ifbaseNameorlocaleisnullUncheckedIOException- if any IO exception occurred during resource bundle loading
-