jadex.bpmn.runtime.task.PojoTaskWrapper 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.task;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jadex.bpmn.model.MParameter;
import jadex.bpmn.model.task.ITask;
import jadex.bpmn.model.task.ITaskContext;
import jadex.bpmn.runtime.ProcessThread;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.commons.FieldInfo;
import jadex.commons.MethodInfo;
import jadex.commons.SReflect;
import jadex.commons.SUtil;
import jadex.commons.SimpleParameterGuesser;
import jadex.commons.future.ExceptionDelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
/**
* Task that acts as wrapper for pojo tasks.
* Allows for using pojo tasks in the same way as conventional ITasks.
*/
public class PojoTaskWrapper implements ITask
{
/** The pojo task. */
protected Object pojotask;
/** The cancel method. */
protected Method cancelmethod;
/** The resinjections. */
protected Map resinjections;
/**
* Bean constructor.
*/
public PojoTaskWrapper()
{
}
/**
* Create a new wrapper task.
*/
public PojoTaskWrapper(Object pojotask, IInternalAccess ia, ProcessThread thread, List cominjections, Map> arginjections, Map resinjections)
{
this.pojotask = pojotask;
this.resinjections = resinjections;
for(FieldInfo fi: cominjections)
{
try
{
Field f = fi.getField(ia.getClassLoader());
if(SReflect.isSupertype(f.getType(), IInternalAccess.class))
{
f.setAccessible(true);
f.set(pojotask, ia);
}
else if(SReflect.isSupertype(f.getType(), IExternalAccess.class))
{
f.setAccessible(true);
f.set(pojotask, ia.getExternalAccess());
}
}
catch(Exception e)
{
System.out.println("Component injection failed: "+e);
}
}
for(String name: arginjections.keySet())
{
List infos = arginjections.get(name);
for(FieldInfo fi: infos)
{
try
{
Field f = fi.getField(ia.getClassLoader());
f.setAccessible(true);
f.set(pojotask, thread.getParameterValue(name));
}
catch(Exception e)
{
System.out.println("Argument injection failed: "+e);
}
}
}
for(String name: resinjections.keySet())
{
FieldInfo fi = resinjections.get(name);
try
{
Field f = fi.getField(ia.getClassLoader());
f.setAccessible(true);
f.set(pojotask, thread.getParameterValue(name));
}
catch(Exception e)
{
System.out.println("Result injection failed: "+e);
}
}
}
/**
* Execute the task.
* @param context The accessible values.
* @param process The process instance executing the task.
* @return To be notified, when the task has completed.
*/
public IFuture execute(final ITaskContext context, final IInternalAccess process)
{
final Future ret = new Future();
MethodInfo cancelmi = context.getActivity().getCancelMethod(process.getClassLoader());
if(cancelmi!=null)
{
cancelmethod = cancelmi.getMethod(process.getClassLoader());
}
MethodInfo bodymi = context.getActivity().getBodyMethod(process.getClassLoader());
Method bodymethod = bodymi.getMethod(process.getClassLoader());
try
{
bodymethod.setAccessible(true);
Set