Search in sources :

Example 21 with WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory in project drools by kiegroup.

the class MvelConditionEvaluator method ensureCompleteEvaluation.

private void ensureCompleteEvaluation(InternalFactHandle handle, InternalWorkingMemory workingMemory, Tuple tuple) {
    if (!evaluated) {
        ASTNode rootNode = getRootNode();
        if (rootNode != null) {
            ensureCompleteEvaluation(rootNode, handle, workingMemory, tuple);
        }
        evaluated = true;
    }
}
Also used : ASTNode(org.mvel2.ast.ASTNode)

Example 22 with WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory in project drools by kiegroup.

the class ClassFieldAccessorFactory method buildGetMethod.

/**
 * Creates the proxy reader method for the given method
 */
protected static void buildGetMethod(final Class<?> originalClass, final String className, final Class<?> superClass, final Method getterMethod, final ClassWriter cw) {
    final Class<?> fieldType = getterMethod.getReturnType();
    Method overridingMethod;
    try {
        overridingMethod = superClass.getMethod(getOverridingGetMethodName(fieldType), InternalWorkingMemory.class, Object.class);
    } catch (final Exception e) {
        throw new RuntimeException("This is a bug. Please report back to JBoss Rules team.", e);
    }
    final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, overridingMethod.getName(), Type.getMethodDescriptor(overridingMethod), null, null);
    mv.visitCode();
    final Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(Opcodes.ALOAD, 2);
    mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(originalClass));
    if (originalClass.isInterface()) {
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(originalClass), getterMethod.getName(), Type.getMethodDescriptor(getterMethod));
    } else {
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(originalClass), getterMethod.getName(), Type.getMethodDescriptor(getterMethod));
    }
    mv.visitInsn(Type.getType(fieldType).getOpcode(Opcodes.IRETURN));
    final Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
    mv.visitLocalVariable("workingMemory", Type.getDescriptor(InternalWorkingMemory.class), null, l0, l1, 1);
    mv.visitLocalVariable("object", Type.getDescriptor(Object.class), null, l0, l1, 2);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) Label(org.mvel2.asm.Label) Method(java.lang.reflect.Method) IOException(java.io.IOException) MethodVisitor(org.mvel2.asm.MethodVisitor)

Example 23 with WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory in project drools by kiegroup.

the class MVELAccumulator method init.

/* (non-Javadoc)
     * @see org.kie.spi.Accumulator#init(java.lang.Object, org.kie.spi.Tuple, org.kie.rule.Declaration[], org.kie.WorkingMemory)
     */
public void init(Object workingMemoryContext, Object context, Tuple tuple, Declaration[] declarations, WorkingMemory workingMemory) throws Exception {
    Object[] localVars = new Object[initUnit.getOtherIdentifiers().length];
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext) workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getInitFactory();
    initUnit.updateFactory(null, tuple, localVars, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory);
    InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage("MAIN");
    if (pkg != null) {
        MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData("mvel");
        factory.setNextFactory(data.getFunctionFactory());
    }
    MVELSafeHelper.getEvaluator().executeExpression(this.init, null, factory);
    DroolsVarFactory df = (DroolsVarFactory) factory.getNextFactory();
    if (localVars.length > 0) {
        for (int i = 0; i < df.getOtherVarsLength(); i++) {
            localVars[i] = factory.getIndexedVariableResolver(df.getOtherVarsPos() + i).getValue();
        }
    }
    ((MVELAccumulatorContext) context).setVariables(localVars);
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) DroolsVarFactory(org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 24 with WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory in project drools by kiegroup.

the class MVELAccumulator method reverse.

public void reverse(Object workingMemoryContext, Object context, Tuple leftTuple, InternalFactHandle handle, Declaration[] declarations, Declaration[] innerDeclarations, WorkingMemory workingMemory) throws Exception {
    Object[] localVars = ((MVELAccumulatorContext) context).getVariables();
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext) workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getActionFactory();
    DroolsVarFactory df = (DroolsVarFactory) factory.getNextFactory();
    Object[] vars = ((MVELAccumulatorContext) context).getShadow().remove(handle.getId());
    for (int i = 0; i < df.getOtherVarsPos(); i++) {
        factory.getIndexedVariableResolver(i).setValue(vars[i]);
    }
    if (localVars.length > 0) {
        for (int i = 0; i < df.getOtherVarsLength(); i++) {
            factory.getIndexedVariableResolver(df.getOtherVarsPos() + i).setValue(localVars[i]);
        }
    }
    // reverseUnit.updateFactory( null, null, handle.getObject(), (LeftTuple) leftTuple, localVars, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory  );
    MVELSafeHelper.getEvaluator().executeExpression(this.reverse, null, factory);
    if (localVars.length > 0) {
        for (int i = 0; i < df.getOtherVarsLength(); i++) {
            localVars[i] = factory.getIndexedVariableResolver(df.getOtherVarsPos() + i).getValue();
        }
    }
    ((MVELAccumulatorContext) context).setVariables(localVars);
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) DroolsVarFactory(org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory)

Example 25 with WorkingMemory

use of org.mvel2.tests.core.res.WorkingMemory in project drools by kiegroup.

the class MVELCompilationUnit method getFactory.

public VariableResolverFactory getFactory(final Object knowledgeHelper, final Declaration[] prevDecl, final Rule rule, final InternalFactHandle rightHandle, final Tuple tuple, final Object[] otherVars, final InternalWorkingMemory workingMemory, final GlobalResolver globals) {
    VariableResolverFactory factory = createFactory();
    updateFactory(knowledgeHelper, prevDecl, rule, rightHandle, rightHandle != null ? rightHandle.getObject() : null, tuple, otherVars, workingMemory, globals, factory);
    return factory;
}
Also used : VariableResolverFactory(org.mvel2.integration.VariableResolverFactory)

Aggregations

VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)14 MethodVisitor (org.mvel2.asm.MethodVisitor)9 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)8 InternalFactHandle (org.drools.core.common.InternalFactHandle)7 WorkingMemory (org.drools.core.WorkingMemory)6 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)6 Tuple (org.drools.core.spi.Tuple)6 LeftTuple (org.drools.core.reteoo.LeftTuple)5 Declaration (org.drools.core.rule.Declaration)5 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)4 ClassGenerator (org.drools.core.rule.builder.dialect.asm.ClassGenerator)4 DeclarationMatcher (org.drools.core.rule.builder.dialect.asm.GeneratorHelper.DeclarationMatcher)4 GeneratorHelper.createInvokerClassGenerator (org.drools.core.rule.builder.dialect.asm.GeneratorHelper.createInvokerClassGenerator)4 GeneratorHelper.matchDeclarationsToTuple (org.drools.core.rule.builder.dialect.asm.GeneratorHelper.matchDeclarationsToTuple)4 Label (org.mvel2.asm.Label)4 DroolsVarFactory (org.drools.core.base.mvel.MVELCompilationUnit.DroolsVarFactory)3 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)3 CompiledInvoker (org.drools.core.spi.CompiledInvoker)3 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)3 HashMap (java.util.HashMap)2