Search in sources :

Example 1 with WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory 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 WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory 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 WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory 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 WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory 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 WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory 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)14 MethodVisitor (org.mvel2.asm.MethodVisitor)9 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)8 InternalFactHandle (org.drools.core.common.InternalFactHandle)7 WorkingMemory (org.drools.core.WorkingMemory)6 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)6 Tuple (org.drools.core.spi.Tuple)6 LeftTuple (org.drools.core.reteoo.LeftTuple)5 Declaration (org.drools.core.rule.Declaration)5 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)4 ClassGenerator (org.drools.core.rule.builder.dialect.asm.ClassGenerator)4 DeclarationMatcher (org.drools.core.rule.builder.dialect.asm.GeneratorHelper.DeclarationMatcher)4 GeneratorHelper.createInvokerClassGenerator (org.drools.core.rule.builder.dialect.asm.GeneratorHelper.createInvokerClassGenerator)4 GeneratorHelper.matchDeclarationsToTuple (org.drools.core.rule.builder.dialect.asm.GeneratorHelper.matchDeclarationsToTuple)4 Label (org.mvel2.asm.Label)4 DroolsVarFactory (org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory)3 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)3 CompiledInvoker (org.drools.core.spi.CompiledInvoker)3 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)3 HashMap (java.util.HashMap)2