The loader resolves configuration data of the provided configuration interface with a portion of application's persistent configuration identified by configuration path. The portion of the persistent configuration is identified by configuration path.
The loader must support persistent configuration stored in META-INF/jakarta-config.properties
file found on the classpath that follows a format that is recognized by the class Properties.
In the following example the MyConfigurationRelatedObject is the configuration interface to be
resolved. An instance of the configuration interface is created by the Loader:
Loader loader = Loader.bootstrap(); MyConfigurationRelatedObject object = null; try { object = loader .path("my.configuration") .load(MyConfigurationRelatedObject.class); } catch (NoSuchObjectException noSuchObjectException) { // object is absent } catch (ConfigException configException) { // a loading-related error occurred }
Implementations of the methods in this class must be:
- idempotent
- safe for concurrent use by multiple threads
- must not return
null.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Loaderstatic Loaderbootstrap(ClassLoader classLoader) Bootstraps aLoaderinstance for subsequent usage.<T> TLoads a configuration-related object of the suppliedtypeand returns it.<T> TLoads a configuration-related object of the suppliedtypeand returns it.Return a new instance of aLoaderwith the configuration path set.
-
Method Details
-
load
Loads a configuration-related object of the suppliedtypeand returns it.Note: The rules governing how it is determined whether any given configuration-related object is "of the supplied
type" are currently wholly undefined.Implementations of this method may or may not return a determinate value.
- Type Parameters:
T- the type of object to load- Parameters:
type- the type of object to load; must not benull- Returns:
- the loaded object; never
null - Throws:
NoSuchObjectException- if the invocation was sound but the requested object was absentConfigException- if the invocation was sound but the object could not be loaded for any reason not related to absenceIllegalArgumentException- if the supliedtypewas invalid for any reasonNullPointerException- if the suppliedtypewasnull
-
load
Loads a configuration-related object of the suppliedtypeand returns it.Note: The rules governing how it is determined whether any given configuration-related object is "of the supplied
type" are currently wholly undefined.Implementations of this method may or may not return a determinate value.
- Type Parameters:
T- the type of object to load- Parameters:
type- the type of object to load; must not benull- Returns:
- the loaded object; never
null - Throws:
NoSuchObjectException- if the invocation was sound but the requested object was absentConfigException- if the invocation was sound but the object could not be loaded for any reason not related to absenceIllegalArgumentException- if the supliedtypewas invalid for any reasonNullPointerException- if the suppliedtypewasnull
-
path
Return a new instance of aLoaderwith the configuration path set. The configuration path identifies where the configuration relevant for the annotated configuration class is found in a given application's persistent configuration.The configuration path uses the dot symbol as a separator.
For instance, if the persistent configuration contains
my.configuration.user=tester
the configuration path for the configuration portionuser=testerwould bemy.configuration.- Parameters:
path- a configuration path.- Returns:
- a new instance of the
Loaderclass with a configured path. - See Also:
-
bootstrap
Bootstraps aLoaderinstance for subsequent usage using the context classloader.This method never returns
null.This method is idempotent.
This method is safe for concurrent use by multiple threads.
This method may or may not return a determinate value. See
bootstrap(ClassLoader)for details.Except as possibly noted above, the observable behavior of this method is specified to be identical to that of the
bootstrap(ClassLoader)method.- Returns:
- a
Loader; nevernull - Throws:
ServiceConfigurationError- if bootstrapping failed because of aServiceLoader.load(Class, ClassLoader)orServiceLoader.findFirst()problemConfigException- if bootstrapping failed because of aload(Class)problem- See Also:
-
bootstrap
Bootstraps aLoaderinstance for subsequent usage.The bootstrap process proceeds as follows:
- A primordial
Loaderis located with observable effects equal to those resulting from executing the following code:Loader loader = ServiceLoader.load(Loader.class, classLoader) .findFirst() .orElseThrow(NoSuchObjectException::new);
- The
load(Class)method is invoked on the resultingLoaderwithLoader.classas its sole argument.- If the invocation throws a
NoSuchObjectException, the primordialLoaderis returned. - If the invocation returns a
Loader, thatLoaderis returned.
- If the invocation throws a
This method may or may not return a determinate value depending on the implementation of the
Loaderloaded in step 2 above.Note: The implementation of this method may change without notice between any two versions of this specification. The requirements described above, however, will be honored in any minor version of this specification within a given major version.
- Parameters:
classLoader- theClassLoaderused to locate service provider files; may benullto indicate the system classloader (or bootstrap class loader) in accordance with the contract of theServiceLoader.load(Class, ClassLoader)method; often is the return value of an invocation ofThread.currentThread().getContextClassLoader()- Returns:
- a
Loader; nevernull - Throws:
ServiceConfigurationError- if bootstrapping failed because of aServiceLoader.load(Class, ClassLoader)orServiceLoader.findFirst()problemConfigException- if bootstrapping failed because of aload(Class)problem
- A primordial
-