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

nyla.solutions.commas.TemplateCommand Maven / Gradle / Ivy

The newest version!
package nyla.solutions.commas;

import nyla.solutions.core.exception.RequiredException;

/**
 * @author Gregory Green
 *
 */
public class TemplateCommand implements Command 
{

	/**
	 * Execute a target command to before and after command execution processing
	 * @see nyla.solutions.commas.Command#execute(java.lang.Object)
	 */
	public Object execute(Object source)
	{
		if (this.targetCommand == null)
			throw new RequiredException("this.targetCommand");
		
		
		if (beforeCommand != null)
		{
			source = beforeCommand.execute(source);
		}
		
		
		//Perform operation
		source = targetCommand.execute(source);
	    
	    
	    if(afterCommand == null)
	    	return source;
	    
	    return afterCommand.execute(source);
	}
	
	/**
	 * @return the beforeCommand
	 */
	public Command getBeforeCommand()
	{
		return beforeCommand;
	}
	/**
	 * @param beforeCommand the beforeCommand to set
	 */
	public void setBeforeCommand(Command beforeCommand)
	{
		this.beforeCommand = beforeCommand;
	}
	/**
	 * @return the targetCommand
	 */
	public Command getTargetCommand()
	{
		return targetCommand;
	}
	/**
	 * @param targetCommand the targetCommand to set
	 */
	public void setTargetCommand(Command targetCommand)
	{
		this.targetCommand = targetCommand;
	}
	
	/**
	 * @return the afterCommand
	 */
	public Command getAfterCommand()
	{
		return afterCommand;
	}
	/**
	 * @param afterCommand the afterCommand to set
	 */
	public void setAfterCommand(Command afterCommand)
	{
		this.afterCommand = afterCommand;
	}

	private Command  beforeCommand = null;
	private Command targetCommand = null;
	private Command afterCommand = null;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy