Search in sources :

Example 6 with MapVariableResolverFactory

use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mikebrock.

the class CoreConfidenceTests method testSysoutNullVariable.

public void testSysoutNullVariable() {
    // Create our root Map object
    Map<String, String> map = new HashMap<String, String>();
    map.put("foo", null);
    VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
    factory.createVariable("this", map);
    org.mvel2.MVEL.executeExpression(org.mvel2.MVEL.compileExpression("System.out.println(foo);"), map, factory);
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 7 with MapVariableResolverFactory

use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mikebrock.

the class CoreConfidenceTests method testMVEL187.

public void testMVEL187() {
    ParserContext context = new ParserContext();
    context.addPackageImport("test");
    context.addInput("outer", Outer.class);
    Object compiled = MVEL.compileExpression("outer.getInner().getValue()", context);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("outer", new Outer());
    VariableResolverFactory varsResolver = new MapVariableResolverFactory(vars);
    assertEquals(2, executeExpression(compiled, varsResolver));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) Outer(org.mvel2.tests.core.res.res2.Outer)

Example 8 with MapVariableResolverFactory

use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mikebrock.

the class CoreConfidenceTests method testThisReferenceMapVirtualObjects1.

// compiled - reflective
public void testThisReferenceMapVirtualObjects1() {
    // Create our root Map object
    Map<String, String> map = new HashMap<String, String>();
    map.put("foo", "bar");
    VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
    factory.createVariable("this", map);
    OptimizerFactory.setDefaultOptimizer("reflective");
    // Run test
    assertEquals(true, executeExpression(compileExpression("this.foo == 'bar'"), map, factory));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 9 with MapVariableResolverFactory

use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mikebrock.

the class CoreConfidenceTests method testTestIntToLong.

public void testTestIntToLong() {
    String s = "1+(long)a";
    ParserContext pc = new ParserContext();
    pc.addInput("a", Integer.class);
    ExpressionCompiler compiler = new ExpressionCompiler(s, pc);
    CompiledExpression expr = compiler.compile();
    Map vars = new HashMap();
    vars.put("a", 1);
    Object r = ((ExecutableStatement) expr).getValue(null, new MapVariableResolverFactory(vars));
    assertEquals(new Long(2), r);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 10 with MapVariableResolverFactory

use of org.mule.mvel2.integration.impl.MapVariableResolverFactory in project mvel by mikebrock.

the class CompiledPerformanceTests method testQuickSort.

public void testQuickSort() throws IOException {
    Serializable s = MVEL.compileExpression(new String(ParseTools.loadFromFile(new File("samples/scripts/fquicksort.mvel"))));
    HashMap map = new HashMap();
    MapVariableResolverFactory mvrf = new MapVariableResolverFactory(map);
    for (int i = 0; i < 1000000; i++) {
        MVEL.executeExpression(s, mvrf);
        mvrf.clear();
    }
// for (int x = 0; x < 4; x++) {
// Serializable s = MVEL.compileSetExpression("tak.bar.name");
// long time = System.currentTimeMillis();
// 
// for (int i = 0; i < ITERATIONS; i++) {
// MVEL.executeSetExpression(s, map, "foobie");
// }
// 
// System.out.println("SET PERFORMANCE: " + (System.currentTimeMillis() - time));
// 
// time = System.currentTimeMillis();
// 
// s = MVEL.compileExpression("tak.bar.name");
// 
// for (int i = 0; i < ITERATIONS; i++) {
// MVEL.executeExpression(s, map);
// }
// 
// System.out.println("GET PERFORMANCE: " + (System.currentTimeMillis() - time));
// 
// }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) File(java.io.File)

Aggregations

MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)62 HashMap (java.util.HashMap)31 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)20 ParserContext (org.mvel2.ParserContext)18 CompiledExpression (org.mvel2.compiler.CompiledExpression)16 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)16 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)13 Debugger (org.mvel2.debug.Debugger)12 Frame (org.mvel2.debug.Frame)12 HashSet (java.util.HashSet)10 SimpleTemplateRegistry (org.mvel2.templates.SimpleTemplateRegistry)7 TemplateRegistry (org.mvel2.templates.TemplateRegistry)7 TemplateRuntimeError (org.mvel2.templates.TemplateRuntimeError)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Serializable (java.io.Serializable)6 LinkedHashMap (java.util.LinkedHashMap)6 CompiledTemplate (org.mvel2.templates.CompiledTemplate)6 MapObject (org.mvel2.tests.core.res.MapObject)6 Interceptor (org.mvel2.integration.Interceptor)5 IndexedVariableResolverFactory (org.mvel2.integration.impl.IndexedVariableResolverFactory)5