Package org.apache.el

Examples of org.apache.el.ExpressionFactoryImpl


public class BenchmarkEl {
    public static void main(final String[] args) {
        final FunctionMapper functionMapper = new LibraryFunctionMapperBuilder().add("proctor", ProctorRuleFunctions.class).build();

        final ExpressionFactory expressionFactory = new ExpressionFactoryImpl();

        final CompositeELResolver elResolver = new CompositeELResolver();
        elResolver.add(new ArrayELResolver());
        elResolver.add(new ListELResolver());
        elResolver.add(new BeanELResolver());
        elResolver.add(new MapELResolver());

        final Map<String, Object> values = Maps.newLinkedHashMap();
        values.put("countries", Sets.newHashSet("AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II", "JJ", "KK", "LL", "MM"));
        values.put("AA", "AA");
        values.put("CC", "CC");
        values.put("NN", "NN");
        values.put("ZZ", "ZZ");
        values.put("I1", 239235);
        values.put("I2", 569071142);
        values.put("I3", -189245);
        values.put("D1", 129835.12512);
        values.put("D2", -9582.9385);
        values.put("D3", 98982223.598731412);
        values.put("BT", Boolean.TRUE);
        values.put("BF", Boolean.FALSE);
        values.put("GLOOP", "");

        final String[] expressions = {
                "${proctor:contains(countries, AA) || proctor:contains(countries, CC) || D2 < I3 && BF}",
                "${! proctor:contains(countries, ZZ) && I1 < I2 && empty GLOOP}",
                "${I2 - I3 + D3 - D1}",
                "${NN == '0' && ZZ == 'ZZ'}",
                "${BT != BF}",
        };

        final int iterations = 100*1000;
        long elapsed = -System.currentTimeMillis();
        for (int i = 0; i < iterations; i++) {
            final Map<String, ValueExpression> localContext = ProctorUtils.convertToValueExpressionMap(expressionFactory, values);
            final VariableMapper variableMapper = new MulticontextReadOnlyVariableMapper(localContext);

            final ELContext elContext = new ELContext() {
                @Override
                public ELResolver getELResolver() {
                    return elResolver;
                }

                @Override
                public FunctionMapper getFunctionMapper() {
                    return functionMapper;
                }

                @Override
                public VariableMapper getVariableMapper() {
                    return variableMapper;
                }
            };

            for (int j = 0; j < expressions.length; j++) {
                final ValueExpression ve = expressionFactory.createValueExpression(elContext, expressions[j], Object.class);
                final Object result = ve.getValue(elContext);
                if (i % 10000 == 0) {
                    System.out.println(result);
                }
            }
View Full Code Here


        assertTrue(found[2] > 250);
        assertTrue(found[2] < 400);
    }

    static RandomTestChooser initializeRandomTestChooser(final List<Range> ranges, final List<TestBucket> buckets) {
        final ExpressionFactory expressionFactory = new ExpressionFactoryImpl();

        final FunctionMapper functionMapper = RuleEvaluator.FUNCTION_MAPPER;

        final ConsumableTestDefinition testDefinition = new ConsumableTestDefinition();
        testDefinition.setConstants(Collections.<String, Object>emptyMap());
View Full Code Here

            new Range(1, 1.0)
    );

    @Before
    public void setupMocks() throws Exception {
        expressionFactory = new ExpressionFactoryImpl();
        functionMapper = RuleEvaluator.FUNCTION_MAPPER;
        testName = "testName";
        final List<TestBucket> buckets = ImmutableList.of(
                new TestBucket("inactive", -1, "zoot", null),
                new TestBucket("control", 0, "zoot", null),
View Full Code Here

    private String evalAttr(String expression, char quote) {
       
        ELContextImpl ctx = new ELContextImpl();
        ctx.setFunctionMapper(new FMapper());
        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
        ValueExpression ve = exprFactory.createValueExpression(ctx,
                AttributeParser.getUnquoted(expression, quote, false, false,
                        false),
                String.class);
        return (String) ve.getValue(ctx);
    }
View Full Code Here

        String elResult = null;

        // Don't try and evaluate expressions that depend on variables or functions
        if (expected != null) {
            try {
                ExpressionFactory factory = new ExpressionFactoryImpl();
                ELContext context = new ELContextImpl();
                ValueExpression ve = factory.createValueExpression(context, input, String.class);
                elResult = ve.getValue(context).toString();
                Assert.assertEquals(expected, elResult);
            } catch (ELException ele) {
                elException = ele;
            }
View Full Code Here

    // ************************************************************************

    private String evaluateExpression(String expression) {
        ELContextImpl ctx = new ELContextImpl();
        ctx.setFunctionMapper(new FMapper());
        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
        ValueExpression ve = exprFactory.createValueExpression(ctx, expression,
                String.class);
        return (String) ve.getValue(ctx);
    }
View Full Code Here

*/
public class TomcatExpressionFactoryFactory implements ExpressionFactoryFactory {

    /** {@inheritDoc} */
    public ExpressionFactory getExpressionFactory() {
        return new ExpressionFactoryImpl();
    }
View Full Code Here

    // ************************************************************************

    private String evaluateExpression(String expression) {
        ELContextImpl ctx = new ELContextImpl();
        ctx.setFunctionMapper(new FMapper());
        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
        ValueExpression ve = exprFactory.createValueExpression(ctx, expression,
                String.class);
        return (String) ve.getValue(ctx);
    }
View Full Code Here

    private String evalAttr(String expression, char quote) {
       
        ELContextImpl ctx = new ELContextImpl();
        ctx.setFunctionMapper(new FMapper());
        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
        ValueExpression ve = exprFactory.createValueExpression(ctx,
                AttributeParser.getUnquoted(expression, quote, false, false,
                        false),
                String.class);
        return (String) ve.getValue(ctx);
    }
View Full Code Here

    private String evalAttr(String expression, char quote) {
       
        ELContextImpl ctx = new ELContextImpl();
        ctx.setFunctionMapper(new FMapper());
        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
        ValueExpression ve = exprFactory.createValueExpression(ctx,
                AttributeParser.getUnquoted(expression, quote, false, false,
                        false),
                String.class);
        return (String) ve.getValue(ctx);
    }
View Full Code Here

TOP

Related Classes of org.apache.el.ExpressionFactoryImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.