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

nyla.solutions.global.patterns.aop.TransformationAroundCommandAdvice 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.aop;

import nyla.solutions.global.patterns.command.Command;
import nyla.solutions.global.util.Organizer;

import org.aspectj.lang.ProceedingJoinPoint;

public class TransformationAroundCommandAdvice
{
	/**
	 * transform the arguments and return for a join point
	 * @param proceedingJoinPoint
	 * @return
	 * @throws Throwable
	 */
	public Object transform(ProceedingJoinPoint proceedingJoinPoint) throws Throwable 
	{
		Object[] arguments = proceedingJoinPoint.getArgs();
		if(beforeCommand != null)
		{
			Object inputArgument = arguments;
			
			if(arguments != null && arguments.length == 1)
			{
				//only use a single argument
				inputArgument = arguments[0];
			}
			
			Object resultArguments = beforeCommand.execute(inputArgument);
			
			arguments = Organizer.toArray(resultArguments);
			
		}
		
	    // proceeding processing and get results
	    Object retVal = proceedingJoinPoint.proceed(arguments);
	    
	    
	    if(afterCommand != null)
	    {
	    	retVal = afterCommand.execute(retVal);
	    }
	    
	    return retVal;
	}// ------------------------------------------------
	
	/**
	 * @return the beforeCommand
	 */
	public Command getBeforeCommand()
	{
		return beforeCommand;
	}
	/**
	 * @param beforeCommand the beforeCommand to set
	 */
	public void setBeforeCommand(Command beforeCommand)
	{
		this.beforeCommand = beforeCommand;
	}
	/**
	 * @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 afterCommand = null;
	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy