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

nyla.solutions.global.patterns.command.TemplateCommand Maven / Gradle / Ivy

Go to download

Nyla Solutions Global Java API provides support for basic application utilities (application configuration, data encryption, debugger and text processing).

The newest version!
package nyla.solutions.global.patterns.command;

import nyla.solutions.global.exception.RequiredException;

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

	/**
	 * Execute a target command to before and after command execution processing
	 * @see nyla.solutions.global.patterns.command.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