Search in sources :

Example 1 with VariableResolverFactory

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

the class MVELAccumulatorFunctionExecutor method accumulate.

/* (non-Javadoc)
     * @see org.kie.spi.Accumulator#accumulate(java.lang.Object, org.kie.spi.Tuple, org.kie.common.InternalFactHandle, org.kie.rule.Declaration[], org.kie.rule.Declaration[], org.kie.WorkingMemory)
     */
public void accumulate(Object workingMemoryContext, Object context, Tuple tuple, InternalFactHandle handle, Declaration[] declarations, Declaration[] innerDeclarations, WorkingMemory workingMemory) throws Exception {
    VariableResolverFactory factory = unit.getFactory(null, null, null, handle, tuple, null, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver());
    final Object value = MVEL.executeExpression(this.expression, handle.getObject(), factory);
    if (this.function.supportsReverse()) {
        ((MVELAccumulatorFunctionContext) context).reverseSupport.put(handle.getId(), value);
    }
    this.function.accumulate(((MVELAccumulatorFunctionContext) context).context, value);
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory)

Example 2 with VariableResolverFactory

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

the class MVELAccumulator method getResult.

/* (non-Javadoc)
     * @see org.kie.spi.Accumulator#getResult(java.lang.Object, org.kie.spi.Tuple, org.kie.rule.Declaration[], org.kie.WorkingMemory)
     */
public Object getResult(Object workingMemoryContext, Object context, Tuple tuple, Declaration[] declarations, WorkingMemory workingMemory) throws Exception {
    Object[] localVars = ((MVELAccumulatorContext) context).getVariables();
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext) workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getResultFactory();
    resultUnit.updateFactory(null, tuple, localVars, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory);
    return MVELSafeHelper.getEvaluator().executeExpression(this.result, null, factory);
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory)

Example 3 with VariableResolverFactory

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

the class MVELAccumulator method accumulate.

/* (non-Javadoc)
     * @see org.kie.spi.Accumulator#accumulate(java.lang.Object, org.kie.spi.Tuple, org.kie.common.InternalFactHandle, org.kie.rule.Declaration[], org.kie.rule.Declaration[], org.kie.WorkingMemory)
     */
public void accumulate(Object workingMemoryContext, Object context, Tuple tuple, InternalFactHandle handle, Declaration[] declarations, Declaration[] innerDeclarations, WorkingMemory workingMemory) throws Exception {
    Object[] localVars = ((MVELAccumulatorContext) context).getVariables();
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext) workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getActionFactory();
    actionUnit.updateFactory(handle, tuple, localVars, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory);
    DroolsVarFactory df = (DroolsVarFactory) factory.getNextFactory();
    if (reverse != null) {
        Object[] shadow = new Object[df.getOtherVarsPos()];
        for (int i = 0; i < df.getOtherVarsPos(); i++) {
            shadow[i] = factory.getIndexedVariableResolver(i).getValue();
        }
        // SNAPSHOT variable values
        ((MVELAccumulatorContext) context).getShadow().put(handle.getId(), shadow);
    }
    MVELSafeHelper.getEvaluator().executeExpression(this.action, 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 4 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 Tuple tuples, final Object[] otherVars, final InternalWorkingMemory workingMemory, final GlobalResolver globals) {
    VariableResolverFactory factory = createFactory();
    updateFactory(knowledgeHelper, prevDecl, rule, null, knowledgeHelper, tuples, otherVars, workingMemory, globals, factory);
    return factory;
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory)

Example 5 with VariableResolverFactory

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

the class MVELEnabledExpression method getValue.

public boolean getValue(final Tuple tuple, final Declaration[] declrs, final RuleImpl rule, final WorkingMemory workingMemory) {
    VariableResolverFactory factory = unit.getFactory(null, declrs, rule, null, (LeftTuple) tuple, null, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver());
    // do we have any functions for this namespace?
    InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage("MAIN");
    if (pkg != null) {
        MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData(this.id);
        factory.setNextFactory(data.getFunctionFactory());
    }
    return ((Boolean) MVEL.executeExpression(this.expr, null, factory)).booleanValue();
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

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