use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class CoreConfidenceTests method testThisReferenceMapVirtualObjects1.
// compiled - reflective
public void testThisReferenceMapVirtualObjects1() {
// Create our root Map object
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "bar");
VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
factory.createVariable("this", map);
OptimizerFactory.setDefaultOptimizer("reflective");
// Run test
assertEquals(true, executeExpression(compileExpression("this.foo == 'bar'"), map, factory));
}
use of org.mule.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class NullSafe method getValue.
public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
if (ctx == null)
return null;
if (nextNode == null) {
final Accessor a = OptimizerFactory.getAccessorCompiler(OptimizerFactory.SAFE_REFLECTIVE).optimizeAccessor(pCtx, expr, start, offset, ctx, elCtx, variableFactory, true, ctx.getClass());
nextNode = new AccessorNode() {
public AccessorNode getNextNode() {
return null;
}
public AccessorNode setNextNode(AccessorNode accessorNode) {
return null;
}
public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
return a.getValue(ctx, elCtx, variableFactory);
}
public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) {
return a.setValue(ctx, elCtx, variableFactory, value);
}
public Class getKnownEgressType() {
return a.getKnownEgressType();
}
};
}
// else {
return nextNode.getValue(ctx, elCtx, variableFactory);
// }
}
use of org.mule.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.mule.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.mule.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);
}
Aggregations