cz.cuni.amis.pogamut.sposh.executor
Class BehaviorWorkExecutor

Package class diagram package BehaviorWorkExecutor
java.lang.Object
  extended by cz.cuni.amis.pogamut.sposh.executor.BehaviorWorkExecutor
All Implemented Interfaces:
ILogicWorkExecutor, IWorkExecutor

public class BehaviorWorkExecutor
extends Object
implements ILogicWorkExecutor

Executor for posh plans that will execute annotated methods on the object.

You put behavior objects into this IWorkExecutor that have some methods annotated with SPOSHAction or SPOSHSense. Names of these methods are used stored as primitives. There can't be two behavior methods with same names, (e.g. testMethod() from behavior object A and testMethod() from object B or testMethod(String) from object A). If such sitation occurs, BehaviorWorkExecutor#addBehavior(java.lang.Object) will throw IllegalArgumentException.

When PoshEngine asks to execute some primitive, this executor will look in list of primitives it is capable to execute (names of annotated methods from behavior objects) and if it has some behavior method with same name, it executed it and returns value.

Author:
Honza

Nested Class Summary
protected  class BehaviorWorkExecutor.BehaviorMethod
          Class for storing methods that can be executed as primitives.
 
Field Summary
protected  List<JavaBehaviour> behaviors
           
protected  HashMap<String,BehaviorWorkExecutor.BehaviorMethod> primitives
          Map that maps name of primitives into behavior methods.
 
Constructor Summary
BehaviorWorkExecutor()
          Create BehaviorWorkExecutor with no methods.
BehaviorWorkExecutor(JavaBehaviour behavior)
          Create BehaviorWorkExecutor with primitives from behavior.
 
Method Summary
 void addBehavior(JavaBehaviour behavior)
          Take the behavior object, find its methods annotated with either SPOSHAction or SPOSHSense and add them as primitives this work executor can process.
 ActionResult executeAction(String primitive, VariableContext ctx)
          Uses executePrimitive(String, VariableContext).
 Object executeSense(String primitive, VariableContext ctx)
          Uses executePrimitive(String, VariableContext).
 void logicAfterPlan()
          Method that is triggered every time the plan for executor is evaluated.
 void logicBeforePlan()
          Method that is triggered every time the plan for executor is evaluated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

primitives

protected final HashMap<String,BehaviorWorkExecutor.BehaviorMethod> primitives
Map that maps name of primitives into behavior methods.


behaviors

protected List<JavaBehaviour> behaviors
Constructor Detail

BehaviorWorkExecutor

public BehaviorWorkExecutor()
Create BehaviorWorkExecutor with no methods.


BehaviorWorkExecutor

public BehaviorWorkExecutor(JavaBehaviour behavior)
Create BehaviorWorkExecutor with primitives from behavior.

Parameters:
behavior - object from which we will add primitives into this worker.
Method Detail

addBehavior

public void addBehavior(JavaBehaviour behavior)
Take the behavior object, find its methods annotated with either SPOSHAction or SPOSHSense and add them as primitives this work executor can process.

Parameters:
behavior -
Throws:
IllegalArgumentException - if behavior contains primitive method with same name, that is already contained in primitives of this worker.

executeSense

public Object executeSense(String primitive,
                           VariableContext ctx)
Uses executePrimitive(String, VariableContext).

Specified by:
executeSense in interface IWorkExecutor
Parameters:
primitive - name of primitive
ctx - variable context for sense containing possible parameters
Returns:
result of executed primitive

executeAction

public ActionResult executeAction(String primitive,
                                  VariableContext ctx)
Uses executePrimitive(String, VariableContext).

Specified by:
executeAction in interface IWorkExecutor
Parameters:
primitive - name of primitive
ctx - variable context for action containing possible parameters
Returns:
result of executed primitive

logicAfterPlan

public void logicAfterPlan()
Description copied from interface: ILogicWorkExecutor
Method that is triggered every time the plan for executor is evaluated. It is triggered right after the plan evaluation.

Specified by:
logicAfterPlan in interface ILogicWorkExecutor

logicBeforePlan

public void logicBeforePlan()
Description copied from interface: ILogicWorkExecutor
Method that is triggered every time the plan for executor is evaluated. It is triggered right before the plan evaluation.

Specified by:
logicBeforePlan in interface ILogicWorkExecutor


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.