- All Superinterfaces:
OptionalSupplier<T>
,Supplier<T>
- All Known Implementing Classes:
DefaultLoader
OptionalSupplier
that supplies an
environmental object, and can load others.
Note: Loader
implementations are
expected to be immutable with respect to the methods exposed by
this interface. All methods in this interface that have a Loader
-typed return type require their implementations to return a
new Loader
.
The presence of the @OverridingDiscouraged
annotation on a
method means that undefined behavior may result if an
implementation of this interface provides an alternate
implementation of the method in question.
- Author:
- Laird Nelson
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.microbean.invoke.OptionalSupplier
OptionalSupplier.Determinism
-
Method Summary
Modifier and TypeMethodDescriptiondefault @Experimental Path<? extends Type>
Experimental; do not use.default <P> @Experimental Path<P>
absolutePath
(Path<P> path) default <L extends Loader<?>>
LCasts thisLoader
appropriately and returns it, usually so that an implementation's implementation-specific methods can be accessed.default boolean
isRoot()
Returnstrue
if and only if thisLoader
is the rootLoader
, which occurs only when the return value ofthis.parent() == this
.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.<U> Loader<U>
default <U> Loader<U>
load
(Qualifiers<? extends String, ?> qualifiers, Class<U> type) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
load
(Qualifiers<? extends String, ?> qualifiers, Type type) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
load
(Qualifiers<? extends String, ?> qualifiers, org.microbean.type.JavaType.Token<U> type) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
load
(org.microbean.type.JavaType.Token<U> type) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.default <U> Loader<U>
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.static Loader<?>
loader()
Bootstraps and returns aLoader
.default Loader<?>
Returns an ancestralLoader
, derived from and possibly identical to thisLoader
, that is suitable for a transliterated and absolute version of the suppliedpath
, particularly for cases where, during the execution of theload(Path)
method, aLoader
must be supplied to some other class.Loader<?>
parent()
path()
default Loader<?>
root()
transliterate
(Path<U> path) Transliterates the supplied absolutePath
into some otherPath
, whose meaning is the same, but whose representation may be different, that will be used instead.Methods inherited from interface org.microbean.invoke.OptionalSupplier
determinism, exceptionally, get, handle, ifPresent, ifPresentOrElse, optional, optional, optional, orElse, orElseGet, orElseThrow, orElseThrow, stream
-
Method Details
-
parent
Returns theLoader
that is the parent of thisLoader
.The root
Loader
is defined to be the only one whoseparent()
method returns itself. It follows that in general aLoader
implementation should not returnthis
. SeeisRoot()
for details.- Returns:
- the
Loader
that is the parent of thisLoader
; notthis
in almost all circumstances - See Also:
- Idempotency:
- Implementations of this method must be idempotent and deterministic.
- Nullability:
- Implementations of this method must not return
null
. - Thread Safety:
- Implementations of this method must be safe for concurrent use by multiple threads.
-
path
Returns thePath
with which thisLoader
was created.The
Path
that is returned by an implementation of this method is not guaranteed to be absolute.The
Path
that is returned by an implementation of this method must be equal to a transliterated version of thePath
that was supplied to theload(Path)
method of thisLoader
's parent that resulted in thisLoader
's creation.- Returns:
- the non-
null
Path
with which thisLoader
was created - See Also:
- Idempotency:
- Implementations of this method must be idempotent and deterministic.
- Nullability:
- Implementations of this method must not return
null
. - Thread Safety:
- Implementations of this method must be safe for concurrent use by multiple threads.
-
absolutePath
Experimental; do not use.- Returns:
- an absolute
Path
- Throws:
NullPointerException
- ifpath()
orparent()
is implemented incorrectly- See Also:
- Idempotency:
- This method is, and its overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, and its overrides must not,
return
null
. - Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
absolutePath
- Type Parameters:
P
- the type of the path- Parameters:
path
- aPath
; must not benull
- Returns:
- an absolute
Path
- Throws:
NullPointerException
- ifpath
isnull
or if #parent()} is implemented incorrectly- Idempotency:
- This method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Uses the addressing information encoded in the suppliedPath
to load and return theLoader
logically found at that location, following additional contractual requirements defined below.Any
Loader
returned by an implementation of this method:- must not be
null
- must implement its
get()
method and itsdeterminism()
method to indicate the transitory or permanent presence or absence of any value it might supply
The default implementations of all other methods in this interface named
load
call this method.- Type Parameters:
U
- the type of the environmental object the returnedLoader
can supply- Parameters:
path
- thePath
(perhaps only partially) identifying theLoader
to load; must not benull
; may be absolute or relative (in which case it will be appended to thisLoader
'sPath
)- Returns:
- a
Loader
for the suppliedPath
; must not benull
, but may implement itsget()
method and itsdeterminism()
method to indicate the transitory or permanent presence or absence of any value it might supply - Throws:
NullPointerException
- ifpath
isnull
ClassCastException
- if the implementation is implemented improperly- See Also:
- must not be
-
load
@OverridingDiscouraged default <U> Loader<U> load(Qualifiers<? extends String, ?> qualifiers, Type type) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
qualifiers
- the path'sQualifiers
; must not benull
type
- the path'sType
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- the path'sType
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- the path'sType
; must not benull
name
- the name of the lastPath.Element
in thePath
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- the path'sType
; must not benull
names
- the sequence of names forming thePath
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- the path'sType
; must not benull
names
- the sequence of names forming thePath
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(Qualifiers<? extends String, ?> qualifiers, org.microbean.type.JavaType.Token<U> type) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
qualifiers
- the path'sQualifiers
; must not benull
type
- aJavaType.Token
representing the path'sType
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- aJavaType.Token
representing the path'sType
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(org.microbean.type.JavaType.Token<U> type, String name) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- aJavaType.Token
representing the path'sType
; must not benull
name
- the name of the lastPath.Element
in thePath
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(org.microbean.type.JavaType.Token<U> type, String... names) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- aJavaType.Token
representing the path'sType
; must not benull
names
- the sequence of names forming thePath
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(org.microbean.type.JavaType.Token<U> type, List<? extends String> names) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- aJavaType.Token
representing the path'sType
; must not benull
names
- the sequence of names forming thePath
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
@OverridingDiscouraged default <U> Loader<U> load(Qualifiers<? extends String, ?> qualifiers, Class<U> type) Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
qualifiers
- the path'sQualifiers
; must not benull
type
- aClass
serving as the path'sType
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- aClass
serving as the path'sType
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- aClass
serving as the path'sType
; must not benull
name
- the name of the lastPath.Element
in thePath
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- aClass
serving as the path'sType
; must not benull
names
- the sequence of names forming thePath
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
load
Builds aPath
from the supplied arguments, calls theload(Path)
method and returns its result.- Type Parameters:
U
- the type of environmental objects the returnedLoader
will supply- Parameters:
type
- aClass
serving as the path'sType
; must not benull
names
- the sequence of names forming thePath
; must not benull
- Returns:
- a
Loader
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made about idempotency or determinism with respect to this method or its (discouraged) overrides.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
loaderFor
Returns an ancestralLoader
, derived from and possibly identical to thisLoader
, that is suitable for a transliterated and absolute version of the suppliedpath
, particularly for cases where, during the execution of theload(Path)
method, aLoader
must be supplied to some other class.The returned
Loader
must be one whosepath()
method returns the longestPath
that is a parent of an absolute version of the (transliterated) suppliedpath
. In many casesthis
will be returned.Typically only classes implementing this interface will need to call this method. Most users will have no need to call this method directly.
Overriding of this method is very strongly discouraged.
- Parameters:
path
- thePath
in question; must not benull
- Returns:
- an ancestral
Loader
, derived from and possibly identical to thisLoader
, that is suitable for a transliterated and absolute version of the suppliedpath
, particularly for cases where, during the execution of theload(Path)
method, aLoader
must be supplied to some other class; nevernull
- Throws:
NullPointerException
- ifpath
isnull
- See Also:
- Idempotency:
- The default implementation of this method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- The default implementation of this method does not,
and its (discouraged) overrides must not, return
null
. - Thread Safety:
- The default implementation of this method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
transliterate
Transliterates the supplied absolutePath
into some otherPath
, whose meaning is the same, but whose representation may be different, that will be used instead.The
Path
that is returned may be thePath
that was supplied. This may happen, for example, if the path has already been transliterated, or if the path identifies a transliteration request.Path transliteration is needed because the
name()
components ofPath.Element
s may unintentionally clash when two components are combined into a single application.Path transliteration must occur during the execution of any implementation of the
load(Path)
method, such that thePath
supplied to that method, once it has been verified to be absolute, is supplied to an implementation of this method. ThePath
returned by an implementation of this method must then be used during the rest of the invocation of theload(Path)
method, as if it had been supplied in the first place.Behavior resulting from any other usage of an implementation of this method is undefined.
The default implementation of this method uses the configuration system itself to find a transliterated
Path
corresponding to the suppliedPath
, returning the suppliedpath
itself if no transliteration can take place. Infinite loops are avoided except as noted below.Overrides of this method must not call
loaderFor(Path)
or an infinite loop may result.Overrides of this method must not call
load(Path)
with the suppliedpath
or an infinite loop may result.An implementation of
Loader
will findPath.transliterate(java.util.function.BiFunction)
particularly useful in implementing this method.Most users will have no need to call this method directly.
- Type Parameters:
U
- the type of the supplied and returnedPath
s- Parameters:
path
- an absolutePath
; must not be null- Returns:
- the transliterated
Path
; nevernull
; possibly the suppliedpath
itself - Throws:
NullPointerException
- ifpath
isnull
IllegalArgumentException
- ifpath
returnsfalse
from itsabsolute()
method- See Also:
- Idempotency:
- The default implementation of this method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- The default implementation of this method does not,
and its (discouraged) overrides must not, return
null
. - Thread Safety:
- The default implementation of this method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
isRoot
Returnstrue
if and only if thisLoader
is the rootLoader
, which occurs only when the return value ofthis.parent() == this
.Overrides of this method are strongly discouraged.
Most users will have no need to call this method directly.
-
root
Returns the rootLoader
, which is theLoader
whoseparent()
method returns iteself.Overrides of this method are strongly discouraged.
Most users will have no need to call this method directly.
- Returns:
- the root
Loader
- See Also:
- Idempotency:
- This method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
as
Casts thisLoader
appropriately and returns it, usually so that an implementation's implementation-specific methods can be accessed.- Type Parameters:
L
- theLoader
subclass- Parameters:
loaderSubclass
- aClass
representing a subclass ofLoader
; must not benull
- Returns:
- this
Loader
- Throws:
NullPointerException
- ifloaderSubclass
isnull
ClassCastException
- if the cast could not be performed- Idempotency:
- This method is, and its (discouraged) overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, and its (discouraged)
overrides must not, return
null
. - Thread Safety:
- This method is, and its (discouraged) overrides must be, safe for concurrent use by multiple threads.
-
loader
Bootstraps and returns aLoader
.If this method has been called before, its prior result is returned.
Otherwise, first, the root
Loader
is located using Java's built-inServiceLoader
. The first of theLoader
instances it discovers is used and all others are ignored. Note that theServiceLoader
discovery process is non-deterministic. Normally there is only one suchLoader
provided by an implementation of this API.The root
Loader
that is loaded via this mechanism is subject to the following restrictions:- It must return a
Path
from itspath()
implementation that is equal toPath.root()
. - It must return a
Path
from itsabsolutePath()
implementation that is equal toPath.root()
. - It must return itself (
this
) from itsparent()
implementation. - It must return
true
from itsisRoot()
implementation. - It must return itself (
this
) from itsroot()
method. - It must return
OptionalSupplier.Determinism.PRESENT
from itsdeterminism()
method. - It must return itself (
this
) from itsget()
method.
Next, this root
Loader
is used to find theLoader
of record, which in most cases is simply itself.The
Loader
of record is subject to the following restrictions (which are compatible with the overwhelmingly common case of its also being the rootLoader
):- It must return a
Path
from itspath()
implementation that is equal toPath.root()
(same as above). - It must return a
Path
from itsabsolutePath()
implementation that is equal toPath.root()
(same as above). - It must return
OptionalSupplier.Determinism.PRESENT
from itsdeterminism()
method (same as above). - It must return the root
Loader
from itsparent()
implementation (which may be itself (this
)). - It must return a
Loader
implementation, often itself (this
), from itsget()
method.
An
IllegalStateException
will be thrown if an implementation of theLoader
interface does not honor the requirements above.This method is the primary entry point for end users of this framework.
- Returns:
- a non-
null
Loader
that can be used to acquire environmental objects that abides by the requirements and restrictions above - Throws:
IllegalStateException
- if any of the requirements and restrictions above is violatedServiceConfigurationError
- if the rootLoader
could not be loaded for any reasonNoClassDefFoundError
- if the rootLoader
could not be loaded for any reason
- It must return a
-