data.expressionEvaluator = new ExpressionEvaluator(); data.expressionEvaluator.setParameters( parameterNames.toArray( new String[parameterNames.size()] ), parameterTypes .toArray( new Class<?>[parameterTypes.size()] ) ); data.expressionEvaluator.setReturnType( Object.class ); data.expressionEvaluator.setThrownExceptions( new Class<?>[] { Exception.class } ); data.expressionEvaluator.cook( realCondition ); Object formulaResult = data.expressionEvaluator.evaluate( data.argumentData );
@SuppressWarnings("unchecked") protected Collection<String> getMappings(ServletConfig config) throws CompileException, InvocationTargetException { ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator( "config.getServletContext().getServletRegistration(config.getServletName()).getMappings()", Collection.class, new String[]{"config"}, new Class[]{ServletConfig.class}); return (Collection<String>) expressionEvaluator.evaluate(new Object[]{config}); }
@Override protected ScriptEvaluator getEvaluator( Class returnType, String[] parameterNames, Class[] parameterTypes ) { try { return new ExpressionEvaluator( block, getReturnType(), parameterNames, parameterTypes ); } catch( CompileException exception ) { throw new OperationException( "could not compile expression: " + block, exception ); } } }
private ExpressionEvaluator cookBooleanExpression(String expression) throws CompileException { ExpressionEvaluator ee = new ExpressionEvaluator(); ee.setParameters(new String[] { "ride", "watermark" }, new Class[] { TaxiRide.class, long.class }); ee.setExpressionType(boolean.class); ee.cook(expression); return ee; }
private boolean evaluateBooleanExpression(ExpressionEvaluator ee, TaxiRide ride, long watermark) throws InvocationTargetException { boolean result= false; if (ee != null) { result = (boolean) ee.evaluate(new Object[] { ride, watermark }); } return result; } }
protected String[] guessParameterNames() throws CompileException, IOException { return ExpressionEvaluator.guessParameterNames( new Scanner( "expressionEval", new StringReader( block ) ) ); }
private int jdk() throws Exception{ // Compile the expression once; relatively slow. ExpressionEvaluator ee = new ExpressionEvaluator("c > d ? c : d", // expression int.class, // expressionType new String[] { "c", "d" }, // parameterNames new Class[] { int.class, int.class } // parameterTypes ); // Evaluate it with varying parameter values; very fast. return (Integer) ee.evaluate(new Object[] { // parameterValues new Integer(10), new Integer(11), }); } }
@Override protected ScriptEvaluator getEvaluator( Class returnType, String[] parameterNames, Class[] parameterTypes ) { try { return new ExpressionEvaluator( block, getReturnType(), parameterNames, parameterTypes ); } catch( CompileException exception ) { throw new OperationException( "could not compile expression: " + block, exception ); } } }
private ExpressionEvaluator cookBooleanExpression(String expression) throws CompileException { ExpressionEvaluator ee = new ExpressionEvaluator(); ee.setParameters(new String[] { "ride", "watermark" }, new Class[] { TaxiRide.class, long.class }); ee.setExpressionType(boolean.class); ee.cook(expression); return ee; }
private boolean evaluateBooleanExpression(ExpressionEvaluator ee, TaxiRide ride, long watermark) throws InvocationTargetException { boolean result= false; if (ee != null) { result = (boolean) ee.evaluate(new Object[] { ride, watermark }); } return result; } }
protected String[] guessParameterNames() throws CompileException, IOException { return ExpressionEvaluator.guessParameterNames( new Scanner( "expressionEval", new StringReader( block ) ) ); }
private int janino() throws Exception{ // Compile the expression once; relatively slow. org.codehaus.janino.ExpressionEvaluator ee = new org.codehaus.janino.ExpressionEvaluator("c > d ? c : d", // expression int.class, // expressionType new String[] { "c", "d" }, // parameterNames new Class[] { int.class, int.class } // parameterTypes ); // Evaluate it with varying parameter values; very fast. return (Integer) ee.evaluate(new Object[] { // parameterValues new Integer(10), new Integer(11), }); }
data.expressionEvaluators[m] = new ExpressionEvaluator(); data.expressionEvaluators[m].setParameters( parameterNames.toArray( new String[parameterNames.size()] ), parameterTypes .toArray( new Class<?>[parameterTypes.size()] ) ); data.expressionEvaluators[m].setReturnType( Object.class ); data.expressionEvaluators[m].setThrownExceptions( new Class<?>[] { Exception.class } ); data.expressionEvaluators[m].cook( fn.getFormula() ); } else { throw new KettleException( "Unable to find field name for formula [" Object formulaResult = data.expressionEvaluators[i].evaluate( argumentData );
ee_list[i] = new ExpressionEvaluator(predicates.get(i), boolean.class, pred_param_names, pred_param_types, new Class[0], null);
pred_eval[i] = new Boolean(ee_list[i].evaluate( pred_param_values).toString()); } catch (InvocationTargetException exception) {
ExpressionEvaluator eeTrade = new ExpressionEvaluator( evalTrade = (Boolean) eeTrade.evaluate(
@Override public void start() { try { assert context != null; ClassLoader cl = context.getClass().getClassLoader(); ee = new ExpressionEvaluator(getDecoratedExpression(), EXPRESSION_TYPE, getParameterNames(), getParameterTypes(), THROWN_EXCEPTIONS, cl); super.start(); } catch (Exception e) { addError( "Could not start evaluator with expression [" + expression + "]", e); } }
public boolean evaluate(E event) throws EvaluationException { if (!isStarted()) { throw new IllegalStateException("Evaluator [" + name + "] was called in stopped state"); } try { Boolean result = (Boolean) ee.evaluate(getParameterValues(event)); return result.booleanValue(); } catch (Exception ex) { errorCount++; if (errorCount >= ERROR_THRESHOLD) { stop(); } throw new EvaluationException("Evaluator [" + name + "] caused an exception", ex); } }
expressionEvaluator = new ExpressionEvaluator(expression, expressionType, parameterNames, parameterTypes);
public Object eval(ExpressionContext context) throws ExpressionEvaluationException { try { if (expressionEvaluator == null && isValue == null) compileExpressionEvaluator(context); // don't bother compiling expressions when returning values if (isValue) return context.get(expression); return expressionEvaluator.evaluate(getArguments(context)); } catch (Exception e) { throw new ExpressionEvaluationException(getErrorMsg(), e); } }