Top Description Inners Fields Constructors Methods
org.hibernate.validator.resourceloading

public Class PlatformResourceBundleLocator

extends Object
implements ResourceBundleLocator
Class Inheritance
All Implemented Interfaces
org.hibernate.validator.spi.resourceloading.ResourceBundleLocator
Static Imports
org.hibernate.validator.internal.util.logging.Messages.MESSAGES

A resource bundle locator, that loads resource bundles by invoking ResourceBundle.loadBundle(String, Local, ClassLoader).

This locator is also able to load all property files of a given name (in case there are multiple with the same name on the classpath) and aggregates them into a ResourceBundle.

Authors
Hardy Ferentschik, Gunnar Morling, Guillaume Smet

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final boolean
private final String
private final ClassLoader
private static final Log
private final Map<Locale, ResourceBundle>
private static final boolean

Constructor Summary

AccessConstructor and Description
public
PlatformResourceBundleLocator(String
the name of the bundle to load
bundleName
)

Creates a new PlatformResourceBundleLocator.

public
PlatformResourceBundleLocator(String
the name of the bundle to load
bundleName
,
ClassLoader
the classloader to be used for loading the bundle. If null, the current thread context classloader and finally Hibernate Validator's own classloader will be used for loading the specified bundle.
classLoader
)

Creates a new PlatformResourceBundleLocator.

public
PlatformResourceBundleLocator(String
the name of the bundle to load
bundleName
,
ClassLoader
the classloader to be used for loading the bundle. If null, the current thread context classloader and finally Hibernate Validator's own classloader will be used for loading the specified bundle.
classLoader
,
boolean
Whether or not all resource bundles of a given name should be loaded and potentially merged.
aggregate
)

Creates a new PlatformResourceBundleLocator.

public
PlatformResourceBundleLocator(String
the name of the bundle to load
bundleName
,
Set<Locale>
the set of locales to initialize at bootstrap
localesToInitialize
)

Creates a new PlatformResourceBundleLocator.

public
PlatformResourceBundleLocator(String
the name of the bundle to load
bundleName
,
Set<Locale>
the set of locales to initialize at bootstrap
localesToInitialize
,
ClassLoader
the classloader to be used for loading the bundle. If null, the current thread context classloader and finally Hibernate Validator's own classloader will be used for loading the specified bundle.
classLoader
)

Creates a new PlatformResourceBundleLocator.

public
PlatformResourceBundleLocator(String
the name of the bundle to load
bundleName
,
Set<Locale>
the set of locales to initialize at bootstrap
localesToInitialize
,
ClassLoader
the classloader to be used for loading the bundle. If null, the current thread context classloader and finally Hibernate Validator's own classloader will be used for loading the specified bundle.
classLoader
,
boolean
Whether or not all resource bundles of a given name should be loaded and potentially merged.
aggregate
)

Creates a new PlatformResourceBundleLocator.

Method Summary

Modifier and TypeMethod and Description
private static boolean
determineAvailabilityOfResourceBundleControl()

Check whether ResourceBundle.Control is available, which is needed for bundle aggregation.

private ResourceBundle
public ResourceBundle

Returns:

the resource bundle or null if none is found.
getResourceBundle
(Locale
The locale of the bundle to load.
locale
)

Implements org.hibernate.validator.spi.resourceloading.ResourceBundleLocator.getResourceBundle.

Search current thread classloader for the resource bundle.
private ResourceBundle
loadBundle(ClassLoader classLoader, Locale locale, String message)

private static <T> T
run(PrivilegedAction<T> action)

Runs the given privileged action, using a privileged block if required.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aggregateback to summary
private final boolean aggregate
bundleNameback to summary
private final String bundleName
classLoaderback to summary
private final ClassLoader classLoader
LOGback to summary
private static final Log LOG
preloadedResourceBundlesback to summary
private final Map<Locale, ResourceBundle> preloadedResourceBundles
Annotations
@Immutable
RESOURCE_BUNDLE_CONTROL_INSTANTIABLEback to summary
private static final boolean RESOURCE_BUNDLE_CONTROL_INSTANTIABLE

Constructor Detail

PlatformResourceBundleLocatorback to summary
public PlatformResourceBundleLocator(String bundleName)

Creates a new PlatformResourceBundleLocator.

Parameters
bundleName:String

the name of the bundle to load

PlatformResourceBundleLocatorback to summary
public PlatformResourceBundleLocator(String bundleName, ClassLoader classLoader)

Creates a new PlatformResourceBundleLocator.

Parameters
bundleName:String

the name of the bundle to load

classLoader:ClassLoader

the classloader to be used for loading the bundle. If null, the current thread context classloader and finally Hibernate Validator's own classloader will be used for loading the specified bundle.

Since
5.2
PlatformResourceBundleLocatorback to summary
public PlatformResourceBundleLocator(String bundleName, ClassLoader classLoader, boolean aggregate)

Creates a new PlatformResourceBundleLocator.

Parameters
bundleName:String

the name of the bundle to load

classLoader:ClassLoader

the classloader to be used for loading the bundle. If null, the current thread context classloader and finally Hibernate Validator's own classloader will be used for loading the specified bundle.

aggregate:boolean

Whether or not all resource bundles of a given name should be loaded and potentially merged.

Since
5.2
PlatformResourceBundleLocatorback to summary
public PlatformResourceBundleLocator(String bundleName, Set<Locale> localesToInitialize)

Creates a new PlatformResourceBundleLocator.

Parameters
bundleName:String

the name of the bundle to load

localesToInitialize:Set<Locale>

the set of locales to initialize at bootstrap

Annotations
@Incubating
Since
6.1.1
PlatformResourceBundleLocatorback to summary
public PlatformResourceBundleLocator(String bundleName, Set<Locale> localesToInitialize, ClassLoader classLoader)

Creates a new PlatformResourceBundleLocator.

Parameters
bundleName:String

the name of the bundle to load

localesToInitialize:Set<Locale>

the set of locales to initialize at bootstrap

classLoader:ClassLoader

the classloader to be used for loading the bundle. If null, the current thread context classloader and finally Hibernate Validator's own classloader will be used for loading the specified bundle.

Annotations
@Incubating
Since
6.1.1
PlatformResourceBundleLocatorback to summary
public PlatformResourceBundleLocator(String bundleName, Set<Locale> localesToInitialize, ClassLoader classLoader, boolean aggregate)

Creates a new PlatformResourceBundleLocator.

Parameters
bundleName:String

the name of the bundle to load

localesToInitialize:Set<Locale>

the set of locales to initialize at bootstrap

classLoader:ClassLoader

the classloader to be used for loading the bundle. If null, the current thread context classloader and finally Hibernate Validator's own classloader will be used for loading the specified bundle.

aggregate:boolean

Whether or not all resource bundles of a given name should be loaded and potentially merged.

Annotations
@Incubating
Since
6.1

Method Detail

determineAvailabilityOfResourceBundleControlback to summary
private static boolean determineAvailabilityOfResourceBundleControl()

Check whether ResourceBundle.Control is available, which is needed for bundle aggregation. If not, we'll skip resource aggregation.

It is *not* available

  • in the Google App Engine environment
  • when running HV as Java 9 named module (which would be the case when adding a module-info descriptor to the HV JAR)
See Also
GAE JRE whitelist, HV-1023, ResourceBundle.Control
doGetResourceBundleback to summary
private ResourceBundle doGetResourceBundle(Locale locale)
getResourceBundleback to summary
public ResourceBundle getResourceBundle(Locale locale)

Implements org.hibernate.validator.spi.resourceloading.ResourceBundleLocator.getResourceBundle.

Search current thread classloader for the resource bundle. If not found, search validator (this) classloader.

Parameters
locale:Locale

The locale of the bundle to load.

Returns:ResourceBundle

the resource bundle or null if none is found.

Annotations
@Override
loadBundleback to summary
private ResourceBundle loadBundle(ClassLoader classLoader, Locale locale, String message)
runback to summary
private static <T> T run(PrivilegedAction<T> action)

Runs the given privileged action, using a privileged block if required.

Note

This must never be changed into a publicly available method to avoid execution of arbitrary privileged actions within HV's protection domain.

Annotations
@IgnoreForbiddenApisErrors
reason:SecurityManager is deprecated in JDK17
org.hibernate.validator.resourceloading back to summary

private Class PlatformResourceBundleLocator.AggregateResourceBundleControl

extends Control
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final ResourceBundle.Control
Inherited from java.util.ResourceBundle.Control:
FORMAT_CLASSFORMAT_DEFAULTFORMAT_PROPERTIESTTL_DONT_CACHETTL_NO_EXPIRATION_CONTROL

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static List<ResourceBundle>
load(String resourceName, ClassLoader loader)

public ResourceBundle
newBundle(String
the base bundle name of the resource bundle, a fully qualified class name
baseName
,
Locale
the locale for which the resource bundle should be instantiated
locale
,
String
the resource bundle format to be loaded
format
,
ClassLoader
the ClassLoader to use to load the bundle
loader
,
boolean
the flag to indicate bundle reloading; true if reloading an expired resource bundle, false otherwise
reload
)

Overrides java.util.ResourceBundle.Control.newBundle.

Instantiates a resource bundle for the given bundle name of the given format and locale, using the given class loader if necessary.
Inherited from java.util.ResourceBundle.Control:
getCandidateLocalesgetControlgetFallbackLocalegetFormatsgetNoFallbackControlgetTimeToLiveneedsReloadtoBundleNametoResourceName

Field Detail

CONTROLback to summary
private static final ResourceBundle.Control CONTROL

Constructor Detail

AggregateResourceBundleControlback to summary
private AggregateResourceBundleControl()

Method Detail

loadback to summary
private static List<ResourceBundle> load(String resourceName, ClassLoader loader) throws IOException
newBundleback to summary
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException

Overrides java.util.ResourceBundle.Control.newBundle.

Doc from java.util.ResourceBundle.Control.newBundle.

Instantiates a resource bundle for the given bundle name of the given format and locale, using the given class loader if necessary. This method returns null if there is no resource bundle available for the given parameters. If a resource bundle can't be instantiated due to an unexpected error, the error must be reported by throwing an Error or Exception rather than simply returning null.

If the reload flag is true, it indicates that this method is being called because the previously loaded resource bundle has expired.

Parameters
baseName:String

the base bundle name of the resource bundle, a fully qualified class name

locale:Locale

the locale for which the resource bundle should be instantiated

format:String

the resource bundle format to be loaded

loader:ClassLoader

the ClassLoader to use to load the bundle

reload:boolean

the flag to indicate bundle reloading; true if reloading an expired resource bundle, false otherwise

Returns:ResourceBundle

the resource bundle instance, or null if none could be found.

Annotations
@Override
Exceptions
IllegalAccessException:
if the class or its nullary constructor is not accessible.
InstantiationException:
if the instantiation of a class fails for some other reason.
IOException:
if an error occurred when reading resources using any I/O operations