Search in sources :

Example 26 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project jbpm by kiegroup.

the class MVELAction method execute.

public void execute(ProcessContext context) throws Exception {
    int length = unit.getOtherIdentifiers().length;
    Object[] vars = new Object[length];
    if (unit.getOtherIdentifiers() != null) {
        for (int i = 0; i < length; i++) {
            vars[i] = context.getVariable(unit.getOtherIdentifiers()[i]);
        }
    }
    InternalWorkingMemory internalWorkingMemory = null;
    if (context.getKieRuntime() instanceof StatefulKnowledgeSessionImpl) {
        internalWorkingMemory = ((StatefulKnowledgeSessionImpl) context.getKieRuntime()).getInternalWorkingMemory();
    } else if (context.getKieRuntime() instanceof StatelessKnowledgeSessionImpl) {
        StatefulKnowledgeSession statefulKnowledgeSession = ((StatelessKnowledgeSessionImpl) context.getKieRuntime()).newWorkingMemory();
        internalWorkingMemory = ((StatefulKnowledgeSessionImpl) statefulKnowledgeSession).getInternalWorkingMemory();
    }
    VariableResolverFactory factory = unit.getFactory(context, // No previous declarations
    null, // No rule
    null, // No "right object"
    null, // No (left) tuples
    null, vars, internalWorkingMemory, (GlobalResolver) context.getKieRuntime().getGlobals());
    // KnowledgePackage pkg = context.getKnowledgeRuntime().getKnowledgeBase().getKnowledgePackage( "MAIN" );
    // if ( pkg != null && pkg instanceof KnowledgePackageImp) {
    // MVELDialectRuntimeData data = ( MVELDialectRuntimeData ) ((KnowledgePackageImp) pkg).pkg.getDialectRuntimeRegistry().getDialectData( id );
    // factory.setNextFactory( data.getFunctionFactory() );
    // }
    // 
    MVELSafeHelper.getEvaluator().executeExpression(this.expr, null, factory);
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) StatelessKnowledgeSessionImpl(org.drools.core.impl.StatelessKnowledgeSessionImpl) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession)

Example 27 with VariableResolverFactory

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

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 28 with VariableResolverFactory

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

the class ForNode method getReducedValueAccelerated.

public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
    VariableResolverFactory ctxFactory = indexAlloc ? factory : new MapVariableResolverFactory(new HashMap<String, Object>(1), factory);
    Object v;
    for (initializer.getValue(ctx, thisValue, ctxFactory); (Boolean) condition.getValue(ctx, thisValue, ctxFactory); after.getValue(ctx, thisValue, ctxFactory)) {
        v = compiledBlock.getValue(ctx, thisValue, ctxFactory);
        if (ctxFactory.tiltFlag())
            return v;
    }
    return null;
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) HashMap(java.util.HashMap) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 29 with VariableResolverFactory

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

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) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 30 with VariableResolverFactory

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

the class CoreConfidenceTests method testThisReferenceMapVirtualObjects.

// interpreted
public void testThisReferenceMapVirtualObjects() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("foo", "bar");
    VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
    factory.createVariable("this", map);
    assertEquals(true, eval("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)

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