org.specrunner.expressions.core
Class ExpressionJanino

java.lang.Object
  extended by org.specrunner.expressions.core.AbstractExpression
      extended by org.specrunner.expressions.core.ExpressionJanino
All Implemented Interfaces:
IExpression

public class ExpressionJanino
extends AbstractExpression

A Janino expression.

Author:
Thiago Santos

Field Summary
protected static ICache<ExpressionKey,org.codehaus.commons.compiler.IExpressionEvaluator> cache
          Cache of expressions.
static String FEATURE_JDK_COMPILER
          Feature to enable Janino work with JDK expressions ( org.codehaus.commons.compiler.jdk.ExpressionEvaluator).
 
Fields inherited from class org.specrunner.expressions.core.AbstractExpression
DEFAULT_PRECEDENCE
 
Fields inherited from interface org.specrunner.expressions.IExpression
FEATURE_PRECEDENCE
 
Constructor Summary
ExpressionJanino(IExpressionFactory parent, Object source)
          Basic constructor.
 
Method Summary
protected  Object arguments(IContext context, String expression, List<String> args, List<Class<?>> types, List<Object> values, boolean silent)
          Prepare arguments.
protected  Object eval(Object source, String expression, List<String> args, List<Class<?>> types, List<Object> values, boolean silent)
          Evaluate the expression.
 Object evaluate(IContext context, boolean silent)
          Given a context, evaluates the expression.
protected  Object getValue(IContext context, String text, boolean silent)
          Get the value for a expression.
protected  Number numericValue(String original)
          Convert to number.
protected  Object tryObject(Class<?> returnType, String expression, String[] arrayArgs, Object[] arrayValues, Class<?>[] arrayTypes)
          Compute the expression assuming return type will be the specified.
 
Methods inherited from class org.specrunner.expressions.core.AbstractExpression
evaluate, getParent, getPrecedence, setPrecedence
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FEATURE_JDK_COMPILER

public static final String FEATURE_JDK_COMPILER
Feature to enable Janino work with JDK expressions ( org.codehaus.commons.compiler.jdk.ExpressionEvaluator).


cache

protected static ICache<ExpressionKey,org.codehaus.commons.compiler.IExpressionEvaluator> cache
Cache of expressions.

Constructor Detail

ExpressionJanino

public ExpressionJanino(IExpressionFactory parent,
                        Object source)
Basic constructor.

Parameters:
parent - The parent factory.
source - The object source.
Method Detail

evaluate

public Object evaluate(IContext context,
                       boolean silent)
                throws ExpressionException
Description copied from interface: IExpression
Given a context, evaluates the expression.

Parameters:
context - A contextual information.
silent - true, for evaluation without exceptions, false, otherwise.
Returns:
The result of expression evaluation.
Throws:
ExpressionException - On evaluation errors.

arguments

protected Object arguments(IContext context,
                           String expression,
                           List<String> args,
                           List<Class<?>> types,
                           List<Object> values,
                           boolean silent)
                    throws ExpressionException
Prepare arguments.

Parameters:
context - The context.
expression - The expression.
args - The arguments.
types - The types.
values - The values.
silent - Silent option.
Returns:
The resulting object, null, otherwise.
Throws:
ExpressionException - On expression errors.

getValue

protected Object getValue(IContext context,
                          String text,
                          boolean silent)
                   throws ExpressionException
Get the value for a expression.

Parameters:
context - The context.
text - The expression.
silent - The silent mode.
Returns:
An object.
Throws:
ExpressionException - On expression errors.

eval

protected Object eval(Object source,
                      String expression,
                      List<String> args,
                      List<Class<?>> types,
                      List<Object> values,
                      boolean silent)
               throws ExpressionException
Evaluate the expression.

Parameters:
source - The expression source.
expression - The expression as string.
args - The arguments.
types - The argument types.
values - The argument values.
silent - Silent mode.
Returns:
The resulting object.
Throws:
ExpressionException - On evaluation errors.

tryObject

protected Object tryObject(Class<?> returnType,
                           String expression,
                           String[] arrayArgs,
                           Object[] arrayValues,
                           Class<?>[] arrayTypes)
                    throws Exception
Compute the expression assuming return type will be the specified.

Parameters:
returnType - The calling result type.
expression - The expression to be evaluated.
arrayArgs - The formal parameters.
arrayValues - The actual parameters.
arrayTypes - The argument types.
Returns:
The expression result.
Throws:
Exception - On processing errors.

numericValue

protected Number numericValue(String original)
Convert to number.

Parameters:
original - The text.
Returns:
The corresponding value.


Copyright © 2014. All rights reserved.