use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class PreFixIncNode method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
VariableResolver vResolver = factory.getVariableResolver(name);
vResolver.setValue(ctx = MathProcessor.doOperations(vResolver.getValue(), Operator.ADD, DataTypes.INTEGER, 1));
return ctx;
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class PropertyHandlerTests method testNullPropertyHandler2.
public void testNullPropertyHandler2() {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
OptimizerFactory.setDefaultOptimizer("reflective");
PropertyHandlerFactory.setNullPropertyHandler(new PropertyHandler() {
public Object getProperty(String name, Object contextObj, VariableResolverFactory variableFactory) {
return "NULL";
}
public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
return "NULL";
}
});
Foo foo = new Foo();
Bar bar = foo.getBar();
foo.setBar(null);
Map map = new HashMap();
map.put("foo", foo);
Serializable s = MVEL.compileExpression("foo.bar");
assertEquals("NULL", MVEL.executeExpression(s, map));
assertEquals("NULL", MVEL.executeExpression(s, map));
foo.setBar(bar);
assertEquals(bar, MVEL.executeExpression(s, map));
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class PropertyHandlerTests method _testListener.
public void _testListener() {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
class MyListener implements Listener {
public int count;
public void onEvent(Object context, String contextName, VariableResolverFactory variableFactory, Object value) {
count++;
}
}
MyListener listener = new MyListener();
GlobalListenerFactory.registerGetListener(listener);
PropertyHandlerFactory.setNullPropertyHandler(new PropertyHandler() {
public Object getProperty(String name, Object contextObj, VariableResolverFactory variableFactory) {
List someList = new ArrayList();
someList.add(new Foo());
return someList;
}
public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
return null;
}
});
PropertyHandlerFactory.registerPropertyHandler(List.class, new PropertyHandler() {
public Object getProperty(String name, Object contextObj, VariableResolverFactory variableFactory) {
List list = (List) contextObj;
int index = Integer.valueOf(name);
while (index >= list.size()) {
list.add(new Foo());
}
return list.get(index);
}
public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
return null;
}
});
Foo foo = new Foo();
final Serializable fooExpr0 = MVEL.compileSetExpression("collectionTest[0].name");
final Serializable fooExpr1 = MVEL.compileSetExpression("collectionTest[1].name");
MVEL.executeSetExpression(fooExpr0, foo, "John Galt");
MVEL.executeSetExpression(fooExpr1, foo, "The Joker");
assertEquals(2, listener.count);
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = false;
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class PropertyHandlerTests method testListPropertyHandler4.
public void testListPropertyHandler4() {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
OptimizerFactory.setDefaultOptimizer("ASM");
final String[] res = new String[1];
GlobalListenerFactory.registerGetListener(new Listener() {
public void onEvent(Object context, String contextName, VariableResolverFactory variableFactory, Object value) {
System.out.println("Listener Fired:" + contextName);
res[0] = contextName;
}
});
Serializable s = MVEL.compileSetExpression("list[0]");
Base b;
MVEL.executeSetExpression(s, new Base(), "hey you");
res[0] = null;
MVEL.executeSetExpression(s, b = new Base(), "hey you");
assertEquals("set", b.list.get(0));
assertEquals("list", res[0]);
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class PropertyHandlerTests method testNullPropertyHandler.
public void testNullPropertyHandler() {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
OptimizerFactory.setDefaultOptimizer("ASM");
PropertyHandlerFactory.setNullPropertyHandler(new PropertyHandler() {
public Object getProperty(String name, Object contextObj, VariableResolverFactory variableFactory) {
return "NULL";
}
public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
return "NULL";
}
});
Foo foo = new Foo();
Bar bar = foo.getBar();
foo.setBar(null);
Map map = new HashMap();
map.put("foo", foo);
Serializable s = MVEL.compileExpression("foo.bar");
assertEquals("NULL", MVEL.executeExpression(s, map));
assertEquals("NULL", MVEL.executeExpression(s, map));
foo.setBar(bar);
assertEquals(bar, MVEL.executeExpression(s, map));
}
Aggregations