1 /*
   2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.spi;
  27 
  28 import java.util.Locale;
  29 import java.util.ResourceBundle;
  30 
  31 /**
  32  * {@code ResourceBundleProvider} is a provider interface that is used for
  33  * loading resource bundles for named modules. Implementation classes of
  34  * this interface are loaded with {@link java.util.ServiceLoader ServiceLoader}
  35  * during a call to the
  36  * {@link ResourceBundle#getBundle(String, Locale, ClassLoader)
  37  * ResourceBundle.getBundle} method. The provider service type is determined by
  38  * {@code basename+"Provider"}.
  39  *
  40  * <p>
  41  * For example, if the base name is "com.example.app.MyResources",
  42  * {@code com.example.app.MyResourcesProvider} will be the provider service type:
  43  * <pre>{@code
  44  * public interface MyResourcesProvider extends ResourceBundleProvider {
  45  * }
  46  * }</pre>
  47  *
  48  * <p>
  49  * This providers's {@link #getBundle(String, Locale) getBundle} method is called
  50  * through the resource bundle loading process instead of {@link
  51  * java.util.ResourceBundle.Control#newBundle(String, Locale, String, ClassLoader, boolean)
  52  * ResourceBundle.Control.newBundle()}. Refer to {@link ResourceBundle} for
  53  * details.
  54  *
  55  * @see <a href="../ResourceBundle.html#bundleprovider">
  56  *     Resource Bundles in Named Modules</a>
  57  * @see <a href="../ResourceBundle.html#RBP_support">
  58  *     ResourceBundleProvider Service Providers</a>
  59  * @since 9
  60  */
  61 public interface ResourceBundleProvider {
  62     /**
  63      * Returns a {@code ResourceBundle} for the given bundle name and locale.
  64      * This method returns {@code null} if there is no {@code ResourceBundle}
  65      * found for the given parameters.
  66      *
  67      *
  68      * @param baseName
  69      *        the base bundle name of the resource bundle, a fully
  70      *        qualified class name
  71      * @param locale
  72      *        the locale for which the resource bundle should be loaded
  73      * @return the ResourceBundle created for the given parameters, or null if no
  74      *         {@code ResourceBundle} for the given parameters is found
  75      */
  76     public ResourceBundle getBundle(String baseName, Locale locale);
  77 }