Search in sources :

Example 51 with VariableResolverFactory

use of org.mule.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 52 with VariableResolverFactory

use of org.mule.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 53 with VariableResolverFactory

use of org.mule.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)

Example 54 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory in project mule by mulesoft.

the class MVELExpressionLanguage method evaluateInternal.

@SuppressWarnings("unchecked")
protected <T> T evaluateInternal(String expression, MVELExpressionLanguageContext variableResolverFactory) {
    validate(expression);
    expression = removeExpressionMarker(expression);
    try {
        return (T) expressionExecutor.execute(expression, variableResolverFactory);
    } catch (Exception e) {
        throw new ExpressionRuntimeException(CoreMessages.expressionEvaluationFailed(e.getMessage(), expression), e);
    }
}
Also used : ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) OBJECT(org.mule.runtime.api.metadata.DataType.OBJECT) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) IOException(java.io.IOException) CompileException(org.mule.mvel2.CompileException)

Example 55 with VariableResolverFactory

use of org.mule.mvel2.integration.VariableResolverFactory 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

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