use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.
the class MvelConditionEvaluator method evaluate.
private boolean evaluate(ExecutableStatement statement, InternalFactHandle handle, InternalWorkingMemory workingMemory, Tuple tuple) {
if (compilationUnit == null) {
Map<String, Object> vars = valuesAsMap(handle.getObject(), workingMemory, tuple, declarations);
if (operators.length > 0) {
if (vars == null) {
vars = new HashMap<String, Object>();
}
InternalFactHandle[] handles = tuple != null ? tuple.toFactHandles() : new InternalFactHandle[0];
for (EvaluatorWrapper operator : operators) {
vars.put(operator.getBindingName(), operator);
operator.loadHandles(workingMemory, handles, handle);
}
}
return evaluate(statement, handle.getObject(), vars);
}
VariableResolverFactory factory = compilationUnit.createFactory();
compilationUnit.updateFactory(handle, tuple, null, workingMemory, workingMemory.getGlobalResolver(), factory);
return (Boolean) MVELSafeHelper.getEvaluator().executeExpression(statement, handle.getObject(), factory);
}
use of org.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.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.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.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;
}
Aggregations