All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.rules.eca.MethodAction Maven / Gradle / Ivy

There is a newer version: 4.0.267
Show newest version
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);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy