src/java.base/share/classes/java/util/ResourceBundle.java
changeset 58242 94bb65cb37d3
parent 54206 003cc64366da
child 58288 48e480e56aad
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
   510      * <blockquote>
   510      * <blockquote>
   511      * <code>(String) {@link #getObject(java.lang.String) getObject}(key)</code>.
   511      * <code>(String) {@link #getObject(java.lang.String) getObject}(key)</code>.
   512      * </blockquote>
   512      * </blockquote>
   513      *
   513      *
   514      * @param key the key for the desired string
   514      * @param key the key for the desired string
   515      * @exception NullPointerException if <code>key</code> is <code>null</code>
   515      * @throws    NullPointerException if <code>key</code> is <code>null</code>
   516      * @exception MissingResourceException if no object for the given key can be found
   516      * @throws    MissingResourceException if no object for the given key can be found
   517      * @exception ClassCastException if the object found for the given key is not a string
   517      * @throws    ClassCastException if the object found for the given key is not a string
   518      * @return the string for the given key
   518      * @return the string for the given key
   519      */
   519      */
   520     public final String getString(String key) {
   520     public final String getString(String key) {
   521         return (String) getObject(key);
   521         return (String) getObject(key);
   522     }
   522     }
   527      * <blockquote>
   527      * <blockquote>
   528      * <code>(String[]) {@link #getObject(java.lang.String) getObject}(key)</code>.
   528      * <code>(String[]) {@link #getObject(java.lang.String) getObject}(key)</code>.
   529      * </blockquote>
   529      * </blockquote>
   530      *
   530      *
   531      * @param key the key for the desired string array
   531      * @param key the key for the desired string array
   532      * @exception NullPointerException if <code>key</code> is <code>null</code>
   532      * @throws    NullPointerException if <code>key</code> is <code>null</code>
   533      * @exception MissingResourceException if no object for the given key can be found
   533      * @throws    MissingResourceException if no object for the given key can be found
   534      * @exception ClassCastException if the object found for the given key is not a string array
   534      * @throws    ClassCastException if the object found for the given key is not a string array
   535      * @return the string array for the given key
   535      * @return the string array for the given key
   536      */
   536      */
   537     public final String[] getStringArray(String key) {
   537     public final String[] getStringArray(String key) {
   538         return (String[]) getObject(key);
   538         return (String[]) getObject(key);
   539     }
   539     }
   545      * If not successful, and the parent resource bundle is not null,
   545      * If not successful, and the parent resource bundle is not null,
   546      * it calls the parent's <code>getObject</code> method.
   546      * it calls the parent's <code>getObject</code> method.
   547      * If still not successful, it throws a MissingResourceException.
   547      * If still not successful, it throws a MissingResourceException.
   548      *
   548      *
   549      * @param key the key for the desired object
   549      * @param key the key for the desired object
   550      * @exception NullPointerException if <code>key</code> is <code>null</code>
   550      * @throws    NullPointerException if <code>key</code> is <code>null</code>
   551      * @exception MissingResourceException if no object for the given key can be found
   551      * @throws    MissingResourceException if no object for the given key can be found
   552      * @return the object for the given key
   552      * @return the object for the given key
   553      */
   553      */
   554     public final Object getObject(String key) {
   554     public final Object getObject(String key) {
   555         Object obj = handleGetObject(key);
   555         Object obj = handleGetObject(key);
   556         if (obj == null) {
   556         if (obj == null) {
   839      * <blockquote>
   839      * <blockquote>
   840      * <code>getBundle(baseName, Locale.getDefault(), callerModule)</code>,
   840      * <code>getBundle(baseName, Locale.getDefault(), callerModule)</code>,
   841      * </blockquote>
   841      * </blockquote>
   842      *
   842      *
   843      * @param baseName the base name of the resource bundle, a fully qualified class name
   843      * @param baseName the base name of the resource bundle, a fully qualified class name
   844      * @exception java.lang.NullPointerException
   844      * @throws    java.lang.NullPointerException
   845      *     if <code>baseName</code> is <code>null</code>
   845      *     if <code>baseName</code> is <code>null</code>
   846      * @exception MissingResourceException
   846      * @throws    MissingResourceException
   847      *     if no resource bundle for the specified base name can be found
   847      *     if no resource bundle for the specified base name can be found
   848      * @return a resource bundle for the given base name and the default locale
   848      * @return a resource bundle for the given base name and the default locale
   849      *
   849      *
   850      * @see <a href="#default_behavior">Resource Bundle Search and Loading Strategy</a>
   850      * @see <a href="#default_behavior">Resource Bundle Search and Loading Strategy</a>
   851      * @see <a href="#resource-bundle-modules">Resource Bundles and Named Modules</a>
   851      * @see <a href="#resource-bundle-modules">Resource Bundles and Named Modules</a>
   913      *
   913      *
   914      * @param baseName
   914      * @param baseName
   915      *        the base name of the resource bundle, a fully qualified class name
   915      *        the base name of the resource bundle, a fully qualified class name
   916      * @param locale
   916      * @param locale
   917      *        the locale for which a resource bundle is desired
   917      *        the locale for which a resource bundle is desired
   918      * @exception NullPointerException
   918      * @throws    NullPointerException
   919      *        if <code>baseName</code> or <code>locale</code> is <code>null</code>
   919      *        if <code>baseName</code> or <code>locale</code> is <code>null</code>
   920      * @exception MissingResourceException
   920      * @throws    MissingResourceException
   921      *        if no resource bundle for the specified base name can be found
   921      *        if no resource bundle for the specified base name can be found
   922      * @return a resource bundle for the given base name and locale
   922      * @return a resource bundle for the given base name and locale
   923      *
   923      *
   924      * @see <a href="#default_behavior">Resource Bundle Search and Loading Strategy</a>
   924      * @see <a href="#default_behavior">Resource Bundle Search and Loading Strategy</a>
   925      * @see <a href="#resource-bundle-modules">Resource Bundles and Named Modules</a>
   925      * @see <a href="#resource-bundle-modules">Resource Bundles and Named Modules</a>
  1262      *
  1262      *
  1263      * @param baseName the base name of the resource bundle, a fully qualified class name
  1263      * @param baseName the base name of the resource bundle, a fully qualified class name
  1264      * @param locale the locale for which a resource bundle is desired
  1264      * @param locale the locale for which a resource bundle is desired
  1265      * @param loader the class loader from which to load the resource bundle
  1265      * @param loader the class loader from which to load the resource bundle
  1266      * @return a resource bundle for the given base name and locale
  1266      * @return a resource bundle for the given base name and locale
  1267      * @exception java.lang.NullPointerException
  1267      * @throws    java.lang.NullPointerException
  1268      *        if <code>baseName</code>, <code>locale</code>, or <code>loader</code> is <code>null</code>
  1268      *        if <code>baseName</code>, <code>locale</code>, or <code>loader</code> is <code>null</code>
  1269      * @exception MissingResourceException
  1269      * @throws    MissingResourceException
  1270      *        if no resource bundle for the specified base name can be found
  1270      *        if no resource bundle for the specified base name can be found
  1271      * @since 1.2
  1271      * @since 1.2
  1272      * @revised 9
  1272      * @revised 9
  1273      * @spec JPMS
  1273      * @spec JPMS
  1274      * @see <a href="#resource-bundle-modules">Resource Bundles and Named Modules</a>
  1274      * @see <a href="#resource-bundle-modules">Resource Bundles and Named Modules</a>
  2248     /**
  2248     /**
  2249      * Removes all resource bundles from the cache that have been loaded
  2249      * Removes all resource bundles from the cache that have been loaded
  2250      * by the given class loader.
  2250      * by the given class loader.
  2251      *
  2251      *
  2252      * @param loader the class loader
  2252      * @param loader the class loader
  2253      * @exception NullPointerException if <code>loader</code> is null
  2253      * @throws    NullPointerException if <code>loader</code> is null
  2254      * @since 1.6
  2254      * @since 1.6
  2255      * @see ResourceBundle.Control#getTimeToLive(String,Locale)
  2255      * @see ResourceBundle.Control#getTimeToLive(String,Locale)
  2256      */
  2256      */
  2257     public static final void clearCache(ClassLoader loader) {
  2257     public static final void clearCache(ClassLoader loader) {
  2258         Objects.requireNonNull(loader);
  2258         Objects.requireNonNull(loader);
  2269      * Gets an object for the given key from this resource bundle.
  2269      * Gets an object for the given key from this resource bundle.
  2270      * Returns null if this resource bundle does not contain an
  2270      * Returns null if this resource bundle does not contain an
  2271      * object for the given key.
  2271      * object for the given key.
  2272      *
  2272      *
  2273      * @param key the key for the desired object
  2273      * @param key the key for the desired object
  2274      * @exception NullPointerException if <code>key</code> is <code>null</code>
  2274      * @throws    NullPointerException if <code>key</code> is <code>null</code>
  2275      * @return the object for the given key, or null
  2275      * @return the object for the given key, or null
  2276      */
  2276      */
  2277     protected abstract Object handleGetObject(String key);
  2277     protected abstract Object handleGetObject(String key);
  2278 
  2278 
  2279     /**
  2279     /**
  2291      * @param key
  2291      * @param key
  2292      *        the resource <code>key</code>
  2292      *        the resource <code>key</code>
  2293      * @return <code>true</code> if the given <code>key</code> is
  2293      * @return <code>true</code> if the given <code>key</code> is
  2294      *        contained in this <code>ResourceBundle</code> or its
  2294      *        contained in this <code>ResourceBundle</code> or its
  2295      *        parent bundles; <code>false</code> otherwise.
  2295      *        parent bundles; <code>false</code> otherwise.
  2296      * @exception NullPointerException
  2296      * @throws    NullPointerException
  2297      *         if <code>key</code> is <code>null</code>
  2297      *         if <code>key</code> is <code>null</code>
  2298      * @since 1.6
  2298      * @since 1.6
  2299      */
  2299      */
  2300     public boolean containsKey(String key) {
  2300     public boolean containsKey(String key) {
  2301         if (key == null) {
  2301         if (key == null) {
  2596          * @param formats
  2596          * @param formats
  2597          *        the formats to be returned by the
  2597          *        the formats to be returned by the
  2598          *        <code>ResourceBundle.Control.getFormats</code> method
  2598          *        <code>ResourceBundle.Control.getFormats</code> method
  2599          * @return a <code>ResourceBundle.Control</code> supporting the
  2599          * @return a <code>ResourceBundle.Control</code> supporting the
  2600          *        specified <code>formats</code>
  2600          *        specified <code>formats</code>
  2601          * @exception NullPointerException
  2601          * @throws    NullPointerException
  2602          *        if <code>formats</code> is <code>null</code>
  2602          *        if <code>formats</code> is <code>null</code>
  2603          * @exception IllegalArgumentException
  2603          * @throws    IllegalArgumentException
  2604          *        if <code>formats</code> is unknown
  2604          *        if <code>formats</code> is unknown
  2605          */
  2605          */
  2606         public static final Control getControl(List<String> formats) {
  2606         public static final Control getControl(List<String> formats) {
  2607             if (formats.equals(Control.FORMAT_PROPERTIES)) {
  2607             if (formats.equals(Control.FORMAT_PROPERTIES)) {
  2608                 return SingleFormatControl.PROPERTIES_ONLY;
  2608                 return SingleFormatControl.PROPERTIES_ONLY;
  2631          *        the formats to be returned by the
  2631          *        the formats to be returned by the
  2632          *        <code>ResourceBundle.Control.getFormats</code> method
  2632          *        <code>ResourceBundle.Control.getFormats</code> method
  2633          * @return a <code>ResourceBundle.Control</code> supporting the
  2633          * @return a <code>ResourceBundle.Control</code> supporting the
  2634          *        specified <code>formats</code> with no fallback
  2634          *        specified <code>formats</code> with no fallback
  2635          *        <code>Locale</code> support
  2635          *        <code>Locale</code> support
  2636          * @exception NullPointerException
  2636          * @throws    NullPointerException
  2637          *        if <code>formats</code> is <code>null</code>
  2637          *        if <code>formats</code> is <code>null</code>
  2638          * @exception IllegalArgumentException
  2638          * @throws    IllegalArgumentException
  2639          *        if <code>formats</code> is unknown
  2639          *        if <code>formats</code> is unknown
  2640          */
  2640          */
  2641         public static final Control getNoFallbackControl(List<String> formats) {
  2641         public static final Control getNoFallbackControl(List<String> formats) {
  2642             if (formats.equals(Control.FORMAT_DEFAULT)) {
  2642             if (formats.equals(Control.FORMAT_DEFAULT)) {
  2643                 return NoFallbackControl.NO_FALLBACK;
  2643                 return NoFallbackControl.NO_FALLBACK;
  2677          * @param baseName
  2677          * @param baseName
  2678          *        the base name of the resource bundle, a fully qualified class
  2678          *        the base name of the resource bundle, a fully qualified class
  2679          *        name
  2679          *        name
  2680          * @return a <code>List</code> of <code>String</code>s containing
  2680          * @return a <code>List</code> of <code>String</code>s containing
  2681          *        formats for loading resource bundles.
  2681          *        formats for loading resource bundles.
  2682          * @exception NullPointerException
  2682          * @throws    NullPointerException
  2683          *        if <code>baseName</code> is null
  2683          *        if <code>baseName</code> is null
  2684          * @see #FORMAT_DEFAULT
  2684          * @see #FORMAT_DEFAULT
  2685          * @see #FORMAT_CLASS
  2685          * @see #FORMAT_CLASS
  2686          * @see #FORMAT_PROPERTIES
  2686          * @see #FORMAT_PROPERTIES
  2687          */
  2687          */
  2864          *        qualified class name
  2864          *        qualified class name
  2865          * @param locale
  2865          * @param locale
  2866          *        the locale for which a resource bundle is desired
  2866          *        the locale for which a resource bundle is desired
  2867          * @return a <code>List</code> of candidate
  2867          * @return a <code>List</code> of candidate
  2868          *        <code>Locale</code>s for the given <code>locale</code>
  2868          *        <code>Locale</code>s for the given <code>locale</code>
  2869          * @exception NullPointerException
  2869          * @throws    NullPointerException
  2870          *        if <code>baseName</code> or <code>locale</code> is
  2870          *        if <code>baseName</code> or <code>locale</code> is
  2871          *        <code>null</code>
  2871          *        <code>null</code>
  2872          */
  2872          */
  2873         public List<Locale> getCandidateLocales(String baseName, Locale locale) {
  2873         public List<Locale> getCandidateLocales(String baseName, Locale locale) {
  2874             if (baseName == null) {
  2874             if (baseName == null) {
  3032          *        unable to find any resource bundles (except for the
  3032          *        unable to find any resource bundles (except for the
  3033          *        base bundle)
  3033          *        base bundle)
  3034          * @return a <code>Locale</code> for the fallback search,
  3034          * @return a <code>Locale</code> for the fallback search,
  3035          *        or <code>null</code> if no further fallback search
  3035          *        or <code>null</code> if no further fallback search
  3036          *        is desired.
  3036          *        is desired.
  3037          * @exception NullPointerException
  3037          * @throws    NullPointerException
  3038          *        if <code>baseName</code> or <code>locale</code>
  3038          *        if <code>baseName</code> or <code>locale</code>
  3039          *        is <code>null</code>
  3039          *        is <code>null</code>
  3040          */
  3040          */
  3041         public Locale getFallbackLocale(String baseName, Locale locale) {
  3041         public Locale getFallbackLocale(String baseName, Locale locale) {
  3042             if (baseName == null) {
  3042             if (baseName == null) {
  3125          *        the flag to indicate bundle reloading; <code>true</code>
  3125          *        the flag to indicate bundle reloading; <code>true</code>
  3126          *        if reloading an expired resource bundle,
  3126          *        if reloading an expired resource bundle,
  3127          *        <code>false</code> otherwise
  3127          *        <code>false</code> otherwise
  3128          * @return the resource bundle instance,
  3128          * @return the resource bundle instance,
  3129          *        or <code>null</code> if none could be found.
  3129          *        or <code>null</code> if none could be found.
  3130          * @exception NullPointerException
  3130          * @throws    NullPointerException
  3131          *        if <code>bundleName</code>, <code>locale</code>,
  3131          *        if <code>bundleName</code>, <code>locale</code>,
  3132          *        <code>format</code>, or <code>loader</code> is
  3132          *        <code>format</code>, or <code>loader</code> is
  3133          *        <code>null</code>, or if <code>null</code> is returned by
  3133          *        <code>null</code>, or if <code>null</code> is returned by
  3134          *        {@link #toBundleName(String, Locale) toBundleName}
  3134          *        {@link #toBundleName(String, Locale) toBundleName}
  3135          * @exception IllegalArgumentException
  3135          * @throws    IllegalArgumentException
  3136          *        if <code>format</code> is unknown, or if the resource
  3136          *        if <code>format</code> is unknown, or if the resource
  3137          *        found for the given parameters contains malformed data.
  3137          *        found for the given parameters contains malformed data.
  3138          * @exception ClassCastException
  3138          * @throws    ClassCastException
  3139          *        if the loaded class cannot be cast to <code>ResourceBundle</code>
  3139          *        if the loaded class cannot be cast to <code>ResourceBundle</code>
  3140          * @exception IllegalAccessException
  3140          * @throws    IllegalAccessException
  3141          *        if the class or its nullary constructor is not
  3141          *        if the class or its nullary constructor is not
  3142          *        accessible.
  3142          *        accessible.
  3143          * @exception InstantiationException
  3143          * @throws    InstantiationException
  3144          *        if the instantiation of a class fails for some other
  3144          *        if the instantiation of a class fails for some other
  3145          *        reason.
  3145          *        reason.
  3146          * @exception ExceptionInInitializerError
  3146          * @throws    ExceptionInInitializerError
  3147          *        if the initialization provoked by this method fails.
  3147          *        if the initialization provoked by this method fails.
  3148          * @exception SecurityException
  3148          * @throws    SecurityException
  3149          *        If a security manager is present and creation of new
  3149          *        If a security manager is present and creation of new
  3150          *        instances is denied. See {@link Class#newInstance()}
  3150          *        instances is denied. See {@link Class#newInstance()}
  3151          *        for details.
  3151          *        for details.
  3152          * @exception IOException
  3152          * @throws    IOException
  3153          *        if an error occurred when reading resources using
  3153          *        if an error occurred when reading resources using
  3154          *        any I/O operations
  3154          *        any I/O operations
  3155          * @see java.util.spi.ResourceBundleProvider#getBundle(String, Locale)
  3155          * @see java.util.spi.ResourceBundleProvider#getBundle(String, Locale)
  3156          * @revised 9
  3156          * @revised 9
  3157          * @spec JPMS
  3157          * @spec JPMS
  3293          * @return the time (0 or a positive millisecond offset from the
  3293          * @return the time (0 or a positive millisecond offset from the
  3294          *        cached time) to get loaded bundles expired in the cache,
  3294          *        cached time) to get loaded bundles expired in the cache,
  3295          *        {@link #TTL_NO_EXPIRATION_CONTROL} to disable the
  3295          *        {@link #TTL_NO_EXPIRATION_CONTROL} to disable the
  3296          *        expiration control, or {@link #TTL_DONT_CACHE} to disable
  3296          *        expiration control, or {@link #TTL_DONT_CACHE} to disable
  3297          *        caching.
  3297          *        caching.
  3298          * @exception NullPointerException
  3298          * @throws    NullPointerException
  3299          *        if <code>baseName</code> or <code>locale</code> is
  3299          *        if <code>baseName</code> or <code>locale</code> is
  3300          *        <code>null</code>
  3300          *        <code>null</code>
  3301          */
  3301          */
  3302         public long getTimeToLive(String baseName, Locale locale) {
  3302         public long getTimeToLive(String baseName, Locale locale) {
  3303             if (baseName == null || locale == null) {
  3303             if (baseName == null || locale == null) {
  3348          * @param loadTime
  3348          * @param loadTime
  3349          *        the time when <code>bundle</code> was loaded and put
  3349          *        the time when <code>bundle</code> was loaded and put
  3350          *        in the cache
  3350          *        in the cache
  3351          * @return <code>true</code> if the expired bundle needs to be
  3351          * @return <code>true</code> if the expired bundle needs to be
  3352          *        reloaded; <code>false</code> otherwise.
  3352          *        reloaded; <code>false</code> otherwise.
  3353          * @exception NullPointerException
  3353          * @throws    NullPointerException
  3354          *        if <code>baseName</code>, <code>locale</code>,
  3354          *        if <code>baseName</code>, <code>locale</code>,
  3355          *        <code>format</code>, <code>loader</code>, or
  3355          *        <code>format</code>, <code>loader</code>, or
  3356          *        <code>bundle</code> is <code>null</code>
  3356          *        <code>bundle</code> is <code>null</code>
  3357          */
  3357          */
  3358         public boolean needsReload(String baseName, Locale locale,
  3358         public boolean needsReload(String baseName, Locale locale,
  3435          *        qualified class name
  3435          *        qualified class name
  3436          * @param locale
  3436          * @param locale
  3437          *        the locale for which a resource bundle should be
  3437          *        the locale for which a resource bundle should be
  3438          *        loaded
  3438          *        loaded
  3439          * @return the bundle name for the resource bundle
  3439          * @return the bundle name for the resource bundle
  3440          * @exception NullPointerException
  3440          * @throws    NullPointerException
  3441          *        if <code>baseName</code> or <code>locale</code>
  3441          *        if <code>baseName</code> or <code>locale</code>
  3442          *        is <code>null</code>
  3442          *        is <code>null</code>
  3443          * @see java.util.spi.AbstractResourceBundleProvider#toBundleName(String, Locale)
  3443          * @see java.util.spi.AbstractResourceBundleProvider#toBundleName(String, Locale)
  3444          */
  3444          */
  3445         public String toBundleName(String baseName, Locale locale) {
  3445         public String toBundleName(String baseName, Locale locale) {
  3493          * @param bundleName
  3493          * @param bundleName
  3494          *        the bundle name
  3494          *        the bundle name
  3495          * @param suffix
  3495          * @param suffix
  3496          *        the file type suffix
  3496          *        the file type suffix
  3497          * @return the converted resource name
  3497          * @return the converted resource name
  3498          * @exception NullPointerException
  3498          * @throws    NullPointerException
  3499          *         if {@code bundleName} or {@code suffix}
  3499          *         if {@code bundleName} or {@code suffix}
  3500          *         is {@code null}
  3500          *         is {@code null}
  3501          */
  3501          */
  3502         public final String toResourceName(String bundleName, String suffix) {
  3502         public final String toResourceName(String bundleName, String suffix) {
  3503             StringBuilder sb = new StringBuilder(bundleName.length() + 1 + suffix.length());
  3503             StringBuilder sb = new StringBuilder(bundleName.length() + 1 + suffix.length());