Search in sources :

Example 1 with DroolsVarFactory

use of org.drools.core.base.mvel.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 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 2 with DroolsVarFactory

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

the class ModifyInterceptor method doAfter.

public int doAfter(Object value, ASTNode node, VariableResolverFactory factory) {
    while (factory != null && !(factory instanceof DroolsVarFactory)) {
        factory = factory.getNextFactory();
    }
    if (factory == null) {
        throw new RuntimeException("Unable to find DroolsMVELIndexedFactory");
    }
    KnowledgeHelper knowledgeHelper = ((DroolsVarFactory) factory).getKnowledgeHelper();
    if (modificationMask.isSet(PropertySpecificUtil.TRAITABLE_BIT)) {
        calculateModificationMask(knowledgeHelper, (WithNode) node);
    }
    knowledgeHelper.update(value, modificationMask, value.getClass());
    return 0;
}
Also used : DroolsVarFactory(org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory) KnowledgeHelper(org.drools.core.spi.KnowledgeHelper)

Example 3 with DroolsVarFactory

use of org.drools.core.base.mvel.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 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 4 with DroolsVarFactory

use of org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory 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)

Aggregations

DroolsVarFactory (org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory)4 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)1 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)1