Interface BindingContext
Minimal interface for a class that can bind strings to objects according to Parameter
s
# A note on deprecation
Various binding methods are being deprecated in favour of ones that don't throw ParameterBindingException
s
for user errors. Also, the code is moving away from being parameter-first to type-first, and making the parameter
versions added extras, which can add context to any error messages.
# Why all the change?
- we never use the whole parameter for the binding, just its type
- there was a bunch of boiler plate code adding the parameter to the problem, but it was up to each implementation to make sure they did it. We are going to move that wrapping to the various higher-level parameter set binding implementations in the future
- code that wanted to use binding without a parameter would have to do it in an awkward way and it took a lot of care to extricate the parameter name from the error message (and it wasn't always possible)
- ResultOrProblems exists to chain and nest user facing problems, like binding errors, and this has been an awkward outlier since day dot. It's also a big bin of untranslated code.
- a lot of non-parameter binding code wasn't catching the exceptions when called
-
Method Summary
Modifier and TypeMethodDescription<T> ResultOrProblems<T>
Bind a non-null value to a specific type, returning the bound value, or a failed result containing details why it didn't work.default ResultOrProblems<?>
Untyped version of bind that uses the parameter's type and wraps any problems with parameter contextDeprecated.default <T> List<ResultOrProblems<T>>
default List<ResultOrProblems<?>>
Untyped version of bindAll that uses the parameter's type and wraps any problems with parameter contextReturns aParameterBinder
that can convert a value of fromType to toType.void
Checks that the given map of bound parameter objects are valid according to the list of parameters.withNewRelativeTo
(URI relativeTo)
-
Method Details
-
validateBoundParameters
void validateBoundParameters(List<Parameter> parameters, Map<String, List<?>> boundParameters) throws InvalidBoundParametersExceptionChecks that the given map of bound parameter objects are valid according to the list of parameters. This should check both the type and the arity of the bound parameters.
- Throws:
InvalidBoundParametersException
-
bind
Deprecated.usebind(Object, Class)
insteadReturns a single parameter value from the given string input.
- Throws:
ParameterBindingException
- if it couldn't be bound to an object.
-
bind
Bind a non-null value to a specific type, returning the bound value, or a failed result containing details why it didn't work.
This method exists as the new way to bind values, without accepting a parameter and without throwing exceptions because:
- we never use the whole parameter for the parameter, just the type
- there was a bunch of boiler plate code adding the parameter to the problem, but it was up to each implementation to make sure they did it. We are going to move that wrapping to the various higher-level parameter set binding implementations in the future
- code that wanted to use binding without a parameter would have to do it in an awkward way and it took a lot of care to extricate the parameter name from the error message (and it wasn't always possible)
- ResultOrProblems exists to chain and nest user facing problems, like binding errors, and this has been an awkward outlier since day dot. It's also a big bin of untranslated code.
- a lot of non-parameter binding code wasn't catching the exceptions when called
-
bindAll
-
bindAll
Untyped version of bindAll that uses the parameter's type and wraps any problems with parameter context
-
bind
Untyped version of bind that uses the parameter's type and wraps any problems with parameter context
-
getBinder
Returns a
ParameterBinder
that can convert a value of fromType to toType. Note that most binders will convert from fromType by converting the value to a string, but more specific binders could be present and should be returned in favour of a less specific one. -
withNewRelativeTo
- Returns:
- a new
BindingContext
that will bind resources relative to a new base URI TODO see if we can factor this out when we do the new resource binding stuff
-
getProject
Project getProject() -
getEngine
Engine getEngine() -
getRelativeTo
URI getRelativeTo() -
getRealizationContext
RealizationContext getRealizationContext()- Returns:
- a
RealizationContext
for realizing any parameters that involve expressions or other riskscape language elements
-
getTempDirectory
Path getTempDirectory()
-
bind(Object, Class)
instead