Search in sources :

Example 26 with AgendaItem

use of org.drools.core.common.AgendaItem 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 27 with AgendaItem

use of org.drools.core.common.AgendaItem 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)

Aggregations

AgendaItem (org.drools.core.common.AgendaItem)27 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)15 List (java.util.List)14 Iterator (org.drools.core.util.Iterator)13 KieSession (org.kie.api.runtime.KieSession)13 KieHelper (org.kie.internal.utils.KieHelper)13 ActivationIterator (org.drools.core.common.ActivationIterator)12 RuleAgendaItem (org.drools.core.phreak.RuleAgendaItem)6 Declaration (org.drools.core.rule.Declaration)6 InternalFactHandle (org.drools.core.common.InternalFactHandle)5 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)5 HashMap (java.util.HashMap)3 DefaultKnowledgeHelper (org.drools.core.base.DefaultKnowledgeHelper)3 AgendaItemImpl (org.drools.core.common.AgendaItemImpl)3 InternalAgenda (org.drools.core.common.InternalAgenda)3 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)3 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)3 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)3