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

nyla.solutions.global.patterns.expression.ScriptingBooleanExpression 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.expression;

import java.util.HashMap;
import java.util.Map;
import nyla.solutions.global.exception.SystemException;
import nyla.solutions.global.exception.fault.FaultException;
import nyla.solutions.global.patterns.scripting.Scripting;
import nyla.solutions.global.util.Debugger;


/**
 * Implements boolean expressing using a scripting instance
 * @author Gregory Green
 *
 */
public class ScriptingBooleanExpression implements BooleanExpression
{
	public ScriptingBooleanExpression()
	{
	}//---------------------------------------------

	/**
	 * Evaluation the boolean based on the evaluation object
	 */
	public synchronized Boolean execute(Object evaluationObject)
	{
		
		 try
		{
			
			Boolean bool = this.scripting.interpret(expression, evaluationObject);
			 return bool;
		} 
		catch (FaultException e)
		{
			throw e;
		}
		catch (Exception e)
		{
			throw new SystemException("expression="+expression+" evaluationObject="+evaluationObject+" \n ERROR:"+Debugger.stackTrace(e));
		}
		  
	}//---------------------------------------------
	
	/**
	 * @return the expression
	 */
	public synchronized String getExpression()
	{
		return expression;
	}//---------------------------------------------


	/**
	 * @param expression the expression to set
	 */
	public  synchronized void setExpression(String expression)
	{
		this.expression = expression;
	}//---------------------------------------------

	/**
	 * @return the variables
	 */
	public Map getVariables()
	{
		if(variables == null)
			return null;
		
		return new HashMap(variables);
	}

	/**
	 * @param variables the variables to set
	 */
	public void setVariables(Map variables)
	{
		if(variables == null)
		{
			this.variables = null;
			return;
		}
		
		this.variables = new HashMap(variables);
	}
	
	

	/**
	 * @return the scripting
	 */
	public Scripting getScripting()
	{
		return scripting;
	}

	/**
	 * @param scripting the scripting to set
	 */
	public void setScripting(Scripting scripting)
	{
		this.scripting = scripting;
	}



	private Map variables = null;
	private Scripting scripting;
	private String expression = null;
}