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);
}
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);
}
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);
}
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;
}
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();
}
Aggregations