io.sarl.lang.core
Class Capacities
final class Capacities
extends java.lang.Object
Utility functions related to the capacities.
Maven Group Identifier:
io.sarl.lang
Maven Artifact Identifier:
core
Since:
0.5
Action Summary
Modifier and type Action and description
static C createSkillDelegator(Skill,Class<T>,AgentTrait)
Create a delegator for the given skill.
static C createSkillDelegatorIfPossible(Skill,Class<T>,AgentTrait)
Create a delegator for the given skill when it is possible.
static AgentTrait getCaller
Replies the caller of the capacity functions.
Action Details
createSkillDelegator(Skill,Class<T>,AgentTrait)
def createSkillDelegator(Skill,Class<T>,AgentTrait) : C

with C extends Capacity

throws java.lang.Exception

Create a delegator for the given skill.

The delegator is wrapping the original skill in order to set the value of the caller that will be replied by getCaller(). The associated caller is given as argument.

The delegator is an instance of an specific inner type, sub-type of Capacity.ContextAwareCapacityWrapper, which is declared in the given capacity.

This function fails if the delegator instance cannot be created due to inner type not found, invalid constructor signature, run-time exception when creating the instance. This functions assumes that the name of the definition type is the same as Capacity.ContextAwareCapacityWrapper, and this definition extends the delegator definition of the first super type of the capacity, and implements all the super types of the capacity. The expected constructor for this inner type has the same signature as the one of Capacity.ContextAwareCapacityWrapper.

The function createSkillDelegatorIfPossible(Skill, Class, AgentTrait) is a similar function than this function, except that it does not fail when the delegator instance cannot be created. In this last case, the function createSkillDelegatorIfPossible(Skill, Class, AgentTrait) reply the original skill itself.
Parameters:
<C> - the type of the capacity.
originalSkill - the skill to delegate to after ensure the capacity caller is correctly set.
capacity - the capacity that contains the definition of the delegator.
capacityCaller - the caller of the capacity functions.
Returns:
the delegator.
Throws exception:
  • java.lang.Exception: if the delegator cannot be created.
See:
createSkillDelegatorIfPossible(Skill,Class<T>,AgentTrait)
createSkillDelegatorIfPossible(Skill,Class<T>,AgentTrait)
def createSkillDelegatorIfPossible(Skill,Class<T>,AgentTrait) : C

with C extends Capacity

throws java.lang.ClassCastException

Create a delegator for the given skill when it is possible.

The delegator is wrapping the original skill in order to set the value of the caller that will be replied by getCaller(). The associated caller is given as argument.

The delegator is an instance of an specific inner type, sub-type of Capacity.ContextAwareCapacityWrapper, which is declared in the given capacity.

This functions assumes that the name of the definition type is the same as Capacity.ContextAwareCapacityWrapper, and this definition extends the delegator definition of the first super type of the capacity, and implements all the super types of the capacity. The expected constructor for this inner type has the same signature as the one of Capacity.ContextAwareCapacityWrapper. If the delegator instance cannot be created due to to inner type not found, invalid constructor signature, run-time exception when creating the instance, this function replies the original skill.

The function createSkillDelegator(Skill, Class, AgentTrait) is a similar function than this function, except that it fails when the delegator instance cannot be created.
Parameters:
<C> - the type of the capacity.
originalSkill - the skill to delegate to after ensure the capacity caller is correctly set.
capacity - the capacity that contains the definition of the delegator.
capacityCaller - the caller of the capacity functions.
Returns:
the delegator, or the original skill.
Throws exception:
  • java.lang.ClassCastException: if the skill is not implementing the capacity.
See:
createSkillDelegator(Skill,Class<T>,AgentTrait)
getCaller
def getCaller : AgentTrait
Replies the caller of the capacity functions.

The replied value has a meaning inside the skills' functions that are implemented the capacities' functions.
Returns:
the caller, or null if the caller is unknown (assuming that the caller is the agent itself).