Module java.base
Package java.util.spi

Class AbstractResourceBundleProvider

java.lang.Object
java.util.spi.AbstractResourceBundleProvider
All Implemented Interfaces:
ResourceBundleProvider

public abstract class AbstractResourceBundleProvider extends Object implements 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: