use of java.io.Serializable 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 java.io.Serializable 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));
}
use of java.io.Serializable in project mvel by mikebrock.
the class TypesAndInferenceTests method testMVEL235.
public void testMVEL235() {
StringBuffer buffer = new StringBuffer();
buffer.append("if(var1.equals(var2)) {");
buffer.append("return true;");
buffer.append("}");
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("var1", MyInterface2.class);
ctx.addInput("var2", MyInterface2.class);
try {
Serializable compiled = (Serializable) MVEL.compileExpression(buffer.toString(), ctx);
System.out.println(compiled);
} catch (Exception e) {
fail(e.getMessage());
}
}
use of java.io.Serializable in project mvel by mikebrock.
the class TypesAndInferenceTests method testMultiTypeVarDeclr3.
public void testMultiTypeVarDeclr3() {
String ex = "int a = 52 * 3, b = 8, c = 16;";
ParserContext ctx = new ParserContext();
ExpressionCompiler compiler = new ExpressionCompiler(ex);
Serializable s = compiler.compile(ctx);
assertNotNull(ctx.getVariables());
assertEquals(3, ctx.getVariables().entrySet().size());
for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) {
assertEquals(Integer.class, entry.getValue());
}
Map vars = new HashMap();
executeExpression(s, vars);
assertEquals(52 * 3, vars.get("a"));
assertEquals(8, vars.get("b"));
assertEquals(16, vars.get("c"));
}
use of java.io.Serializable in project mvel by mikebrock.
the class TypesAndInferenceTests method testListCoercion.
public void testListCoercion() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("bar", Bar.class);
Serializable s = compileSetExpression("bar.testList[0]", ctx);
Foo foo = new Foo();
foo.getBar().getTestList().add(new Integer(-1));
executeSetExpression(s, foo, "12");
assertEquals(12, foo.getBar().getTestList().get(0).intValue());
foo = new Foo();
foo.getBar().getTestList().add(new Integer(-1));
executeSetExpression(s, foo, "13");
assertEquals(13, foo.getBar().getTestList().get(0).intValue());
OptimizerFactory.setDefaultOptimizer("ASM");
ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("bar", Bar.class);
s = compileSetExpression("bar.testList[0]", ctx);
foo = new Foo();
foo.getBar().getTestList().add(new Integer(-1));
executeSetExpression(s, foo, "12");
assertEquals(12, foo.getBar().getTestList().get(0).intValue());
executeSetExpression(s, foo, "13");
assertEquals(13, foo.getBar().getTestList().get(0).intValue());
}
Aggregations