< prev index next >

src/java.base/share/classes/java/util/ResourceBundle.java

Print this page




1205      * <p>
1206      * The following class and property files are provided:
1207      * <pre>
1208      *     MyResources.class
1209      *     MyResources.properties
1210      *     MyResources_fr.properties
1211      *     MyResources_fr_CH.class
1212      *     MyResources_fr_CH.properties
1213      *     MyResources_en.properties
1214      *     MyResources_es_ES.class
1215      * </pre>
1216      *
1217      * The contents of all files are valid (that is, public non-abstract
1218      * subclasses of <code>ResourceBundle</code> for the ".class" files,
1219      * syntactically correct ".properties" files).  The default locale is
1220      * <code>Locale("en", "GB")</code>.
1221      *
1222      * <p>Calling <code>getBundle</code> with the locale arguments below will
1223      * instantiate resource bundles as follows:
1224      *
1225      * <table summary="getBundle() locale to resource bundle mapping">


1226      * <tr><td>Locale("fr", "CH")</td><td>MyResources_fr_CH.class, parent MyResources_fr.properties, parent MyResources.class</td></tr>
1227      * <tr><td>Locale("fr", "FR")</td><td>MyResources_fr.properties, parent MyResources.class</td></tr>
1228      * <tr><td>Locale("de", "DE")</td><td>MyResources_en.properties, parent MyResources.class</td></tr>
1229      * <tr><td>Locale("en", "US")</td><td>MyResources_en.properties, parent MyResources.class</td></tr>
1230      * <tr><td>Locale("es", "ES")</td><td>MyResources_es_ES.class, parent MyResources.class</td></tr>

1231      * </table>
1232      *
1233      * <p>The file MyResources_fr_CH.properties is never used because it is
1234      * hidden by the MyResources_fr_CH.class. Likewise, MyResources.properties
1235      * is also hidden by MyResources.class.
1236      *
1237      * @apiNote If the caller module is a named module and the given
1238      * {@code loader} is the caller module's class loader, this method is
1239      * equivalent to {@code getBundle(baseName, locale)}; otherwise, it will not
1240      * find resource bundles from named modules.
1241      * Use {@link #getBundle(String, Locale, Module)} to load resource bundles
1242      * on behalf on a specific module instead.
1243      *
1244      * @param baseName the base name of the resource bundle, a fully qualified class name
1245      * @param locale the locale for which a resource bundle is desired
1246      * @param loader the class loader from which to load the resource bundle
1247      * @return a resource bundle for the given base name and locale
1248      * @exception java.lang.NullPointerException
1249      *        if <code>baseName</code>, <code>locale</code>, or <code>loader</code> is <code>null</code>
1250      * @exception MissingResourceException


1294      *
1295      * <li>The {@link ResourceBundle.Control#getCandidateLocales(String,
1296      * Locale) control.getCandidateLocales} method is called with the target
1297      * locale to get a list of <em>candidate <code>Locale</code>s</em> for
1298      * which resource bundles are searched.</li>
1299      *
1300      * <li>The {@link ResourceBundle.Control#newBundle(String, Locale,
1301      * String, ClassLoader, boolean) control.newBundle} method is called to
1302      * instantiate a <code>ResourceBundle</code> for the base bundle name, a
1303      * candidate locale, and a format. (Refer to the note on the cache
1304      * lookup below.) This step is iterated over all combinations of the
1305      * candidate locales and formats until the <code>newBundle</code> method
1306      * returns a <code>ResourceBundle</code> instance or the iteration has
1307      * used up all the combinations. For example, if the candidate locales
1308      * are <code>Locale("de", "DE")</code>, <code>Locale("de")</code> and
1309      * <code>Locale("")</code> and the formats are <code>"java.class"</code>
1310      * and <code>"java.properties"</code>, then the following is the
1311      * sequence of locale-format combinations to be used to call
1312      * <code>control.newBundle</code>.
1313      *
1314      * <table style="width: 50%; text-align: left; margin-left: 40px;"
1315      *  border="0" cellpadding="2" cellspacing="2" summary="locale-format combinations for newBundle">
1316      * <tbody>
1317      * <tr>
1318      * <td
1319      * style="vertical-align: top; text-align: left; font-weight: bold; width: 50%;"><code>Locale</code><br>
1320      * </td>
1321      * <td
1322      * style="vertical-align: top; text-align: left; font-weight: bold; width: 50%;"><code>format</code><br>
1323      * </td>
1324      * </tr>


1325      * <tr>
1326      * <td style="vertical-align: top; width: 50%;"><code>Locale("de", "DE")</code><br>
1327      * </td>
1328      * <td style="vertical-align: top; width: 50%;"><code>java.class</code><br>
1329      * </td>
1330      * </tr>
1331      * <tr>
1332      * <td style="vertical-align: top; width: 50%;"><code>Locale("de", "DE")</code></td>
1333      * <td style="vertical-align: top; width: 50%;"><code>java.properties</code><br>
1334      * </td>
1335      * </tr>
1336      * <tr>
1337      * <td style="vertical-align: top; width: 50%;"><code>Locale("de")</code></td>
1338      * <td style="vertical-align: top; width: 50%;"><code>java.class</code></td>
1339      * </tr>
1340      * <tr>
1341      * <td style="vertical-align: top; width: 50%;"><code>Locale("de")</code></td>
1342      * <td style="vertical-align: top; width: 50%;"><code>java.properties</code></td>
1343      * </tr>
1344      * <tr>




1205      * <p>
1206      * The following class and property files are provided:
1207      * <pre>
1208      *     MyResources.class
1209      *     MyResources.properties
1210      *     MyResources_fr.properties
1211      *     MyResources_fr_CH.class
1212      *     MyResources_fr_CH.properties
1213      *     MyResources_en.properties
1214      *     MyResources_es_ES.class
1215      * </pre>
1216      *
1217      * The contents of all files are valid (that is, public non-abstract
1218      * subclasses of <code>ResourceBundle</code> for the ".class" files,
1219      * syntactically correct ".properties" files).  The default locale is
1220      * <code>Locale("en", "GB")</code>.
1221      *
1222      * <p>Calling <code>getBundle</code> with the locale arguments below will
1223      * instantiate resource bundles as follows:
1224      *
1225      * <table>
1226      * <caption style="display:none">getBundle() locale to resource bundle mapping</caption>
1227      * <tbody>
1228      * <tr><td>Locale("fr", "CH")</td><td>MyResources_fr_CH.class, parent MyResources_fr.properties, parent MyResources.class</td></tr>
1229      * <tr><td>Locale("fr", "FR")</td><td>MyResources_fr.properties, parent MyResources.class</td></tr>
1230      * <tr><td>Locale("de", "DE")</td><td>MyResources_en.properties, parent MyResources.class</td></tr>
1231      * <tr><td>Locale("en", "US")</td><td>MyResources_en.properties, parent MyResources.class</td></tr>
1232      * <tr><td>Locale("es", "ES")</td><td>MyResources_es_ES.class, parent MyResources.class</td></tr>
1233      * </tbody>
1234      * </table>
1235      *
1236      * <p>The file MyResources_fr_CH.properties is never used because it is
1237      * hidden by the MyResources_fr_CH.class. Likewise, MyResources.properties
1238      * is also hidden by MyResources.class.
1239      *
1240      * @apiNote If the caller module is a named module and the given
1241      * {@code loader} is the caller module's class loader, this method is
1242      * equivalent to {@code getBundle(baseName, locale)}; otherwise, it will not
1243      * find resource bundles from named modules.
1244      * Use {@link #getBundle(String, Locale, Module)} to load resource bundles
1245      * on behalf on a specific module instead.
1246      *
1247      * @param baseName the base name of the resource bundle, a fully qualified class name
1248      * @param locale the locale for which a resource bundle is desired
1249      * @param loader the class loader from which to load the resource bundle
1250      * @return a resource bundle for the given base name and locale
1251      * @exception java.lang.NullPointerException
1252      *        if <code>baseName</code>, <code>locale</code>, or <code>loader</code> is <code>null</code>
1253      * @exception MissingResourceException


1297      *
1298      * <li>The {@link ResourceBundle.Control#getCandidateLocales(String,
1299      * Locale) control.getCandidateLocales} method is called with the target
1300      * locale to get a list of <em>candidate <code>Locale</code>s</em> for
1301      * which resource bundles are searched.</li>
1302      *
1303      * <li>The {@link ResourceBundle.Control#newBundle(String, Locale,
1304      * String, ClassLoader, boolean) control.newBundle} method is called to
1305      * instantiate a <code>ResourceBundle</code> for the base bundle name, a
1306      * candidate locale, and a format. (Refer to the note on the cache
1307      * lookup below.) This step is iterated over all combinations of the
1308      * candidate locales and formats until the <code>newBundle</code> method
1309      * returns a <code>ResourceBundle</code> instance or the iteration has
1310      * used up all the combinations. For example, if the candidate locales
1311      * are <code>Locale("de", "DE")</code>, <code>Locale("de")</code> and
1312      * <code>Locale("")</code> and the formats are <code>"java.class"</code>
1313      * and <code>"java.properties"</code>, then the following is the
1314      * sequence of locale-format combinations to be used to call
1315      * <code>control.newBundle</code>.
1316      *
1317      * <table style="width: 50%; text-align: left; margin-left: 40px;">
1318      * <caption style="display:none">locale-format combinations for newBundle</caption>
1319      * <thead>
1320      * <tr>
1321      * <td
1322      * style="vertical-align: top; text-align: left; font-weight: bold; width: 50%;"><code>Locale</code><br>
1323      * </td>
1324      * <td
1325      * style="vertical-align: top; text-align: left; font-weight: bold; width: 50%;"><code>format</code><br>
1326      * </td>
1327      * </tr>
1328      * </thead>
1329      * <tbody>
1330      * <tr>
1331      * <td style="vertical-align: top; width: 50%;"><code>Locale("de", "DE")</code><br>
1332      * </td>
1333      * <td style="vertical-align: top; width: 50%;"><code>java.class</code><br>
1334      * </td>
1335      * </tr>
1336      * <tr>
1337      * <td style="vertical-align: top; width: 50%;"><code>Locale("de", "DE")</code></td>
1338      * <td style="vertical-align: top; width: 50%;"><code>java.properties</code><br>
1339      * </td>
1340      * </tr>
1341      * <tr>
1342      * <td style="vertical-align: top; width: 50%;"><code>Locale("de")</code></td>
1343      * <td style="vertical-align: top; width: 50%;"><code>java.class</code></td>
1344      * </tr>
1345      * <tr>
1346      * <td style="vertical-align: top; width: 50%;"><code>Locale("de")</code></td>
1347      * <td style="vertical-align: top; width: 50%;"><code>java.properties</code></td>
1348      * </tr>
1349      * <tr>


< prev index next >