Package org.forgerock.openig.util
Class JsonValues
- java.lang.Object
-
- org.forgerock.openig.util.JsonValues
-
public final class JsonValues extends Object
Provides additional functionality toJsonValue.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Class<?>asClass(org.forgerock.json.JsonValue value)Returns the class object associated with a named class or interface, using the thread context class loader.static <T> TasNewInstance(org.forgerock.json.JsonValue value, Class<T> type)Creates a new instance of a named class.static org.forgerock.util.Function<org.forgerock.json.JsonValue,Bindings,org.forgerock.json.JsonValueException>bindings()Returns a function that will create some bindings based of a Map-basedJsonValue.static org.forgerock.util.Function<org.forgerock.json.JsonValue,Bindings,org.forgerock.json.JsonValueException>bindings(Bindings bindings)Returns a function that will create some bindings based of a Map-basedJsonValue.static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException>evaluated()Returns a function that will evaluate all String nodes.static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException>evaluated(Bindings bindings)Returns a function that will evaluate all String nodes.static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,Expression<T>,org.forgerock.json.JsonValueException>expression(Class<T> type)Returns a function for transforming JsonValues to expressions.static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,Expression<T>,org.forgerock.json.JsonValueException>expression(Class<T> type, Bindings bindings)Returns a function for transforming JsonValues to expressions.static org.forgerock.json.JsonValuefirstOf(org.forgerock.json.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 org.forgerock.json.JsonValuegetWithDeprecation(org.forgerock.json.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 org.forgerock.util.Function<org.forgerock.json.JsonValue,String,org.forgerock.json.JsonValueException>heapObjectNameOrPointer()Returns a function that will look for the name of the object.static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,LeftValueExpression<T>,org.forgerock.json.JsonValueException>leftValueExpression(Class<T> type)Returns a function for transforming JsonValues to left-value expressions.static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,T,HeapException>optionalHeapObject(Heap heap, Class<T> type)Returns aFunctionto transform a list of String-basedJsonValues into a list of optional heap objects.static org.forgerock.json.JsonValuereadJson(URL resource)Builds aJsonValuefrom the given URL.static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,T,HeapException>requiredHeapObject(Heap heap, Class<T> type)Returns aFunctionto transform a list of String-basedJsonValues into a list of required heap objects.static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException>resolvedLocation()Returns a function that will resolve the field $location.static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException>resolvedLocation(Bindings bindings)Returns a function that will resolve the field $location.static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException>slashEnded()Returns the JsonValue with its value ended by a slash.static voidwarnForDeprecation(org.forgerock.json.JsonValue config, org.slf4j.Logger logger, String name, String deprecatedName)Issues a warning that the configuration propertyoldNameis deprecated and that the propertynewNameshould be used instead.
-
-
-
Method Detail
-
slashEnded
public static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException> slashEnded()
Returns the JsonValue with its value ended by a slash. This could be useful when working on uris. Example of use:config.get("openamUri").as(evaluatedWithHeapProperties()) .required() .as(slashEnded()) .as(uri());- Returns:
- the string value always ended with a slash.
- Throws:
org.forgerock.json.JsonValueException- If the JSON value is not a string.
-
asClass
public static Class<?> asClass(org.forgerock.json.JsonValue value)
Returns the class object associated with a named class or interface, using the thread context class loader. If the value isnull, this method returnsnull.- Parameters:
value- the value containing the class name string.- Returns:
- the class object with the specified name.
- Throws:
org.forgerock.json.JsonValueException- if value is not a string or the named class could not be found.
-
asNewInstance
public static <T> T asNewInstance(org.forgerock.json.JsonValue value, Class<T> type)Creates a new instance of a named class. The class is instantiated as if by anewexpression with an empty argument list. The class is initialized if it has not already been initialized. If the value isnull, this method returnsnull.- Type Parameters:
T- the type of the new instance.- Parameters:
value- the value containing the class name string.type- the type that the instantiated class should to resolve to.- Returns:
- a new instance of the requested class.
- Throws:
org.forgerock.json.JsonValueException- if the requested class could not be instantiated.
-
resolvedLocation
public static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException> resolvedLocation()
Returns a function that will resolve the field $location.- Returns:
- a function that will resolve the field $location.
- See Also:
ResolveLocationJsonValueFunction
-
resolvedLocation
public static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException> resolvedLocation(Bindings bindings)
Returns a function that will resolve the field $location.- Parameters:
bindings- The bindings used when evaluating the $location value- Returns:
- a function that will resolve the field $location.
- See Also:
ResolveLocationJsonValueFunction
-
heapObjectNameOrPointer
public static org.forgerock.util.Function<org.forgerock.json.JsonValue,String,org.forgerock.json.JsonValueException> heapObjectNameOrPointer()
Returns a function that will look for the name of the object. It infers a locally unique name for the given object declaration. If a name attribute is provided, simply return its value as name, otherwise builds a unique name composed of both the declaration JSON pointer (map to the location within the JSON file) and the value of the type attribute (ease to identify the object).The following declaration would return Inline:
{ "name": "Inline", "type": "Router" }And this one would return {WelcomeHandler}/heap/objects/0/config/defaultHandler:
{ "type": "WelcomeHandler" }- Returns:
- the name of the heap object or the pointer to that object if it is anonymous.
-
evaluated
public static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException> evaluated()
Returns a function that will evaluate all String nodes. Transformation is applied recursively.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
nullbecause we cannot differentiate successful evaluations or failed ones.- Returns:
- a function to evaluate String nodes of a
JsonValue
-
evaluated
public static org.forgerock.util.Function<org.forgerock.json.JsonValue,org.forgerock.json.JsonValue,org.forgerock.json.JsonValueException> evaluated(Bindings bindings)
Returns a function that will evaluate all String nodes. Transformation is applied recursively.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
nullbecause we cannot differentiate successful evaluations or failed ones.- Parameters:
bindings- the bindings to use when evaluating the found expressions- Returns:
- a function to evaluate String nodes of a
JsonValue
-
firstOf
public static org.forgerock.json.JsonValue firstOf(org.forgerock.json.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. Example of use:Uri uri = firstOf(config, "authorizeEndpoint", "authorize_endpoint").required().asURI();- Parameters:
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.- Returns:
- the specified item JSON value or JsonValue encapsulating null if none were found.
-
leftValueExpression
public static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,LeftValueExpression<T>,org.forgerock.json.JsonValueException> leftValueExpression(Class<T> type)
Returns a function for transforming JsonValues to left-value expressions.- Type Parameters:
T- expected result type- Parameters:
type- The expected result type of the expression.- Returns:
- A function for transforming JsonValues to left-value expressions.
-
expression
public static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,Expression<T>,org.forgerock.json.JsonValueException> expression(Class<T> type)
Returns a function for transforming JsonValues to expressions.- Type Parameters:
T- expected result type- Parameters:
type- The expected result type of the expression.- Returns:
- A function for transforming JsonValues to expressions.
-
expression
public static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,Expression<T>,org.forgerock.json.JsonValueException> expression(Class<T> type, Bindings bindings)
Returns a function for transforming JsonValues to expressions.- Type Parameters:
T- expected result type- Parameters:
type- The expected result type of the expression.bindings- The initial bindings used when evaluated this expression- Returns:
- A function for transforming JsonValues to expressions.
-
bindings
public static org.forgerock.util.Function<org.forgerock.json.JsonValue,Bindings,org.forgerock.json.JsonValueException> bindings()
Returns a function that will create some bindings based of a Map-basedJsonValue.- Returns:
- a function that will create some bindings based of a Map-based
JsonValue.
-
bindings
public static org.forgerock.util.Function<org.forgerock.json.JsonValue,Bindings,org.forgerock.json.JsonValueException> bindings(Bindings bindings)
Returns a function that will create some bindings based of a Map-basedJsonValue.- Parameters:
bindings- The initial bindings used when evaluated the- Returns:
- a function that will create some bindings based of a Map-based
JsonValue.
-
requiredHeapObject
public static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,T,HeapException> requiredHeapObject(Heap heap, Class<T> type)
Returns aFunctionto transform a list of String-basedJsonValues into a list of required heap objects.- Type Parameters:
T- expected object type- Parameters:
heap- the heap to query for references resolutiontype- expected object type- Returns:
- a
Functionto transform a list of String-basedJsonValues into a list of required heap objects.
-
optionalHeapObject
public static <T> org.forgerock.util.Function<org.forgerock.json.JsonValue,T,HeapException> optionalHeapObject(Heap heap, Class<T> type)
Returns aFunctionto transform a list of String-basedJsonValues into a list of optional heap objects.- Type Parameters:
T- expected object type- Parameters:
heap- the heap to query for references resolutiontype- expected object type- Returns:
- a
Functionto transform a list of String-basedJsonValues into a list of required heap objects.
-
getWithDeprecation
public static org.forgerock.json.JsonValue getWithDeprecation(org.forgerock.json.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. This method will log a warning if only a deprecated property is found or if two equivalent property names are found.- Parameters:
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.- Returns:
- The request property.
-
warnForDeprecation
public static void warnForDeprecation(org.forgerock.json.JsonValue config, org.slf4j.Logger logger, String name, String deprecatedName)Issues a warning that the configuration propertyoldNameis deprecated and that the propertynewNameshould be used instead.- Parameters:
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.
-
readJson
public static org.forgerock.json.JsonValue readJson(URL resource) throws IOException
Builds aJsonValuefrom the given URL.- Parameters:
resource- the URL to read the JSON from- Returns:
- a
JsonValuebuilt from the resource URL - Throws:
IOException- If an error occurs while trying to read the JSON
-
-