
nyla.solutions.spring.scripting.SpringExecutable Maven / Gradle / Ivy
The newest version!
package nyla.solutions.spring.scripting;
import java.util.Map;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.ParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import nyla.solutions.commas.Command;
import nyla.solutions.core.data.Environment;
import nyla.solutions.core.exception.SystemException;
import nyla.solutions.core.util.Config;
import nyla.solutions.core.util.Debugger;
/**
*
* Execute a spring expression language SPEL
*
* <bean id="cacheProcessDocSummary"
class="solutions.global.patterns.scripting">
<property name="expression"
value="${T(solutions.global.util.Debugger).println('Hello World')}">
</property>
</bean>
<bean id="mkdirPrintingExecutable"
class="com.merck.mrl.global.patterns.scripting.SpringExecutable">
<property name="expression"
value="new java.io.File(${T(solutions.global.util.Config).getProperty('solutions.global.media.RotateImageFileCommand.outputPath')}).mkdir()">
</property>
</bean>
*
* @author Gregory Green
*
*/
public class SpringExecutable implements Command
{
/**
* Default constructor
*/
public SpringExecutable()
{
parser = new SpelExpressionParser();
}//---------------------------------------------
/**
* Evaluation the boolean based on the evaluation object
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Integer execute(Environment env)
{
try
{
StandardEvaluationContext context = new StandardEvaluationContext(this.evaluationObject);
Map runtimeVariables = Config.getProperties();
//Map runtimeVariables = new Hashtable();
if(env != null)
{
runtimeVariables.putAll(env.getMap());
}
if(this.variables != null)
runtimeVariables.putAll(this.variables);
//Set variables
context.setVariables(runtimeVariables);
Debugger.println(this,"Parsing expression="+expression);
Expression expression = parser.parseExpression(this.expression,new TemplatedParserContext());
Object object = expression.getValue(context);
if(env != null && valueKey != null && object != null)
{
//put results in environment variable
env.put(valueKey,object);
}
return 0;
}
catch (Exception e)
{
throw new SystemException("expression="+expression+" evaluationObject="+evaluationObject+" \n ERROR:"+Debugger.stackTrace(e));
}
}//---------------------------------------------
/**
* @return the evaluationObject
*/
public Object getEvaluationObject()
{
return evaluationObject;
}//---------------------------------------------
/**
* @param evaluationObject the evaluationObject to set
*/
public void setEvaluationObject(Object evaluationObject)
{
this.evaluationObject = evaluationObject;
}//---------------------------------------------
/**
* @return the expression
*/
public String getExpression()
{
return expression;
}//---------------------------------------------
/**
* @param expression the expression to set
*/
public void setExpression(String expression)
{
this.expression = expression;
}//---------------------------------------------
/**
* @return the variables
*/
public Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy