Class DynamicContext

java.lang.Object
dev.metaschema.core.metapath.DynamicContext

public class DynamicContext extends Object
The implementation of a Metapath dynamic context.
  • Constructor Details

    • DynamicContext

      public DynamicContext()
      Construct a new dynamic context with a default static context.
    • DynamicContext

      public DynamicContext(@NonNull StaticContext staticContext)
      Construct a new Metapath dynamic context using the provided static context.
      Parameters:
      staticContext - the Metapath static context
  • Method Details

    • subContext

      @NonNull public DynamicContext subContext()
      Generate a new dynamic context that is a copy of this dynamic context.

      This method can be used to create a new sub-context where changes can be made without affecting this context. This is useful for setting information that is only used in a limited evaluation sub-scope, such as for handling variable assignment.

      The focus context from this context is preserved in the new sub-context, allowing nested expressions to access the enclosing focus (e.g., for position() and last() calls within variable binding scopes).

      Returns:
      a new dynamic context
    • subContext

      @NonNull public DynamicContext subContext(@NonNull FocusContext focusContext)
      Generate a new dynamic context with the specified focus context.

      This method is used by predicate expressions to establish a new focus for evaluating predicates. The focus context provides the information needed by fn:position() and fn:last().

      Parameters:
      focusContext - the focus context for the new sub-context
      Returns:
      a new dynamic context with the specified focus context
    • getFocusContext

      @Nullable public FocusContext getFocusContext()
      Get the focus context for this dynamic context.

      The focus context contains the context item, position, and size as defined in the XPath 3.1 evaluation context.

      Returns:
      the focus context, or null if no focus context is established
    • getStaticContext

      @NonNull public StaticContext getStaticContext()
      Get the static context associated with this dynamic context.
      Returns:
      the associated static context
    • getImplicitTimeZone

      @NonNull public ZoneId getImplicitTimeZone()
      Get the default time zone used for evaluation.
      Returns:
      the time zone identifier object
    • getImplicitTimeZoneAsDayTimeDuration

      @NonNull public IDayTimeDurationItem getImplicitTimeZoneAsDayTimeDuration()
      Get the default time zone used for evaluation.
      Returns:
      the time zone identifier object
    • setImplicitTimeZone

      public void setImplicitTimeZone(@NonNull ZoneId timezone)
      Set the implicit timezone to the provided value.

      Note: This value should only be adjusted when the context is first created. Once the context is used, this value is expected to be stable.

      Parameters:
      timezone - the timezone to use
    • setImplicitTimeZone

      public void setImplicitTimeZone(@NonNull IDayTimeDurationItem offset)
      Set the implicit timezone to the provided value.

      Note: This value should only be adjusted when the context is first created. Once the context is used, this value is expected to be stable.

      Parameters:
      offset - the offset which must be >= -PT14H and <= PT13H
      Throws:
      DateTimeFunctionException - with the code DateTimeFunctionException.INVALID_TIME_ZONE_VALUE_ERROR if the offset is < -PT14H or > PT14H
    • getCurrentDateTime

      @NonNull public ZonedDateTime getCurrentDateTime()
      Get the current date and time.
      Returns:
      the current date and time
    • getAvailableDocuments

      @NonNull public Map<URI,IDocumentNodeItem> getAvailableDocuments()
      Get the mapping of loaded documents from the document URI to the document node.
      Returns:
      the map of document URIs to document nodes
    • getDocumentLoader

      @NonNull public IDocumentLoader getDocumentLoader()
      Get the document loader assigned to this dynamic context.
      Returns:
      the loader
      Throws:
      ContextAbsentDynamicMetapathException - if a document loader is not configured for this dynamic context
    • setDocumentLoader

      public void setDocumentLoader(@NonNull IDocumentLoader documentLoader)
      Assign a document loader to this dynamic context.
      Parameters:
      documentLoader - the document loader to assign
    • getCachedResult

      @Nullable public ISequence<?> getCachedResult(@NonNull CalledContext callingContext)
      Get the cached function call result for evaluating a function that has the property IFunction.FunctionProperty.DETERMINISTIC.
      Parameters:
      callingContext - the function calling context information that distinguishes the call from any other call
      Returns:
      the cached result sequence for the function call
    • cacheResult

      public void cacheResult(@NonNull CalledContext callingContext, @NonNull ISequence<?> result)
      Cache a function call result for a that has the property IFunction.FunctionProperty.DETERMINISTIC.
      Parameters:
      callingContext - the calling context information that distinguishes the call from any other call
      result - the function call result
    • disablePredicateEvaluation

      @NonNull public DynamicContext disablePredicateEvaluation()
      Used to disable the evaluation of predicate expressions during Metapath evaluation.

      This can be useful for determining the potential targets identified by a Metapath expression as a partial evaluation, without evaluating that these targets match the predicate.

      Returns:
      this dynamic context
    • enablePredicateEvaluation

      @NonNull public DynamicContext enablePredicateEvaluation()
      Used to enable the evaluation of predicate expressions during Metapath evaluation.

      This is the default behavior if unchanged.

      Returns:
      this dynamic context
    • getConfiguration

      @NonNull public IConfiguration<MetapathEvaluationFeature<?>> getConfiguration()
      Get the Metapath evaluation configuration.
      Returns:
      the configuration
    • getVariableValue

      @NonNull public ISequence<?> getVariableValue(@NonNull IEnhancedQName name)
      Get the sequence value assigned to a let variable with the provided qualified name.
      Parameters:
      name - the variable qualified name
      Returns:
      the non-null variable value
      Throws:
      DynamicMetapathException - of the variable has not been assigned or if the variable value is null
    • lookupFunction

      @NonNull public IFunction lookupFunction(@NonNull IEnhancedQName name, int arity)
      Get the function with the provided name and arity.
      Parameters:
      name - the requested function's qualified name
      arity - the number of arguments in the requested function
      Returns:
      the function
      Throws:
      StaticMetapathException - with the code StaticMetapathException.NO_FUNCTION_MATCH if a matching function was not found
    • bindVariableValue

      @NonNull public DynamicContext bindVariableValue(@NonNull IEnhancedQName name, @NonNull ISequence<?> boundValue)
      Bind the variable name to the sequence value.
      Parameters:
      name - the name of the variable to bind
      boundValue - the value to bind to the variable
      Returns:
      this dynamic context
    • pushExecutionStack

      public void pushExecutionStack(@NonNull IExpression expression)
      Push the current expression under evaluation to the execution queue.
      Parameters:
      expression - the expression to push
    • popExecutionStack

      public void popExecutionStack(@NonNull IExpression expression)
      Pop the expression that was under evaluation from the execution queue.
      Parameters:
      expression - the expected expression to be popped
    • getExecutionStack

      @NonNull public Deque<IExpression> getExecutionStack()
      Return a copy of the current execution stack.
      Returns:
      the execution stack
    • formatExecutionStackTrace

      @NonNull public String formatExecutionStackTrace()
      Provides a formatted stack trace.
      Returns:
      the formatted stack trace