Interface ExpressionService

All Superinterfaces:
Identifiable

public interface ExpressionService extends Identifiable
API for a service that uses the 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
  • 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:
      getUid in interface Identifiable
      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

      static URI 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 context
      root - an optional root object to use during expression evaluation
      Returns:
      the newly created context
    • parseExpression

      org.springframework.expression.Expression parseExpression(String expression)
      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 same expression is passed multiple times. If an expression is only used once, then calling evaluateExpression(String, Map, Object, EvaluationContext, Class) can be more convenient.

      Type Parameters:
      T - the result type
      Parameters:
      expression - the expression to evaluate
      variables - optional variables to pass into the evaluation
      root - optional "root" object to set for the evaluation
      context - a context, such as one returned from createEvaluationContext(EvaluationConfiguration, Object), or null to create a new context
      resultClass - 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 evaluate
      variables - optional variables to pass into the evaluation
      root - optional "root" object to set for the evaluation
      context - a context, such as one returned from createEvaluationContext(EvaluationConfiguration, Object), or null to create a new context
      resultClass - the expected result object type
      Returns:
      the expression result
      Throws:
      org.springframework.expression.EvaluationException - if any error occurs