jadex.rules.eca.MethodAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-rules-eca Show documentation
Show all versions of jadex-rules-eca Show documentation
Small Java annotation-based event-condition-action rule engine.
package jadex.rules.eca;
import java.lang.reflect.Method;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
/**
*
*/
public class MethodAction implements IAction
{
/** The object. */
protected Object object;
/** The method. */
protected Method method;
/**
*
*/
public MethodAction(Object object, Method method)
{
this.object = object;
this.method = method;
}
/**
*
*/
public IFuture execute(IEvent event, IRule rule, Object context, Object condresult)
{
try
{
method.setAccessible(true);
Object result = method.invoke(object, new Object[]{event, rule, context, condresult});
if(result instanceof IFuture)
{
return (Future)result;
}
else
{
return new Future((T)result);
}
}
catch(Exception e)
{
return new Future(e);
// throw new RuntimeException(e);
}
}
}