use of org.mule.mvel2.ParserConfiguration in project drools by kiegroup.
the class MVELDialectRuntimeData method getParserConfiguration.
public ParserConfiguration getParserConfiguration() {
if (parserConfiguration == null) {
ClassLoader packageClassLoader = getPackageClassLoader();
String key = null;
Object value = null;
try {
// First replace fields and method tokens with actual instances
for (Entry<String, Object> entry : this.imports.entrySet()) {
key = entry.getKey();
value = entry.getValue();
if (entry.getValue() instanceof String) {
String str = (String) value;
// @TODO MVEL doesn't yet support importing of fields
if (str.startsWith("m:")) {
Class cls = packageClassLoader.loadClass(str.substring(2));
for (Method method : cls.getDeclaredMethods()) {
if (method.getName().equals(key)) {
entry.setValue(method);
break;
}
}
} else {
Class cls = packageClassLoader.loadClass(str);
entry.setValue(cls);
}
}
}
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Unable to resolve method of field: " + key + " - " + value, e);
}
final ParserConfiguration conf = new ParserConfiguration();
conf.setImports(this.imports);
conf.setPackageImports(this.packageImports);
conf.setClassLoader(packageClassLoader);
this.parserConfiguration = conf;
}
return this.parserConfiguration;
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testContextFieldNotFound.
public void testContextFieldNotFound() {
String str = "'stilton'.equals( type );";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Cheese.class);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
MVEL.executeExpression(stmt, new Cheese(), new HashMap());
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testNestedNumInMapKey.
public void testNestedNumInMapKey() {
String str = "objectKeyMaptributes[Triangle.Foo.OBTUSE]";
ParserConfiguration pconf = new ParserConfiguration();
pconf.addImport("Triangle", Triangle.class);
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Person.class);
pctx.setStrongTyping(true);
Foo foo = new Foo();
Person p = new Person();
Map<Object, Foo> map = new HashMap<Object, Foo>();
map.put(Triangle.Foo.OBTUSE, foo);
p.setObjectKeyMaptributes(map);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Object o = MVEL.executeExpression(stmt, p, new HashMap());
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMethodCallWithSpaces.
public void testMethodCallWithSpaces() {
String[] str = new String[] { "Foo f = new Foo(); f.setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f . setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f. setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f .setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f.boolTest = true ; f.isBoolTest()", "Foo f = new Foo(); f . boolTest = true ; f.isBoolTest()", "Foo f = new Foo(); f. boolTest = true ; f.isBoolTest()", "Foo f = new Foo(); f .boolTest = true ; f.isBoolTest()" };
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", Bar.class);
pctx.addImport(Foo.class);
List<String> errors = new ArrayList<String>();
for (String s : str) {
try {
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(s, pctx);
Bar ctx = new Bar();
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx, new HashMap());
assertTrue(result);
} catch (Exception e) {
e.printStackTrace();
errors.add("**** Error on expression: " + s + "\n" + e.getMessage());
}
}
assertTrue(errors.toString(), errors.isEmpty());
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testNestedClassWithNestedGenericsOnNakedMethod.
public void testNestedClassWithNestedGenericsOnNakedMethod() {
String str = "deliveries.size";
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Triangle.class);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
assertEquals(Integer.valueOf(0), (Integer) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
str = "deliveries.size == 0";
stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
assertTrue((Boolean) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = false;
}
Aggregations