Search in sources :

Example 91 with VariableResolverFactory

use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.

the class MvelConditionEvaluator method evaluate.

private boolean evaluate(ExecutableStatement statement, InternalFactHandle handle, InternalWorkingMemory workingMemory, Tuple tuple) {
    if (compilationUnit == null) {
        Map<String, Object> vars = valuesAsMap(handle.getObject(), workingMemory, tuple, declarations);
        if (operators.length > 0) {
            if (vars == null) {
                vars = new HashMap<String, Object>();
            }
            InternalFactHandle[] handles = tuple != null ? tuple.toFactHandles() : new InternalFactHandle[0];
            for (EvaluatorWrapper operator : operators) {
                vars.put(operator.getBindingName(), operator);
                operator.loadHandles(workingMemory, handles, handle);
            }
        }
        return evaluate(statement, handle.getObject(), vars);
    }
    VariableResolverFactory factory = compilationUnit.createFactory();
    compilationUnit.updateFactory(handle, tuple, null, workingMemory, workingMemory.getGlobalResolver(), factory);
    return (Boolean) MVELSafeHelper.getEvaluator().executeExpression(statement, handle.getObject(), factory);
}
Also used : EvaluatorWrapper(org.drools.core.base.EvaluatorWrapper) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 92 with VariableResolverFactory

use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.

the class MVELAccumulator method init.

/* (non-Javadoc)
     * @see org.kie.spi.Accumulator#init(java.lang.Object, org.kie.spi.Tuple, org.kie.rule.Declaration[], org.kie.WorkingMemory)
     */
public void init(Object workingMemoryContext, Object context, Tuple tuple, Declaration[] declarations, WorkingMemory workingMemory) throws Exception {
    Object[] localVars = new Object[initUnit.getOtherIdentifiers().length];
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext) workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getInitFactory();
    initUnit.updateFactory(null, tuple, localVars, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory);
    InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage("MAIN");
    if (pkg != null) {
        MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData("mvel");
        factory.setNextFactory(data.getFunctionFactory());
    }
    MVELSafeHelper.getEvaluator().executeExpression(this.init, null, factory);
    DroolsVarFactory df = (DroolsVarFactory) factory.getNextFactory();
    if (localVars.length > 0) {
        for (int i = 0; i < df.getOtherVarsLength(); i++) {
            localVars[i] = factory.getIndexedVariableResolver(df.getOtherVarsPos() + i).getValue();
        }
    }
    ((MVELAccumulatorContext) context).setVariables(localVars);
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) DroolsVarFactory(org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 93 with VariableResolverFactory

use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.

the class MVELAccumulator method reverse.

public void reverse(Object workingMemoryContext, Object context, Tuple leftTuple, InternalFactHandle handle, Declaration[] declarations, Declaration[] innerDeclarations, WorkingMemory workingMemory) throws Exception {
    Object[] localVars = ((MVELAccumulatorContext) context).getVariables();
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext) workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getActionFactory();
    DroolsVarFactory df = (DroolsVarFactory) factory.getNextFactory();
    Object[] vars = ((MVELAccumulatorContext) context).getShadow().remove(handle.getId());
    for (int i = 0; i < df.getOtherVarsPos(); i++) {
        factory.getIndexedVariableResolver(i).setValue(vars[i]);
    }
    if (localVars.length > 0) {
        for (int i = 0; i < df.getOtherVarsLength(); i++) {
            factory.getIndexedVariableResolver(df.getOtherVarsPos() + i).setValue(localVars[i]);
        }
    }
    // reverseUnit.updateFactory( null, null, handle.getObject(), (LeftTuple) leftTuple, localVars, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory  );
    MVELSafeHelper.getEvaluator().executeExpression(this.reverse, null, factory);
    if (localVars.length > 0) {
        for (int i = 0; i < df.getOtherVarsLength(); i++) {
            localVars[i] = factory.getIndexedVariableResolver(df.getOtherVarsPos() + i).getValue();
        }
    }
    ((MVELAccumulatorContext) context).setVariables(localVars);
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) DroolsVarFactory(org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory)

Example 94 with VariableResolverFactory

use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.

the class MVELCompilationUnit method getFactory.

public VariableResolverFactory getFactory(final Object knowledgeHelper, final Declaration[] prevDecl, final Rule rule, final InternalFactHandle rightHandle, final Tuple tuple, final Object[] otherVars, final InternalWorkingMemory workingMemory, final GlobalResolver globals) {
    VariableResolverFactory factory = createFactory();
    updateFactory(knowledgeHelper, prevDecl, rule, rightHandle, rightHandle != null ? rightHandle.getObject() : null, tuple, otherVars, workingMemory, globals, factory);
    return factory;
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory)

Example 95 with VariableResolverFactory

use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.

the class MVELCompilationUnit method createFactory.

public VariableResolverFactory createFactory() {
    Object[] vals = new Object[inputIdentifiers.length];
    VariableResolverFactory factory = varModel.createFactory(vals);
    factory.setNextFactory(new DroolsVarFactory());
    return factory;
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory)

Aggregations

VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)79 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)41 HashMap (java.util.HashMap)33 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)33 VariableResolver (org.mvel2.integration.VariableResolver)32 ParserContext (org.mvel2.ParserContext)24 Serializable (java.io.Serializable)23 CompileException (org.mvel2.CompileException)23 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)14 AccessorOptimizer (org.mvel2.optimizers.AccessorOptimizer)14 Map (java.util.Map)13 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)12 IndexedVariableResolverFactory (org.mvel2.integration.impl.IndexedVariableResolverFactory)12 List (java.util.List)11 CompiledExpression (org.mvel2.compiler.CompiledExpression)11 ASTNode (org.mvel2.ast.ASTNode)10 Foo (org.mvel2.tests.core.res.Foo)10 MapObject (org.mvel2.tests.core.res.MapObject)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9