Search in sources :

Example 6 with VariableResolverFactory

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));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 7 with VariableResolverFactory

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);
// }
}
Also used : AccessorNode(org.mvel2.compiler.AccessorNode) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) Accessor(org.mvel2.compiler.Accessor)

Example 8 with VariableResolverFactory

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);
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory)

Example 9 with VariableResolverFactory

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);
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory)

Example 10 with VariableResolverFactory

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);
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) DroolsVarFactory(org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory)

Aggregations

VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)54 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)28 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)19 HashMap (java.util.HashMap)18 ParserContext (org.mvel2.ParserContext)10 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)10 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)9 CompiledExpression (org.mvel2.compiler.CompiledExpression)9 ASTNode (org.mvel2.ast.ASTNode)8 Debugger (org.mvel2.debug.Debugger)8 Frame (org.mvel2.debug.Frame)8 Interceptor (org.mvel2.integration.Interceptor)8 LinkedHashMap (java.util.LinkedHashMap)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)7 WithNode (org.mvel2.ast.WithNode)6 IndexedVariableResolverFactory (org.mvel2.integration.impl.IndexedVariableResolverFactory)6 MapObject (org.mvel2.tests.core.res.MapObject)6 Macro (org.mvel2.Macro)4 Foo (org.mvel2.tests.core.res.Foo)4 DroolsVarFactory (org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory)3