Search in sources :

Example 96 with VariableResolverFactory

use of org.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);
    }
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) AgendaItem(org.drools.core.common.AgendaItem) CompiledExpression(org.mvel2.compiler.CompiledExpression) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 97 with VariableResolverFactory

use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.

the class ActivationPropertyHandler method getProperty.

public Object getProperty(String name, Object obj, VariableResolverFactory variableFactory) {
    AgendaItem item = (AgendaItem) obj;
    if ("rule".equals(name)) {
        return item.getRule();
    } else if ("active".equals(name)) {
        return item.isQueued();
    } else if ("objects".equals(name)) {
        return item.getObjects();
    } else if ("factHandles".equals(name)) {
        return item.getFactHandles();
    } else if ("declarationIds".equals(name)) {
        return item.getDeclarationIds();
    } else if ("this".equals(name)) {
        return item;
    }
    // FIXME hack as MVEL seems to be ignoring indexed variables
    VariableResolver vr = variableFactory.getNextFactory().getVariableResolver(name);
    if (vr != null) {
        return vr.getValue();
    }
    Declaration declr = item.getTerminalNode().getSubRule().getOuterDeclarations().get(name);
    if (declr != null) {
        return declr.getValue(null, item.getTuple().get(declr).getObject());
    } else {
        return item.getRule().getMetaData(name);
    }
}
Also used : Declaration(org.drools.core.rule.Declaration) VariableResolver(org.mvel2.integration.VariableResolver) AgendaItem(org.drools.core.common.AgendaItem)

Example 98 with VariableResolverFactory

use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.

the class MVELObjectExpression method getValue.

public Object getValue(final Tuple leftTuple, final Declaration[] declrs, final Rule rule, final InternalWorkingMemory wm) {
    VariableResolverFactory factory = unit.getFactory(null, declrs, rule, null, leftTuple, null, wm, wm.getGlobalResolver());
    // do we have any functions for this namespace?
    InternalKnowledgePackage pkg = wm.getKnowledgeBase().getPackage("MAIN");
    if (pkg != null) {
        MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData(this.id);
        factory.setNextFactory(data.getFunctionFactory());
    }
    return MVELSafeHelper.getEvaluator().executeExpression(this.expr, factory);
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 99 with VariableResolverFactory

use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.

the class MVELSalienceExpression method getValue.

public int getValue(final KnowledgeHelper khelper, final Rule rule, final WorkingMemory workingMemory) {
    VariableResolverFactory factory = unit.getFactory(khelper, khelper != null ? ((AgendaItem) khelper.getMatch()).getTerminalNode().getSalienceDeclarations() : null, rule, null, khelper != null ? (LeftTuple) khelper.getMatch().getTuple() : null, 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());
    }
    Object value = MVEL.executeExpression(this.expr, factory);
    if (value instanceof String) {
        value = TimeUtils.parseTimeString((String) value);
    }
    return ((Number) value).intValue();
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) LeftTuple(org.drools.core.reteoo.LeftTuple) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 100 with VariableResolverFactory

use of org.mvel2.integration.VariableResolverFactory in project drools by kiegroup.

the class MVELReturnValueExpression method evaluate.

public FieldValue evaluate(final InternalFactHandle handle, final Tuple tuple, final Declaration[] previousDeclarations, final Declaration[] requiredDeclarations, final WorkingMemory workingMemory, final Object ctx) throws Exception {
    VariableResolverFactory factory = (VariableResolverFactory) ctx;
    unit.updateFactory(handle, tuple, null, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory);
    // 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 workingMemory.getKnowledgeBase().getConfiguration().getComponentFactory().getFieldFactory().getFieldValue(MVELSafeHelper.getEvaluator().executeExpression(this.expr, handle, factory));
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)79 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)41 HashMap (java.util.HashMap)33 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)33 VariableResolver (org.mvel2.integration.VariableResolver)32 ParserContext (org.mvel2.ParserContext)24 Serializable (java.io.Serializable)23 CompileException (org.mvel2.CompileException)23 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)14 AccessorOptimizer (org.mvel2.optimizers.AccessorOptimizer)14 Map (java.util.Map)13 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)12 IndexedVariableResolverFactory (org.mvel2.integration.impl.IndexedVariableResolverFactory)12 List (java.util.List)11 CompiledExpression (org.mvel2.compiler.CompiledExpression)11 ASTNode (org.mvel2.ast.ASTNode)10 Foo (org.mvel2.tests.core.res.Foo)10 MapObject (org.mvel2.tests.core.res.MapObject)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9