Top Inners Fields Constructors Methods
sun.util.resources

public abstract Class Bundles

extends Object
Class Inheritance
Imports
java.lang.ref.ReferenceQueue, .SoftReference, java.security.AccessController, .PrivilegedAction, java.util.Enumeration, .Iterator, .List, .Locale, .MissingResourceException, .Objects, .ResourceBundle, .ServiceConfigurationError, .ServiceLoader, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.spi.ResourceBundleProvider, jdk.internal.access.JavaUtilResourceBundleAccess, .SharedSecrets

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Bundles.BundleReference

References to bundles are soft references so that they can be garbage collected when they have no hard references.

private static class
Bundles.CacheKey

Key used for cached resource bundles.

private static interface
Bundles.CacheKeyReference

The common interface to get a CacheKey in LoaderReference and BundleReference.

public static interface
Bundles.Strategy

The Strategy interface defines methods that are called by Bundles.of during the resource bundle loading process.

Field Summary

Modifier and TypeField and Description
private static final JavaUtilResourceBundleAccess
private static final ConcurrentMap<Bundles.CacheKey, Bundles.BundleReference>
cacheList

The cache is a map from cache keys (with bundle base name, locale, and class loader) to either a resource bundle or NONEXISTENT_BUNDLE wrapped by a BundleReference.

private static final int
INITIAL_CACHE_SIZE

initial size of the bundle cache

private static final ResourceBundle
NONEXISTENT_BUNDLE

constant indicating that no resource bundle exists

private static final ReferenceQueue<Object>
referenceQueue

Queue for reference objects referring to class loaders or bundles.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
private static ResourceBundle

Returns:

the ResourceBundle found in the cache or null
findBundleInCache
(Bundles.CacheKey
the key to look up the cache
cacheKey
)

Finds a bundle in the cache.

private static ResourceBundle
findBundleOf(Bundles.CacheKey cacheKey, Bundles.Strategy strategy, String baseName, List<Locale> candidateLocales, int index)

private static boolean
private static ResourceBundle
loadBundleFromProviders(String baseName, Locale locale, ServiceLoader<ResourceBundleProvider> providers, Bundles.CacheKey cacheKey)

Loads ResourceBundle from service providers.

private static ResourceBundle
loadBundleOf(String baseName, Locale targetLocale, Bundles.Strategy strategy)

public static ResourceBundle
of(String baseName, Locale locale, Bundles.Strategy strategy)

private static ResourceBundle

Returns:

the ResourceBundle for the cacheKey; if someone has put the bundle before this call, the one found in the cache is returned.
putBundleInCache
(Bundles.CacheKey
the key for the resource bundle
cacheKey
,
ResourceBundle
the resource bundle to be put in the cache
bundle
)

Put a new bundle in the cache.

private static void
throwMissingResourceException(String baseName, Locale locale, Throwable cause)

Throw a MissingResourceException with proper message

public static String

Returns:

the other bundle name, or the same name for non-legacy ISO languages
toOtherBundleName
(String
ResourceBundle base name
baseName
,
String
ResourceBundle bundle name
bundleName
,
Locale
locale
locale
)

Generates the other bundle name for languages that have changed, i.e. "he", "id", and "yi"

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bundleAccessback to summary
private static final JavaUtilResourceBundleAccess bundleAccess
cacheListback to summary
private static final ConcurrentMap<Bundles.CacheKey, Bundles.BundleReference> cacheList

The cache is a map from cache keys (with bundle base name, locale, and class loader) to either a resource bundle or NONEXISTENT_BUNDLE wrapped by a BundleReference. The cache is a ConcurrentMap, allowing the cache to be searched concurrently by multiple threads. This will also allow the cache keys to be reclaimed along with the ClassLoaders they reference. This variable would be better named "cache", but we keep the old name for compatibility with some workarounds for bug 4212439.

INITIAL_CACHE_SIZEback to summary
private static final int INITIAL_CACHE_SIZE

initial size of the bundle cache

NONEXISTENT_BUNDLEback to summary
private static final ResourceBundle NONEXISTENT_BUNDLE

constant indicating that no resource bundle exists

referenceQueueback to summary
private static final ReferenceQueue<Object> referenceQueue

Queue for reference objects referring to class loaders or bundles.

Constructor Detail

Bundlesback to summary
private Bundles()

Method Detail

cleanupCacheback to summary
private static void cleanupCache()
findBundleInCacheback to summary
private static ResourceBundle findBundleInCache(Bundles.CacheKey cacheKey)

Finds a bundle in the cache.

Parameters
cacheKey:Bundles.CacheKey

the key to look up the cache

Returns:ResourceBundle

the ResourceBundle found in the cache or null

findBundleOfback to summary
private static ResourceBundle findBundleOf(Bundles.CacheKey cacheKey, Bundles.Strategy strategy, String baseName, List<Locale> candidateLocales, int index)
isValidBundleback to summary
private static boolean isValidBundle(ResourceBundle bundle)
loadBundleFromProvidersback to summary
private static ResourceBundle loadBundleFromProviders(String baseName, Locale locale, ServiceLoader<ResourceBundleProvider> providers, Bundles.CacheKey cacheKey)

Loads ResourceBundle from service providers.

Annotations
@SuppressWarnings:removal
loadBundleOfback to summary
private static ResourceBundle loadBundleOf(String baseName, Locale targetLocale, Bundles.Strategy strategy)
ofback to summary
public static ResourceBundle of(String baseName, Locale locale, Bundles.Strategy strategy)
putBundleInCacheback to summary
private static ResourceBundle putBundleInCache(Bundles.CacheKey cacheKey, ResourceBundle bundle)

Put a new bundle in the cache.

Parameters
cacheKey:Bundles.CacheKey

the key for the resource bundle

bundle:ResourceBundle

the resource bundle to be put in the cache

Returns:ResourceBundle

the ResourceBundle for the cacheKey; if someone has put the bundle before this call, the one found in the cache is returned.

throwMissingResourceExceptionback to summary
private static void throwMissingResourceException(String baseName, Locale locale, Throwable cause)

Throw a MissingResourceException with proper message

toOtherBundleNameback to summary
public static String toOtherBundleName(String baseName, String bundleName, Locale locale)

Generates the other bundle name for languages that have changed, i.e. "he", "id", and "yi"

Parameters
baseName:String

ResourceBundle base name

bundleName:String

ResourceBundle bundle name

locale:Locale

locale

Returns:String

the other bundle name, or the same name for non-legacy ISO languages

sun.util.resources back to summary

private Class Bundles.BundleReference

extends SoftReference<ResourceBundle>
implements CacheKeyReference
Class Inheritance
All Implemented Interfaces
sun.util.resources.Bundles.CacheKeyReference

References to bundles are soft references so that they can be garbage collected when they have no hard references.

Field Summary

Modifier and TypeField and Description
private final Bundles.CacheKey

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Bundles.CacheKey
Inherited from java.lang.ref.SoftReference:
get

Field Detail

cacheKeyback to summary
private final Bundles.CacheKey cacheKey

Constructor Detail

BundleReferenceback to summary
pack-priv BundleReference(ResourceBundle referent, ReferenceQueue<Object> q, Bundles.CacheKey key)

Method Detail

getCacheKeyback to summary
public Bundles.CacheKey getCacheKey()

Implements sun.util.resources.Bundles.CacheKeyReference.getCacheKey.

Annotations
@Override
sun.util.resources back to summary

private Class Bundles.CacheKey

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable

Key used for cached resource bundles. The key checks the base name, the locale, and the class loader to determine if the resource is a match to the requested one. The loader may be null, but the base name and the locale must have a non-null value.

Field Summary

Modifier and TypeField and Description
private Throwable
private int
private Locale
private String
private ServiceLoader<ResourceBundleProvider>

Constructor Summary

AccessConstructor and Description
pack-priv
CacheKey(String baseName, Locale locale)

Method Summary

Modifier and TypeMethod and Description
private void
public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private Throwable
pack-priv Locale
pack-priv String
pack-priv ServiceLoader<ResourceBundleProvider>
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
private void
pack-priv Bundles.CacheKey
setLocale(Locale locale)

pack-priv Bundles.CacheKey
setName(String baseName)

pack-priv void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

causeback to summary
private Throwable cause
hashCodeCacheback to summary
private int hashCodeCache
localeback to summary
private Locale locale
nameback to summary
private String name
providersback to summary
private ServiceLoader<ResourceBundleProvider> providers

Constructor Detail

CacheKeyback to summary
pack-priv CacheKey(String baseName, Locale locale)

Method Detail

calculateHashCodeback to summary
private void calculateHashCode()
cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getCauseback to summary
private Throwable getCause()
getLocaleback to summary
pack-priv Locale getLocale()
getNameback to summary
pack-priv String getName()
getProvidersback to summary
pack-priv ServiceLoader<ResourceBundleProvider> getProviders()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
setCauseback to summary
private void setCause(Throwable cause)
setLocaleback to summary
pack-priv Bundles.CacheKey setLocale(Locale locale)
setNameback to summary
pack-priv Bundles.CacheKey setName(String baseName)
setProvidersback to summary
pack-priv void setProviders(ServiceLoader<ResourceBundleProvider> providers)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
sun.util.resources back to summary

private Interface Bundles.CacheKeyReference

Known Direct Implementers
sun.util.resources.Bundles.BundleReference

The common interface to get a CacheKey in LoaderReference and BundleReference.

Method Summary

Modifier and TypeMethod and Description
public Bundles.CacheKey

Method Detail

getCacheKeyback to summary
public Bundles.CacheKey getCacheKey()
sun.util.resources back to summary

public Interface Bundles.Strategy

Known Direct Implementers
sun.util.resources.LocaleData.LocaleDataStrategy

The Strategy interface defines methods that are called by Bundles.of during the resource bundle loading process.

Method Summary

Modifier and TypeMethod and Description
public List<Locale>
getCandidateLocales(String baseName, Locale locale)

Returns a list of locales to be looked up for bundle loading.

public Class<? extends ResourceBundleProvider>
getResourceBundleProviderType(String baseName, Locale locale)

Returns the service provider type for the given baseName and locale, or null if no service providers should be used.

public String
toBundleName(String baseName, Locale locale)

Returns the bundle name for the given baseName and locale.

Method Detail

getCandidateLocalesback to summary
public List<Locale> getCandidateLocales(String baseName, Locale locale)

Returns a list of locales to be looked up for bundle loading.

getResourceBundleProviderTypeback to summary
public Class<? extends ResourceBundleProvider> getResourceBundleProviderType(String baseName, Locale locale)

Returns the service provider type for the given baseName and locale, or null if no service providers should be used.

toBundleNameback to summary
public String toBundleName(String baseName, Locale locale)

Returns the bundle name for the given baseName and locale.