Interface ExpressionService
- All Superinterfaces:
Identifiable
Expression API for evaluating dynamic
expressions.
This API extends Identifiable; each implementation must define their
own unique identifier so they can be differentiated at runtime.
- Since:
- 1.49
- Version:
- 1.0
- Author:
- matt
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAPI for configuration of the expression runtime. -
Field Summary
Fields inherited from interface net.solarnetwork.service.Identifiable
GROUP_UID_PROPERTY, UID_PROPERTY -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.expression.EvaluationContextcreateEvaluationContext(ExpressionService.EvaluationConfiguration configuration, Object root) Create a reusable evaluation context.<T> TevaluateExpression(String expression, Map<String, Object> variables, Object root, org.springframework.expression.EvaluationContext context, Class<T> resultClass) Evaluate an expression.<T> TevaluateExpression(org.springframework.expression.Expression expression, Map<String, Object> variables, Object root, org.springframework.expression.EvaluationContext context, Class<T> resultClass) Evaluate an expression.static URIGet a link to a general expression service guide.Get a link to a language reference guide.getUid()Get a unique identifier for the language this expression service supports.org.springframework.expression.ExpressionparseExpression(String expression) Parse an expression.Methods inherited from interface net.solarnetwork.service.Identifiable
getDisplayName, getGroupUid
-
Method Details
-
getUid
String getUid()Get a unique identifier for the language this expression service supports.This identifier is meant to be stored alongside an expressions managed by users, so they might be able to choose from all languages supported by the system.
- Specified by:
getUidin interfaceIdentifiable- Returns:
- a unique identifier
-
getLanguageReferenceLink
URI getLanguageReferenceLink()Get a link to a language reference guide.- Returns:
- a link to a reference guide for the language supported by this service
-
getGeneralExpressionReferenceLink
Get a link to a general expression service guide.- Returns:
- a link to a general guide
-
createEvaluationContext
org.springframework.expression.EvaluationContext createEvaluationContext(ExpressionService.EvaluationConfiguration configuration, Object root) Create a reusable evaluation context.Creating a context can be an expensive operation, so this method can be called to create a thread-safe and reusable context instance.
- Parameters:
configuration- optional configuration to apply to the contextroot- an optional root object to use during expression evaluation- Returns:
- the newly created context
-
parseExpression
Parse an expression.- Parameters:
expression- the expression to parse- Returns:
- the parsed expression
-
evaluateExpression
<T> T evaluateExpression(org.springframework.expression.Expression expression, Map<String, Object> variables, Object root, org.springframework.expression.EvaluationContext context, Class<T> resultClass) Evaluate an expression.Calling this method, instead of
evaluateExpression(String, Map, Object, EvaluationContext, Class), can result in faster evaluation times if the sameexpressionis passed multiple times. If anexpressionis only used once, then callingevaluateExpression(String, Map, Object, EvaluationContext, Class)can be more convenient.- Type Parameters:
T- the result type- Parameters:
expression- the expression to evaluatevariables- optional variables to pass into the evaluationroot- optional "root" object to set for the evaluationcontext- a context, such as one returned fromcreateEvaluationContext(EvaluationConfiguration, Object), or null to create a new contextresultClass- the expected result object type- Returns:
- the expression result
- Throws:
org.springframework.expression.EvaluationException- if any error occurs
-
evaluateExpression
<T> T evaluateExpression(String expression, Map<String, Object> variables, Object root, org.springframework.expression.EvaluationContext context, Class<T> resultClass) Evaluate an expression.- Type Parameters:
T- the result type- Parameters:
expression- the expression to evaluatevariables- optional variables to pass into the evaluationroot- optional "root" object to set for the evaluationcontext- a context, such as one returned fromcreateEvaluationContext(EvaluationConfiguration, Object), or null to create a new contextresultClass- the expected result object type- Returns:
- the expression result
- Throws:
org.springframework.expression.EvaluationException- if any error occurs
-