- All Implemented Interfaces:
Provider
AbstractProvider
that can return Value
s backed
by System properties.
While System properties are often casually assumed to be stable
and String
-typed, the exact opposite is true: System
properties may contain arbitrarily-typed Object
s under
arbitrarily-typed keys, and the properties themselves may be replaced at any point.
This means that all Value
s supplied by this SystemPropertyProvider
are non-deterministic and may change type and presence from one call
to another.
It is also worth mentioning explicitly that, deliberately, no type conversion of any System property value takes place in this class.
-
Constructor Summary
ConstructorDescriptionCreates a newSystemPropertyProvider
that uses flat keys, does not presume that the only things stored in the System properties areString
s, and honors the fact that System properties are mutable.SystemPropertyProvider
(boolean flatKeys, boolean onlyStrings, boolean mutable) Creates a newSystemPropertyProvider
. -
Method Summary
Modifier and TypeMethodDescriptionprotected Supplier<?>
protected static final String
Overrides theAbstractProvider.path(Loader, Path)
method to return a (relative)Path
consisting solely of the last element of the suppliedabsolutePath
.Methods inherited from class org.microbean.loader.spi.AbstractProvider
get, lowerBound
-
Constructor Details
-
SystemPropertyProvider
public SystemPropertyProvider()Creates a newSystemPropertyProvider
that uses flat keys, does not presume that the only things stored in the System properties areString
s, and honors the fact that System properties are mutable. -
SystemPropertyProvider
Creates a newSystemPropertyProvider
.- Parameters:
flatKeys
- whether the key for a system property is derived from aPath
's last element's name onlyonlyStrings
- whether all System properties are expected to beString
-typedmutable
- whether System properties should be treated as mutable (which they are, strictly speaking, but for many applications this may not matter in practice)
-
-
Method Details
-
find
Returns aSupplier
suitable for the System property represented by the suppliedPath
.This method never returns
null
. Its overrides may if they wish.The name of the last element of the supplied
Path
is taken to be the name of the System property value to retrieve. If the type erasure of the suppliedPath
'squalified()
method is assignable fromString.class
, then calls will be made by the returnedValue
'sget()
method toSystem.getProperty(String)
before simple calls toSystem.getProperties().get(String)
.Any
Supplier
returned by this method will be non-deterministic, since system properties may change at any point. Additionally, if the suppliedPath
's type is not assignable from that borne by a System property value, then theSupplier
will returnnull
from itsget()
method in such a case, indicating that the value is present but cannot be represented. Overrides are strongly encouraged to abide by these conditions.- Specified by:
find
in classAbstractProvider
- Parameters:
requestor
- theLoader
seeking aValue
; must not benull
absolutePath
- an absolutePath
for which aValue
is being sought; must not benull
- Returns:
- a
Supplier
suitable for the System property whose name is represented by the suppliedPath
's lastElement
's name - Throws:
NullPointerException
- if an argument for either parameter isnull
- See Also:
- Idempotency:
- This method is idempotent and deterministic.
Overrides must be idempotent, but need not be deterministic.
Supplier
s returned by this method or its overrides are not guaranteed to be idempotent or deterministic. - Nullability:
- This method never returns
null
but its overrides may. - Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
path
Overrides theAbstractProvider.path(Loader, Path)
method to return a (relative)Path
consisting solely of the last element of the suppliedabsolutePath
.- Overrides:
path
in classAbstractProvider
- Type Parameters:
T
- the type of both the supplied and returnedPath
s- Parameters:
requestor
- theLoader
seeking aValue
; must not benull
absolutePath
- an absolutePath
for which aValue
is being sought; must not benull
- Returns:
- a
Path
that will be used to build aValue
to be returned by theAbstractProvider.get(Loader, Path)
method - See Also:
- Idempotency:
- This method is, and its overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, but overrides may, return
null
. - Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
key
- Parameters:
path
- thePath
in question; must not benull
flat
- whether the key is derived from the suppliedPath
's last element's name only- Returns:
- a
String
representation of the suppliedPath
- Throws:
NullPointerException
- ifpath
isnull
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null
. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-