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

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

There is a newer version: 4.0.267
Show newest version
package jadex.rules.eca;

import jadex.commons.IResultCommand;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;

/**
 *  Wrapper that maps a command into a rule action.
 */
public class CommandAction implements IAction
{
	/** The command. */
	protected IResultCommand, CommandData> command;
	
	/**
	 * 
	 */
	public CommandAction(IResultCommand, CommandData> command)
	{
		this.command = command;
	}

	/**
	 * 
	 */
	public IFuture execute(IEvent event, IRule rule, Object context, Object condresult)
	{
		try
		{
			return command.execute(new CommandData(event, rule, context, condresult));
		}
		catch(Exception e)
		{
			return new Future(e);
//			throw new RuntimeException(e);
		}
	}

	/**
	 *  Get the command.
	 *  @return The command.
	 */
	public IResultCommand, CommandData> getCommand()
	{
		return command;
	}

	/**
	 *  Set the command.
	 *  @param command The command to set.
	 */
	public void setCommand(IResultCommand, CommandData> command)
	{
		this.command = command;
	}
	
	/**
	 * 
	 */
	public static class CommandData
	{
		/** The event. */
		protected IEvent event;
		
		/** The rule. */
		protected IRule rule;
		
		/** The context. */
		protected Object context;
		
		/** The condition result. */
		protected Object condresult;

		/**
		 *  Create a new CommandData. 
		 */
		public CommandData(IEvent event, IRule rule, Object context, Object condresult)
		{
			this.event = event;
			this.rule = rule;
			this.context = context;
			this.condresult = condresult;
		}

		/**
		 *  Get the event.
		 *  @return The event.
		 */
		public IEvent getEvent()
		{
			return event;
		}

		/**
		 *  Get the rule.
		 *  @return The rule.
		 */
		public IRule getRule()
		{
			return rule;
		}

		/**
		 *  Get the context.
		 *  @return The context.
		 */
		public Object getContext()
		{
			return context;
		}

		/**
		 *  Get the condresult.
		 *  @return The condresult.
		 */
		public Object getCondresult()
		{
			return condresult;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy