use of org.mule.mvel2.integration.VariableResolverFactory 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);
}
use of org.mule.mvel2.integration.VariableResolverFactory 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);
}
use of org.mule.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 InternalFactHandle rightHandle, final Tuple tuple, final Object[] otherVars, final InternalWorkingMemory workingMemory, final GlobalResolver globals) {
VariableResolverFactory factory = createFactory();
updateFactory(knowledgeHelper, prevDecl, rule, rightHandle, rightHandle != null ? rightHandle.getObject() : null, tuple, otherVars, workingMemory, globals, factory);
return factory;
}
use of org.mule.mvel2.integration.VariableResolverFactory in project drools by kiegroup.
the class MVELCompilationUnit method createFactory.
public VariableResolverFactory createFactory() {
Object[] vals = new Object[inputIdentifiers.length];
VariableResolverFactory factory = varModel.createFactory(vals);
factory.setNextFactory(new DroolsVarFactory());
return factory;
}
use of org.mule.mvel2.integration.VariableResolverFactory in project drools by kiegroup.
the class MVELConsequence method evaluate.
public void evaluate(final KnowledgeHelper knowledgeHelper, final WorkingMemory workingMemory) throws Exception {
VariableResolverFactory factory = unit.getFactory(knowledgeHelper, ((AgendaItem) knowledgeHelper.getMatch()).getTerminalNode().getRequiredDeclarations(), knowledgeHelper.getRule(), knowledgeHelper.getTuple(), 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());
}
CompiledExpression compexpr = (CompiledExpression) this.expr;
if (MVELDebugHandler.isDebugMode()) {
if (MVELDebugHandler.verbose) {
logger.info(DebugTools.decompile(compexpr));
}
MVEL.executeDebugger(compexpr, knowledgeHelper, factory);
} else {
MVEL.executeExpression(compexpr, knowledgeHelper, factory);
}
}
Aggregations