Search in sources :

Example 1 with DroolsVarFactory

use of org.drools.mvel.expr.MVELCompilationUnit.DroolsVarFactory in project drools by kiegroup.

the class MVELAccumulator method tryReverse.

public boolean tryReverse(Object workingMemoryContext, Object context, Tuple leftTuple, InternalFactHandle handle, Object value, Declaration[] declarations, Declaration[] innerDeclarations, ReteEvaluator reteEvaluator) {
    if (!supportsReverse()) {
        return false;
    }
    Object[] localVars = ((MVELAccumulatorContext) context).getVariables();
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext) workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getActionFactory();
    DroolsVarFactory df = (DroolsVarFactory) factory.getNextFactory();
    Object[] vars = (Object[]) value;
    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]);
        }
    }
    this.reverse.evaluate(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);
    return true;
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) DroolsVarFactory(org.drools.mvel.expr.MVELCompilationUnit.DroolsVarFactory)

Example 2 with DroolsVarFactory

use of org.drools.mvel.expr.MVELCompilationUnit.DroolsVarFactory 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 Object init(Object workingMemoryContext, Object context, Tuple tuple, Declaration[] declarations, ReteEvaluator reteEvaluator) {
    Object[] localVars = new Object[initUnit.getOtherIdentifiers().length];
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext) workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getInitFactory();
    initUnit.updateFactory(null, tuple, localVars, reteEvaluator, reteEvaluator.getGlobalResolver(), factory);
    InternalKnowledgePackage pkg = reteEvaluator.getKnowledgeBase().getPackage("MAIN");
    if (pkg != null) {
        MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData("mvel");
        factory.setNextFactory(data.getFunctionFactory());
    }
    this.init.evaluate(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);
    return context;
}
Also used : MVELDialectRuntimeData(org.drools.mvel.MVELDialectRuntimeData) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) DroolsVarFactory(org.drools.mvel.expr.MVELCompilationUnit.DroolsVarFactory) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 3 with DroolsVarFactory

use of org.drools.mvel.expr.MVELCompilationUnit.DroolsVarFactory 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 Object accumulate(Object workingMemoryContext, Object context, Tuple tuple, InternalFactHandle handle, Declaration[] declarations, Declaration[] innerDeclarations, ReteEvaluator reteEvaluator) {
    Object[] localVars = ((MVELAccumulatorContext) context).getVariables();
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext) workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getActionFactory();
    actionUnit.updateFactory(handle, tuple, localVars, reteEvaluator, reteEvaluator.getGlobalResolver(), factory);
    DroolsVarFactory df = (DroolsVarFactory) factory.getNextFactory();
    Object[] shadow = null;
    if (reverse != null) {
        shadow = new Object[df.getOtherVarsPos()];
        for (int i = 0; i < df.getOtherVarsPos(); i++) {
            shadow[i] = factory.getIndexedVariableResolver(i).getValue();
        }
    }
    this.action.evaluate(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);
    return shadow;
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) DroolsVarFactory(org.drools.mvel.expr.MVELCompilationUnit.DroolsVarFactory)

Aggregations

DroolsVarFactory (org.drools.mvel.expr.MVELCompilationUnit.DroolsVarFactory)3 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 MVELDialectRuntimeData (org.drools.mvel.MVELDialectRuntimeData)1