Search in sources :

Example 1 with StatelessKnowledgeSession

use of org.kie.internal.runtime.StatelessKnowledgeSession in project jbpm by kiegroup.

the class MVELReturnValueEvaluator method evaluate.

public Object evaluate(ProcessContext context) throws Exception {
    int length = unit.getOtherIdentifiers().length;
    Object[] vars = new Object[length];
    if (unit.getOtherIdentifiers() != null) {
        for (int i = 0; i < length; i++) {
            vars[i] = context.getVariable(unit.getOtherIdentifiers()[i]);
        }
    }
    InternalWorkingMemory internalWorkingMemory = null;
    if (context.getKieRuntime() instanceof StatefulKnowledgeSessionImpl) {
        internalWorkingMemory = ((StatefulKnowledgeSessionImpl) context.getKieRuntime()).getInternalWorkingMemory();
    } else if (context.getKieRuntime() instanceof StatelessKnowledgeSession) {
        StatefulKnowledgeSession statefulKnowledgeSession = ((StatelessKnowledgeSessionImpl) context.getKieRuntime()).newWorkingMemory();
        internalWorkingMemory = ((StatefulKnowledgeSessionImpl) statefulKnowledgeSession).getInternalWorkingMemory();
    }
    VariableResolverFactory factory = unit.getFactory(context, // No previous declarations
    null, // No rule
    null, // No "right object"
    null, // No (left) tuples
    null, vars, internalWorkingMemory, (GlobalResolver) context.getKieRuntime().getGlobals());
    // do we have any functions for this namespace?
    KiePackage pkg = context.getKieRuntime().getKieBase().getKiePackage("MAIN");
    if (pkg instanceof KnowledgePackageImpl) {
        MVELDialectRuntimeData data = (MVELDialectRuntimeData) ((KnowledgePackageImpl) pkg).getDialectRuntimeRegistry().getDialectData(id);
        factory.setNextFactory(data.getFunctionFactory());
    }
    Object value = MVELSafeHelper.getEvaluator().executeExpression(this.expr, null, factory);
    if (!(value instanceof Boolean)) {
        throw new RuntimeException("Constraints must return boolean values: " + unit.getExpression() + " returns " + value + (value == null ? "" : " (type=" + value.getClass()));
    }
    return ((Boolean) value).booleanValue();
}
Also used : StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) StatelessKnowledgeSession(org.kie.internal.runtime.StatelessKnowledgeSession) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) KiePackage(org.kie.api.definition.KiePackage) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl)

Aggregations

InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)1 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)1 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)1 KiePackage (org.kie.api.definition.KiePackage)1 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)1 StatelessKnowledgeSession (org.kie.internal.runtime.StatelessKnowledgeSession)1 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)1