Class FWParameterResolver
${name} of texts and evaluates JEXL expressions. This is
the only implementation for the pipeline map (GUI, pipelines, data readers) and for the simulation variable map
(file names, SQL statements, URLs and identifiers of solutions and projects); the values come from a
FWParameterContext.
Texts (replace(FWParameterContext, String, Object, boolean)): the placeholders are replaced
repeatedly as long as replacements happen, so a value may contain placeholders again and placeholders may be nested
(${a${i}}). A name is resolved as special parameter (see FWParameterContext) or as value of the
context. A parameter that is present without value is replaced by an empty text. If a parameter is missing, a
warning is logged and
- with
aIgnoreNull, the placeholder is replaced by an empty text, - otherwise, if the caller gave a default other than the text itself, the default is returned (e.g.
"0"for a flag), - otherwise the placeholder stays in the text, all other placeholders are replaced.
${SETTINGS...} makes the whole result the default (may be null).
Expressions (evaluate(FWParameterContext, String), evaluateBoolean(Map, String, boolean),
evaluateNumber(Map, String)) are JEXL rules with the same syntax as the rules of a solution:
${a.b} is the value of the parameter a.b (not its text), e.g. ${count} gt 2,
${type} eq 'DOUBLE' or ${type} eq 'INT', file:exists('sim/sim_resource.zip'),
${values}[2]. All namespaces of JexlBuilder can be used. They are used for the control
attributes of the GUI configuration (visible, enabled, required,
if), the minimum and maximum of number fields and the rules of the pipeline.
- Author:
- Andreas Enders
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectEvaluates a JEXL expression with the values of a parameter map, seeevaluate(FWParameterContext, String).static Objectevaluate(FWParameterContext aContext, String aExpression) Evaluates a JEXL expression or script.static booleanevaluateBoolean(Map<String, Object> aParameterMap, String aExpression, boolean aDefault) Evaluates a control attribute (e.g.static booleanevaluateBoolean(FWParameterContext aContext, String aExpression, boolean aDefault) Evaluates a JEXL expression as boolean.static doubleevaluateNumber(Map<String, Object> aParameterMap, String aExpression) Evaluates a JEXL expression as number, e.g.getParametersFromString(String aText) static booleanhasPlaceholders(String aText) static StringCreates an expression that checks whether a parameter has one of several values, e.g.static StringReplaces the placeholders with the values of a parameter map, seereplace(FWParameterContext, String, Object, boolean).static StringReplaces the placeholders with the values of a parameter map, seereplace(FWParameterContext, String, Object, boolean).static Stringreplace(FWParameterContext aContext, String aText, Object aDefault, boolean aIgnoreNull) Replaces the placeholders${name}of a text, see class description.static Stringreplace(FWSimVarMap aVarMap, String aText, Object aDefault) Replaces the placeholders with the values of a simulation variable map, seereplace(FWParameterContext, String, Object, boolean).
-
Field Details
-
PARAMPATTERN
Matches texts that contain a placeholder${...}. -
PARAMSEARCHPATTERN
Finds the innermost placeholders${name}(without nested braces).
-
-
Method Details
-
hasPlaceholders
- Parameters:
aText- the text, may benull- Returns:
trueif the text contains a placeholder start${
-
replace
Replaces the placeholders with the values of a parameter map, seereplace(FWParameterContext, String, Object, boolean).- Parameters:
aParameterMap- the parameter map (TEMPDIRmay be added)aText- the textaDefault- the result for missing parameters, see class description- Returns:
- the resulting text
-
replace
public static String replace(Map<String, Object> aParameterMap, String aText, Object aDefault, boolean aIgnoreNull) Replaces the placeholders with the values of a parameter map, seereplace(FWParameterContext, String, Object, boolean).- Parameters:
aParameterMap- the parameter map (TEMPDIRmay be added)aText- the textaDefault- the result for missing parameters, see class descriptionaIgnoreNull-trueto replace missing parameters by an empty string- Returns:
- the resulting text
-
replace
Replaces the placeholders with the values of a simulation variable map, seereplace(FWParameterContext, String, Object, boolean).- Parameters:
aVarMap- the variable map (TEMPDIRmay be added)aText- the textaDefault- the result for missing parameters, see class description- Returns:
- the resulting text
-
replace
public static String replace(FWParameterContext aContext, String aText, Object aDefault, boolean aIgnoreNull) Replaces the placeholders${name}of a text, see class description.- Parameters:
aContext- provides the parameter valuesaText- the text, may benullaDefault- the result for missing parameters (unless it is the text itself) and for a missing settingaIgnoreNull-trueto replace missing parameters by an empty string- Returns:
- the resulting text;
nullif the text isnull
-
evaluate
Evaluates a JEXL expression with the values of a parameter map, seeevaluate(FWParameterContext, String).- Parameters:
aParameterMap- the parameter mapaExpression- the expression- Returns:
- the result
- Throws:
RuntimeException- if the expression cannot be compiled or evaluated
-
evaluate
Evaluates a JEXL expression or script. Parameters are written as in solution rules (${a.b}), the special parameters can be used. The compiled expressions are cached.- Parameters:
aContext- provides the parameter valuesaExpression- the expression or script- Returns:
- the result
- Throws:
RuntimeException- if the expression cannot be compiled or evaluated
-
evaluateBoolean
public static boolean evaluateBoolean(Map<String, Object> aParameterMap, String aExpression, boolean aDefault) Evaluates a control attribute (e.g.visible,enabled,required,if) as JEXL expression with the values of a parameter map, seeevaluateBoolean(FWParameterContext, String, boolean).- Parameters:
aParameterMap- the parameter mapaExpression- the expression, may benullor emptyaDefault- the result for an empty expression or if it cannot be evaluated- Returns:
- the result as boolean
-
evaluateBoolean
public static boolean evaluateBoolean(FWParameterContext aContext, String aExpression, boolean aDefault) Evaluates a JEXL expression as boolean. The result is converted withStringHelper.parseBoolean(Object, boolean)(true,"true",1,"yes", ...).- Parameters:
aContext- provides the parameter valuesaExpression- the expression, may benullor emptyaDefault- the result for an empty expression, an unknown result or if it cannot be evaluated (a warning is logged)- Returns:
- the result as boolean
-
evaluateNumber
Evaluates a JEXL expression as number, e.g. the minimum${a.min} + 1of a number field.- Parameters:
aParameterMap- the parameter mapaExpression- the expression- Returns:
- the result as number; a text result is parsed; 0 if the result is no number
- Throws:
RuntimeException- if the expression cannot be compiled or evaluated
-
oneOfRule
Creates an expression that checks whether a parameter has one of several values, e.g.${Datatype} eq 'CSV' or ${Datatype} eq 'DATABASE'for the control attributes of generated forms.- Parameters:
aParameter- name of the parameteraValues- the values (must not contain')- Returns:
- the expression
-
getParametersFromString
-