jadex.bpmn.runtime.ProcessServiceInvocationHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-kernel-bpmn Show documentation
Show all versions of jadex-kernel-bpmn Show documentation
The Jadex BPMN kernel provides a workflow kernel for the standardized business process modeling notation. The kernel relies on annotated BPMN diagrams, which include detailed execution information.
package jadex.bpmn.runtime;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import jadex.bpmn.features.IBpmnComponentFeature;
import jadex.bpmn.features.IInternalBpmnComponentFeature;
import jadex.bpmn.model.MActivity;
import jadex.bpmn.model.MBpmnModel;
import jadex.bpmn.model.MSubProcess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.modelinfo.UnparsedExpression;
import jadex.bridge.service.annotation.Service;
import jadex.bridge.service.component.interceptors.FutureFunctionality;
import jadex.commons.SReflect;
import jadex.commons.SUtil;
import jadex.commons.future.Future;
import jadex.javaparser.SJavaParser;
/**
* Invocation handler for mapping service requests to
* start events of BPMN processes.
*/
@Service // Hack!!! Let BasicServiceInvocationHandler know that this is a service implementation.
public class ProcessServiceInvocationHandler implements InvocationHandler
{
//-------- constants --------
/** The future result parameter name. */
public static final String THREAD_PARAMETER_SERVICE_RESULT = "$$service_result";
/** The user result parameter name. */
// Todo: remove. use explicit model.
public static final String EVENT_PARAMETER_SERVICE_RESULT = "service_result";
//-------- attributes --------
/** The process instance. */
protected IInternalAccess instance;
/** The method / event mapping. */
protected Map events;
//-------- constructors --------
/**
* Create a new process service invocation handler.
*/
public ProcessServiceInvocationHandler(IInternalAccess instance, Map events)
{
this.instance = instance;
this.events = events;
}
/**
* Create a new process service invocation handler.
*/
public ProcessServiceInvocationHandler(IInternalAccess instance, String actid)
{
this.instance = instance;
MBpmnModel model = (MBpmnModel)instance.getModel().getRawModel();
MSubProcess proc = (MSubProcess)model.getActivityById(actid);
final Map> evtsubstarts = model.getEventSubProcessStartEventMapping();
List macts = evtsubstarts.get(proc);
events = new HashMap();
Class> iface = null;
for(MActivity mact: macts)
{
if(MBpmnModel.EVENT_START_MESSAGE.equals(mact.getActivityType()))
{
if(mact.hasPropertyValue(MActivity.IFACE))
{
if(iface==null)
{
UnparsedExpression uexp = mact.getPropertyValue(MActivity.IFACE);
iface = (Class>)SJavaParser.parseExpression(uexp, model.getModelInfo().getAllImports(), instance.getClassLoader()).getValue(null);
}
UnparsedExpression uexp = mact.getPropertyValue(MActivity.METHOD);
String method = (String)SJavaParser.parseExpression(uexp, model.getModelInfo().getAllImports(), instance.getClassLoader()).getValue(null);
// String method = mact.getPropertyValue("method");
events.put(method, mact);
}
}
}
}
//-------- InvocationHandler interface --------
/**
* Called when a method is invoked on a proxy.
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
// Drop goal when future is terminated from service caller
final Future