Class ComposerContext
java.lang.Object
com.aquima.interactions.profile.wrapper.ProfileDelegate
com.aquima.interactions.rule.inference.InferenceContextDelegate
com.aquima.interactions.composer.model.ComposerContext
- All Implemented Interfaces:
IComposerContext
,IEventChannel
,IProfile
,IProfileLifecycle
,InferenceContext
,Serializable
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 Summary
Modifier and TypeMethodDescriptionprotected ComposerContext[]
contextsForReference
(AbstractReference reference) This method returns the contexts for a reference.protected void
enterContext
(EntityValue entityContext) protected boolean
evaluateCondition
(ICondition condition, boolean unknownValue) protected IEntityInstance[]
evaluateRepeatExpression
(AbstractReference reference) This method returns the array of instances for which the content should be expanded.protected IMultilingualText
evaluateTsl
(IDynamicText tslText) forContainerId
(String containerId) This method creates a child context of active composer context.forInstance
(EntityValue instance) 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.getActiveInstance
(String entityName) This method returns the active instance for the specified type.This method returns theContainerId
of the container which is being composed in this context.protected IDomainValue[]
getFieldDomain
(String fieldName) protected IValue
getFieldValue
(String fieldName, boolean createInstanceForEmptyRelation) protected EntityValue
Returns the last instance which was activated due to a repeat expression, or null if no instance was activated.protected boolean
isVisible
(AbstractReference reference) protected void
leaveContext
(EntityValue entityContext) protected static ComposerContext
wrapInstance
(InferenceContext context) Wrap the inference context with a ComposerContext when not already wrapped.Methods inherited from class com.aquima.interactions.rule.inference.InferenceContextDelegate
getInferenceDetails
Methods inherited from class com.aquima.interactions.profile.wrapper.ProfileDelegate
activate, addEventListener, commitTransaction, createInstance, createInstance, deleteInstance, getAllInstancesForEntity, getEntityDefinition, getInstance, getInstanceById, getInstanceByName, getProfile, getSingletonInstance, getState, getSupportedEvents, passivate, removeEventListener, restore, rollbackTransaction, startTransaction
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.aquima.interactions.foundation.events.IEventChannel
addEventListener, getSupportedEvents, removeEventListener
Methods inherited from interface com.aquima.interactions.rule.InferenceContext
getInferenceDetails
Methods inherited from interface com.aquima.interactions.profile.IProfile
commitTransaction, createInstance, createInstance, deleteInstance, getAllInstancesForEntity, getEntityDefinition, getInstance, getInstanceById, getInstanceByName, getSingletonInstance, getState, restore, rollbackTransaction, startTransaction
Methods inherited from interface com.aquima.interactions.profile.IProfileLifecycle
activate, passivate
-
Method Details
-
wrapInstance
Wrap the inference context with a ComposerContext when not already wrapped.- Parameters:
context
- The inference context to wrap.- Returns:
- The wrapped inference context.
-
forContainerId
Description copied from interface:IComposerContext
This method creates a child context of active composer context. It uses the provided container id to create a newContainerId
as the container id of the child context.- Specified by:
forContainerId
in interfaceIComposerContext
- Parameters:
containerId
- id of the container for which the child context is created.- Returns:
- The child context.
-
forInstance
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 newContainerId
as the container id of the child context.- Specified by:
forInstance
in interfaceIComposerContext
- Parameters:
instance
- instance for which the child context is created.- Returns:
- The child context.
-
getContainerId
Description copied from interface:IComposerContext
This method returns theContainerId
of the container which is being composed in this context.- Specified by:
getContainerId
in interfaceIComposerContext
- Returns:
- The container id.
-
getActiveInstance
public IEntityInstance getActiveInstance(String entityName) throws UnknownInstanceException, UnknownEntityException, CreateInstanceException 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 interfaceInferenceContext
- Overrides:
getActiveInstance
in classInferenceContextDelegate
- Parameters:
entityName
- The entity type for which the active instance is requested.- Returns:
- The instance that is active for the specified type.
- Throws:
UnknownInstanceException
- This exception type is raised when no active instance could be found for the specified type.UnknownEntityException
- This exception type is raised when the entity type is unknown.CreateInstanceException
- This type of exception may be raised when a singleton instance could not be created for the specified type.
-
getFieldValue
protected IValue getFieldValue(String fieldName, boolean createInstanceForEmptyRelation) throws AppException - Throws:
AppException
-
getFieldDomain
- Throws:
AppException
-
enterContext
- Throws:
AppException
-
leaveContext
- Throws:
AppException
-
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) throws RuleEngineException - Throws:
RuleEngineException
-
evaluateTsl
- Throws:
RuleEngineException
-
isVisible
- Throws:
RuleEngineException
-
evaluateRepeatExpression
protected IEntityInstance[] evaluateRepeatExpression(AbstractReference reference) throws RuleEngineException, AppException 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 validAppException
-
contextsForReference
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
-