Class ComposerContext

All Implemented Interfaces:
IComposerContext, IEventChannel, IProfile, IProfileLifecycle, InferenceContext, Serializable

public final class ComposerContext extends InferenceContextDelegate implements IComposerContext
This internal composer context wraps the inference context of the client, and adds instance management to keep track of the instances that were activated by containers. And adds some methods for easier context access.
Since:
6.0
Author:
O. Kerpershoek, Jon van Leuven
See Also:
  • Method Details

    • wrapInstance

      protected static ComposerContext wrapInstance(InferenceContext context)
      Wrap the inference context with a ComposerContext when not already wrapped.
      Parameters:
      context - The inference context to wrap.
      Returns:
      The wrapped inference context.
    • forContainerId

      public IComposerContext forContainerId(String containerId)
      Description copied from interface: IComposerContext
      This method creates a child context of active composer context. It uses the provided container id to create a new ContainerId as the container id of the child context.
      Specified by:
      forContainerId in interface IComposerContext
      Parameters:
      containerId - id of the container for which the child context is created.
      Returns:
      The child context.
    • forInstance

      public IComposerContext forInstance(EntityValue instance)
      Description copied from interface: IComposerContext
      This method creates a child context of active composer context, using this method the provided instance is used as the active instance in the underlying inference context. It uses the provided instance to create a new ContainerId as the container id of the child context.
      Specified by:
      forInstance in interface IComposerContext
      Parameters:
      instance - instance for which the child context is created.
      Returns:
      The child context.
    • getContainerId

      public ContainerId getContainerId()
      Description copied from interface: IComposerContext
      This method returns the ContainerId of the container which is being composed in this context.
      Specified by:
      getContainerId in interface IComposerContext
      Returns:
      The container id.
    • getActiveInstance

      public IEntityInstance getActiveInstance(String entityName)
      Description copied from interface: InferenceContext
      This method returns the active instance for the specified type. When no active instance can be found for the specified type, the type is assumed to be a singleton instance. When this method is invoked for a non singleton type without any active instance, the call to the getSingletonInstance will fail due to a CreateInstanceException.
      Specified by:
      getActiveInstance in interface InferenceContext
      Overrides:
      getActiveInstance in class InferenceContextDelegate
      Parameters:
      entityName - The entity type for which the active instance is requested.
      Returns:
      The instance that is active for the specified type.
    • getFieldValue

      protected IValue getFieldValue(String fieldName, boolean createInstanceForEmptyRelation)
    • getFieldDomain

      protected IDomainValue[] getFieldDomain(String fieldName)
    • enterContext

      protected void enterContext(EntityValue entityContext)
    • leaveContext

      protected void leaveContext(EntityValue entityContext)
    • getLastRepeatInstanceId

      protected EntityValue getLastRepeatInstanceId()
      Returns the last instance which was activated due to a repeat expression, or null if no instance was activated.
      Returns:
      a reference to the last instance activated by a repeat expression or null.
    • evaluateCondition

      protected boolean evaluateCondition(ICondition condition, boolean unknownValue)
    • evaluateTsl

      protected IMultilingualText evaluateTsl(IDynamicText tslText)
    • isVisible

      protected boolean isVisible(AbstractReference reference)
    • evaluateRepeatExpression

      protected IEntityInstance[] evaluateRepeatExpression(AbstractReference reference)
      This method returns the array of instances for which the content should be expanded. This method can return three different result:
      • null - No instance needs to be activated, as the reference did not define a repeat expression.
      • empty array - No suitable instance was found, the content can be discarded.
      • instance array - The content needs to be expanded for each instance in the array.
      Parameters:
      reference - The reference containing the repeat expression.
      Returns:
      Array of instances for which the content should be expanded, or null when no context needs to be used.
      Throws:
      RuleEngineException - exception when the repeat expression is not valid
    • contextsForReference

      protected ComposerContext[] contextsForReference(AbstractReference reference)
      This method returns the contexts for a reference. If the reference contains a repeat expression, this expression is evaluated and a (sorted) array of contexts is returned. If the reference does not contain a repeat expression then a single context representing the reference is returned.
      Parameters:
      reference - The reference to evaluate
      Returns:
      An array of composer contexts, never null.
      Throws:
      AppException - exception thrown when the context cannot be determined