Search in sources :

Example 11 with KnowledgeHelper

use of org.mvel2.tests.core.res.KnowledgeHelper 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)

Aggregations

VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)5 WorkingMemory (org.drools.core.WorkingMemory)3 InternalFactHandle (org.drools.core.common.InternalFactHandle)3 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)3 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)3 Declaration (org.drools.core.rule.Declaration)3 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)3 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)3 Tuple (org.drools.core.spi.Tuple)3 MethodVisitor (org.mvel2.asm.MethodVisitor)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 AgendaItem (org.drools.core.common.AgendaItem)2 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)2 LeftTuple (org.drools.core.reteoo.LeftTuple)2 Sink (org.drools.core.reteoo.Sink)2 ClassGenerator (org.drools.core.rule.builder.dialect.asm.ClassGenerator)2 Activation (org.drools.core.spi.Activation)2 Consequence (org.drools.core.spi.Consequence)2