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;
}
}
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();
}
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);
}
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);
}
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;
}
Aggregations