public void testMyInterceptors() {
// Avoid MVEL OOM issue:
http://jira.codehaus.org/browse/MVEL-252
// This also disables JIT compilre
// At this time, MVEL does not support per instance configuration of the
JIT due to performance constraints.
OptimizerFactory.setDefaultOptimizer(OptimizerFactory.SAFE_REFLECTIVE);
Interceptor testLeftInterceptor = new Interceptor() {
public int doBefore(ASTNode node,
VariableResolverFactory factory) {
System.out.println("BEFORE left Node: " + node.getName());
System.out.println("BEFORE left Node: node.getClass(): " +
node.getClass());
//node.setAsLiteral();
//node.setLiteralValue("Ivan");
System.out.println("BEFORE left Node: " + node.getLiteralValue());
node.setAccessor(new MetaDataAccessor());
return 0;
}
public int doAfter(Object val,
ASTNode node,
VariableResolverFactory factory) {
System.out.println("AFTER left Node: " + node.getName());
System.out.println("AFTER left Node: node.getLiteralValue(): " +
node.getLiteralValue());
return 0;
}
};
Interceptor testRightInterceptor = new Interceptor() {
public int doBefore(ASTNode node,
VariableResolverFactory factory) {
System.out.println("BEFORE right Node: " + node.getName());
System.out.println("BEFORE right Node: node.getClass(): " +
node.getClass());
return 0;
}
public int doAfter(Object val,
ASTNode node,
VariableResolverFactory factory) {
System.out.println("AFTER right Node: " + node.getName());
return 0;
}
};
Map<String, Interceptor> interceptors = new HashMap<String,
Interceptor>();
interceptors.put("testLeft", testLeftInterceptor);
interceptors.put("testRight", testRightInterceptor);
String expression = "(@testLeft emailMessage.from == @testRight 'Mark'
|| @testLeft myBean.var == 1)";
//compileExpression(expression, null, interceptors);
Map<String, Object> contextObjects = new HashMap<String, Object>();
EmailMessage emailMessage = new EmailMessage();
emailMessage.setFrom("Mark");
contextObjects.put("emailMessage", emailMessage);
MyBean myBean = new MyBean();
myBean.setVar(1);
contextObjects.put("myBean", myBean);
boolean evaluationResult =
executeExpression(compileExpression(expression, null, interceptors),
contextObjects, Boolean.class);
System.out.println(evaluationResult);
}
public class MetaDataAccessor implements Accessor{
public Object getValue(Object ctx, Object elCtx, VariableResolverFactory
variableFactory) {
return null; //To change body of implemented methods use File |
Settings | File Templates.
}
public Object setValue(Object ctx, Object elCtx, VariableResolverFactory
variableFactory, Object value) {
return null; //To change body of implemented methods use File |
Settings | File Templates.
}
public Class getKnownEgressType() {
return null; //To change body of implemented methods use File |
Settings | File Templates.
}
}
When the MetaDataAccessor's geValue was invoked, the ctx and elCtx were
Null, however I am expecting the correct expression and context object
presents?
What is wrong with my codes?
I would expect the value reduce process can be done by my accessor in some
cases but apparently it is not.
-----
Ivan, your Panda, forever
--
View this message in context:
http://drools.46999.n3.nabble.com/MVEL-Getting-Null-Context-Object-with-M...
Sent from the Drools: User forum mailing list archive at
Nabble.com.