Modifier and Type | Method and Description |
---|---|
static Class<?> |
asClass(JsonValue value)
Returns the class object associated with a named class or interface, using the thread
context class loader.
|
static Function<JsonValue,Bindings,JsonValueException> |
bindings()
Returns a function that will create some bindings based of a Map-based
JsonValue . |
static Function<JsonValue,Bindings,JsonValueException> |
bindings(Bindings bindings)
Returns a function that will create some bindings based of a Map-based
JsonValue . |
static Function<JsonValue,SecretReference<GenericSecret>,JsonValueException> |
constantSecretReference(Clock clock)
Returns a
SecretReference.constant(Secret) from a GenericSecret attribute value. |
static Function<JsonValue,JsonValue,JsonValueException> |
evaluated()
Returns a function that will evaluate all String nodes.
|
static Function<JsonValue,JsonValue,JsonValueException> |
evaluated(Bindings bindings)
Returns a function that will evaluate all String nodes.
|
static <T,E extends Exception> |
expectedType(Class<T> type,
Function<JsonValue,T,E> adapter)
Allows to use
defaultTo in an heaplet configuration to retrieve an object. |
static <T> Function<JsonValue,Expression<T>,JsonValueException> |
expression(Class<T> type)
Returns a function for transforming JsonValues to expressions.
|
static <T> Function<JsonValue,Expression<T>,JsonValueException> |
expression(Class<T> type,
Bindings bindings)
Returns a function for transforming JsonValues to expressions.
|
static JsonValue |
firstOf(JsonValue config,
String... names)
Returns, if the given JSON value contains one of the names, the first
defined JSON value, otherwise if the given JSON value does not match any
of the names, then a JsonValue encapsulating null is returned.
|
static JsonValue |
getWithDeprecation(JsonValue config,
org.slf4j.Logger logger,
String name,
String... deprecatedNames)
Returns the named property from the provided JSON object, falling back to
zero or more deprecated property names.
|
static Function<JsonValue,String,JsonValueException> |
heapObjectNameOrPointer()
Returns a function that will look for the name of the object.
|
static Function<JsonValue,Instant,JsonValueException> |
instant()
|
static <T> Function<JsonValue,LeftValueExpression<T>,JsonValueException> |
leftValueExpression(Class<T> type)
Returns a function for transforming JsonValues to left-value expressions.
|
static <T,E extends Exception> |
listOf(Function<JsonValue,T,E> adapter)
Returns a function that transform a JSON node value into a list of adapted instances.
|
static <T> Function<JsonValue,T,HeapException> |
lookupOrCreateHeapObject(Heap heap,
Class<T> type)
|
static Function<JsonValue,Optional<JsonValue>,JsonValueException> |
optional()
|
static <T> Function<JsonValue,T,HeapException> |
optionalHeapObject(Heap heap,
Class<T> type)
|
static <T> Function<JsonValue,Optional<T>,JsonValueException> |
optionalOf(Function<JsonValue,T,JsonValueException> delegate)
Returns a wrapping function returning an
Optional result of the given delegate function. |
static <S extends Secret> |
purposeOf(Class<S> type)
|
static JsonValue |
readJson(URL resource)
Builds a
JsonValue from the given URL. |
static Function<JsonValue,JsonValue,JsonValueException> |
required(String message)
Displays a custom message when the required attribute is not present in the configuration.
|
static <T> Function<JsonValue,T,HeapException> |
requiredHeapObject(Heap heap,
Class<T> type)
|
static Function<JsonValue,JsonValue,JsonValueException> |
resolvedLocation()
Returns a function that will resolve the field $location.
|
static Function<JsonValue,JsonValue,JsonValueException> |
resolvedLocation(Bindings bindings)
Returns a function that will resolve the field $location.
|
static Function<JsonValue,JsonValue,JsonValueException> |
slashEnded()
Returns the JsonValue with its value ended by a slash.
|
static <V,E extends Exception> |
streamOf(Function<JsonValue,V,E> transformFunction)
Returns the JSON value as a
Stream containing objects whose type (and value) is specified by a
transformation function. |
static Function<JsonValue,JsonValue,SubstitutionException> |
tokenized(PropertyResolver propertyResolver)
Returns a function performing deep token substitution and object coercion ($ "functions").
|
static void |
warnForDeprecation(JsonValue config,
org.slf4j.Logger logger,
String name,
String deprecatedName)
Issues a warning that the configuration property
oldName is
deprecated and that the property newName should be used instead. |
public static Function<JsonValue,JsonValue,JsonValueException> slashEnded()
config.get("openamUri").as(evaluatedWithHeapProperties())
.required()
.as(slashEnded())
.as(uri());
JsonValueException
- If the JSON value is not a string.public static Class<?> asClass(JsonValue value)
null
, this method returns null
.value
- the value containing the class name string.JsonValueException
- if value is not a string or the named class could not be found.public static Function<JsonValue,JsonValue,JsonValueException> resolvedLocation()
ResolveLocationJsonValueFunction
public static Function<JsonValue,JsonValue,JsonValueException> resolvedLocation(Bindings bindings)
bindings
- The bindings used when evaluating the $location valueResolveLocationJsonValueFunction
public static Function<JsonValue,String,JsonValueException> heapObjectNameOrPointer()
The following declaration would return Inline:
{
"name": "Inline",
"type": "Router"
}
And this one would return {WelcomeHandler}/heap/objects/0/config/defaultHandler:
{
"type": "WelcomeHandler"
}
public static Function<JsonValue,JsonValue,JsonValueException> evaluated()
Malformed expressions are ignored e.g: "$$$${{" and their values are not changed.
When an error occurs during the
evaluation of an expression, the value is set to null
because we
cannot differentiate successful evaluations or failed ones.
JsonValue
public static Function<JsonValue,JsonValue,JsonValueException> evaluated(Bindings bindings)
Malformed expressions are ignored e.g: "$$$${{" and their values are not changed.
When an error occurs during the
evaluation of an expression, the value is set to null
because we
cannot differentiate successful evaluations or failed ones.
bindings
- the bindings to use when evaluating the found expressionsJsonValue
public static JsonValue firstOf(JsonValue config, String... names)
Uri uri = firstOf(config, "authorizeEndpoint", "authorize_endpoint").required().asURI();
config
- The JSON value where one of the selected names can be found.
Usually in a heaplet configuration for example.names
- Names of the attributes that you are looking for.public static Function<JsonValue,Instant,JsonValueException> instant()
Instant
representation of a timestamp in seconds.JsonValueException
- if the value is not a number.public static <T> Function<JsonValue,LeftValueExpression<T>,JsonValueException> leftValueExpression(Class<T> type)
T
- expected result typetype
- The expected result type of the expression.public static <T> Function<JsonValue,Expression<T>,JsonValueException> expression(Class<T> type)
T
- expected result typetype
- The expected result type of the expression.public static <T> Function<JsonValue,Expression<T>,JsonValueException> expression(Class<T> type, Bindings bindings)
T
- expected result typetype
- The expected result type of the expression.bindings
- The initial bindings used when evaluated this expressionpublic static Function<JsonValue,Bindings,JsonValueException> bindings()
JsonValue
.JsonValue
.public static Function<JsonValue,Bindings,JsonValueException> bindings(Bindings bindings)
JsonValue
.bindings
- The initial bindings used when evaluated theJsonValue
.public static <T> Function<JsonValue,T,HeapException> lookupOrCreateHeapObject(Heap heap, Class<T> type)
Function
that will lookup into the provided heap and its parents for an object
named by the provided JsonValue
declaration. If no such object is found then it's
created in the provided heap.T
- expected object typeheap
- the heap to query for references resolutiontype
- expected object typeFunction
that will create the object if it's not found into the provided heap or its parents.public static <T> Function<JsonValue,T,HeapException> requiredHeapObject(Heap heap, Class<T> type)
public static <T> Function<JsonValue,T,HeapException> optionalHeapObject(Heap heap, Class<T> type)
public static JsonValue getWithDeprecation(JsonValue config, org.slf4j.Logger logger, String name, String... deprecatedNames)
config
- The configuration object.logger
- The logger which should be used for deprecation warnings.name
- The non-deprecated property name.deprecatedNames
- The deprecated property names ordered from newest to oldest.public static void warnForDeprecation(JsonValue config, org.slf4j.Logger logger, String name, String deprecatedName)
oldName
is
deprecated and that the property newName
should be used instead.config
- The configuration object.logger
- The logger which should be used for deprecation warnings.name
- The non-deprecated property name.deprecatedName
- The deprecated property name.public static JsonValue readJson(URL resource) throws IOException
JsonValue
from the given URL.resource
- the URL to read the JSON fromJsonValue
built from the resource URLIOException
- If an error occurs while trying to read the JSONpublic static Function<JsonValue,JsonValue,SubstitutionException> tokenized(PropertyResolver propertyResolver)
propertyResolver
- Resolver to use for token substitutionpublic static <T,E extends Exception> Function<JsonValue,T,E> expectedType(Class<T> type, Function<JsonValue,T,E> adapter)
defaultTo
in an heaplet configuration to retrieve an object.
Example:
config.get("keyStore").defaultTo(myObject)
.as(expectedType(KeyStore.class, optionalHeapObject(heap, KeyStore.class)));
T
- The generic type of the object returned by the adapter.E
- The generic exception thrown by the adapter if something wrong happens.type
- The class of the object.adapter
- The function used to to retrieve the object.public static Function<JsonValue,Optional<JsonValue>,JsonValueException> optional()
public static <T> Function<JsonValue,Optional<T>,JsonValueException> optionalOf(Function<JsonValue,T,JsonValueException> delegate)
Optional
result of the given delegate
function.T
- expected result typedelegate
- delegate transformation functionpublic static <S extends Secret> Function<JsonValue,Purpose<S>,JsonValueException> purposeOf(Class<S> type)
S
- The type of the Purpose
.type
- The Purpose
type (i.e: GenericSecret
, etc...).null
if the value is null.public static Function<JsonValue,JsonValue,JsonValueException> required(String message)
message
- The message to display when the required attribute is not present.JsonValueException
if the attribute is not present in
the configuration with a custom message.public static <T,E extends Exception> Function<JsonValue,List<T>,E> listOf(Function<JsonValue,T,E> adapter)
Accepts formats such as:
{
"null": null,
"singleton": node,
"multi": [
nodes...
]
}
A null
value results in an immutable empty list.
A unique, singleton primitive value is returned as a singleton list (modifiable).
An array of values returns a list of adapted objects (of the size of the initial JSON array)
T
- List's item typeE
- exception typeadapter
- adaptation functionnull
)public static <V,E extends Exception> Function<JsonValue,Stream<V>,E> streamOf(Function<JsonValue,V,E> transformFunction)
Stream
containing objects whose type (and value) is specified by a
transformation function. If the value is not a collection, this method returns Stream.empty()
. It is up
to the transformation function to transform/enforce source types of the elements in the Json source collection.
If any of the elements of the list are not of the appropriate type, or the type-transformation cannot occur, the
exception specified by the transformation function is thrown.V
- the type of elements in this listE
- the type of exception thrown by the transformation functiontransformFunction
- a Function
to transform an element of the JsonValue list to the desired typeStream.empty()
if not a collection.NullPointerException
- if transformFunction
is null
.public static Function<JsonValue,SecretReference<GenericSecret>,JsonValueException> constantSecretReference(Clock clock)
SecretReference.constant(Secret)
from a GenericSecret
attribute value.clock
- A reference to a Clock
GenericSecret
or null
if the value is null.Copyright 2011-2017 ForgeRock AS.