Search in sources :

Example 16 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

the class DebugTools method getAllVariableResolvers.

public static Map<String, VariableResolver> getAllVariableResolvers(VariableResolverFactory rootFactory) {
    Map<String, VariableResolver> allVariableResolvers = new HashMap<String, VariableResolver>();
    VariableResolverFactory vrf = rootFactory;
    do {
        for (String var : vrf.getKnownVariables()) {
            allVariableResolvers.put(var, vrf.getVariableResolver(var));
        }
    } while ((vrf = vrf.getNextFactory()) != null);
    return allVariableResolvers;
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) HashMap(java.util.HashMap) VariableResolver(org.mvel2.integration.VariableResolver)

Example 17 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

the class BaseVariableResolverFactory method appendFactory.

public void appendFactory(VariableResolverFactory resolverFactory) {
    if (nextFactory == null) {
        nextFactory = resolverFactory;
    } else {
        VariableResolverFactory vrf = nextFactory;
        while (vrf.getNextFactory() != null) {
            vrf = vrf.getNextFactory();
        }
        vrf.setNextFactory(nextFactory);
    }
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory)

Example 18 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

the class CoreConfidenceTests method testMVEL190.

public void testMVEL190() {
    ParserContext context = new ParserContext();
    context.addImport(Ship.class);
    context.addImport(MapObject.class);
    context.addInput("obj", MapObject.class);
    Object compiled = MVEL.compileExpression("((Ship) obj).getName()", context);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("obj", new Ship());
    VariableResolverFactory varsResolver = new MapVariableResolverFactory(vars);
    System.out.println(executeExpression(compiled, varsResolver));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) IndexedVariableResolverFactory(org.mvel2.integration.impl.IndexedVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapObject(org.mvel2.tests.core.res.MapObject) Ship(org.mvel2.tests.core.res.Ship) ParserContext(org.mvel2.ParserContext)

Example 19 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

the class CoreConfidenceTests method testThisReferenceMapVirtualObjects2.

// compiled - asm
public void testThisReferenceMapVirtualObjects2() {
    // 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);
    if (!Boolean.getBoolean("mvel2.disable.jit"))
        OptimizerFactory.setDefaultOptimizer("ASM");
    // Run test
    assertEquals(true, executeExpression(compileExpression("this.foo == 'bar'"), map, factory));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) IndexedVariableResolverFactory(org.mvel2.integration.impl.IndexedVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapObject(org.mvel2.tests.core.res.MapObject)

Example 20 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mvel.

the class CoreConfidenceTests method testInterceptors.

public void testInterceptors() {
    Interceptor testInterceptor = new Interceptor() {

        public int doBefore(ASTNode node, VariableResolverFactory factory) {
            System.out.println("BEFORE Node: " + node.getName());
            return 0;
        }

        public int doAfter(Object val, ASTNode node, VariableResolverFactory factory) {
            System.out.println("AFTER Node: " + node.getName());
            return 0;
        }
    };
    Map<String, Interceptor> interceptors = new HashMap<String, Interceptor>();
    interceptors.put("test", testInterceptor);
    executeExpression(compileExpression("@test System.out.println('MIDDLE');", null, interceptors));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) IndexedVariableResolverFactory(org.mvel2.integration.impl.IndexedVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ASTNode(org.mvel2.ast.ASTNode) MapObject(org.mvel2.tests.core.res.MapObject) Interceptor(org.mvel2.integration.Interceptor)

Aggregations

VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)54 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)28 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)19 HashMap (java.util.HashMap)18 ParserContext (org.mvel2.ParserContext)10 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)10 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)9 CompiledExpression (org.mvel2.compiler.CompiledExpression)9 ASTNode (org.mvel2.ast.ASTNode)8 Debugger (org.mvel2.debug.Debugger)8 Frame (org.mvel2.debug.Frame)8 Interceptor (org.mvel2.integration.Interceptor)8 LinkedHashMap (java.util.LinkedHashMap)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)7 WithNode (org.mvel2.ast.WithNode)6 IndexedVariableResolverFactory (org.mvel2.integration.impl.IndexedVariableResolverFactory)6 MapObject (org.mvel2.tests.core.res.MapObject)6 Macro (org.mvel2.Macro)4 Foo (org.mvel2.tests.core.res.Foo)4 DroolsVarFactory (org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory)3