jadex.bdibpmn.BpmnPlanExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-kernel-bdibpmn Show documentation
Show all versions of jadex-kernel-bdibpmn Show documentation
The Jadex BDI-BPMN kernel allows to use BPMN
workflow descriptions as alternative
description for BDI agent plans.
package jadex.bdibpmn;
import jadex.bdi.model.OAVBDIMetaModel;
import jadex.bdi.runtime.IPlanExecutor;
import jadex.bdi.runtime.PlanFailureException;
import jadex.bdi.runtime.interpreter.BDIInterpreter;
import jadex.bdi.runtime.interpreter.EventProcessingRules;
import jadex.bdi.runtime.interpreter.OAVBDIRuntimeModel;
import jadex.bdi.runtime.interpreter.PlanRules;
import jadex.bpmn.BpmnModelLoader;
import jadex.bpmn.model.MBpmnModel;
import jadex.bpmn.model.MPool;
import jadex.bpmn.runtime.ProcessThread;
import jadex.bpmn.runtime.handler.EventEndErrorActivityHandler.EventEndErrorException;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* A plan executor for plans modeled in BPMN. These plan steps
* are executed on the agent thread.
*/
public class BpmnPlanExecutor implements IPlanExecutor, Serializable
{
//-------- attributes --------
/** Model loader (todo: classpath issues?) */
protected BpmnModelLoader loader;
//-------- constructor --------
/**
* Create a new BPMN plan executor.
*/
public BpmnPlanExecutor()
{
this.loader = new BpmnModelLoader();
}
//-------- IPlanExecutor interface --------
/**
* Create the body of a plan.
* @param rplan The rplan.
* @return The created body state.
* May throw any kind of exception, when the body creation fails
*/
public Object createPlanBody(BDIInterpreter interpreter, Object rcapability, Object rplan) throws Exception
{
// Create plan body object.
Object mplan = interpreter.getState().getAttributeValue(rplan, OAVBDIRuntimeModel.element_has_model);
Object mbody = interpreter.getState().getAttributeValue(mplan, OAVBDIMetaModel.plan_has_body);
String impl = (String)interpreter.getState().getAttributeValue(mbody, OAVBDIMetaModel.body_has_impl);
String[] imports = interpreter.getModel(rcapability).getAllImports();
// is rid of parent ok?
MBpmnModel bodymodel = loader.loadBpmnModel(impl, imports, interpreter.getClassLoader(),
new Object[]{interpreter.getModel().getResourceIdentifier(), interpreter.getComponentIdentifier().getRoot()});
if(bodymodel==null)
{
throw new RuntimeException("Plan body could not be created: "+impl);
}
// Check names of pools, if any.
else
{
List pools = bodymodel.getPools();
if(pools!=null && !pools.isEmpty())
{
for(int i=0; i