use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testUnwantedImport.
public void testUnwantedImport() {
ParserConfiguration conf = new ParserConfiguration();
conf.addPackageImport("java.util");
conf.addPackageImport("org.mvel2.tests.core.res");
ParserContext pctx = new ParserContext(conf);
MVEL.analysisCompile("ScenarioType.Set.ADD", pctx);
assertNull(conf.getImports().get("Set"));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testBigDecimalOutput.
public void testBigDecimalOutput() {
String str = "import java.math.BigDecimal; BigDecimal test = new BigDecimal(\"50000\"); System.out.println(test / new BigDecimal(\"1.13\"));";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.setStrictTypeEnforcement(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
MVEL.executeExpression(stmt, new HashMap());
}
use of org.mule.mvel2.ParserConfiguration in project kie-wb-common by kiegroup.
the class DataEnumLoader method loadEnum.
private Map<String, String[]> loadEnum(String mvelSource, ClassLoader classLoader, MVELEvaluator mvelEvaluator) {
if (mvelSource == null || (mvelSource.trim().equals(""))) {
return Collections.emptyMap();
}
if (mvelSource.startsWith("=")) {
mvelSource = mvelSource.substring(1);
} else {
mvelSource = "[ " + addCommasForNewLines(mvelSource) + " ]";
}
final Object mvelData;
try {
final ParserConfiguration pconf = new ParserConfiguration();
final ParserContext pctx = new ParserContext(pconf);
pconf.setClassLoader(classLoader);
final Serializable compiled = MVEL.compileExpression(mvelSource, pctx);
mvelData = mvelEvaluator.executeExpression(compiled, new HashMap<String, Object>());
} catch (RuntimeException e) {
addError("Unable to load enumeration data.");
addError(e.getMessage());
addError("Error type: " + e.getClass().getName());
return Collections.emptyMap();
}
if (!(mvelData instanceof Map<?, ?>)) {
addError("The expression is not a map, it is a " + mvelData.getClass().getName());
return Collections.emptyMap();
}
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) mvelData;
Map<String, String[]> newMap = new HashMap<>();
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = makeEnumKey(entry.getKey());
validateKey(key);
Object list = entry.getValue();
if (!(list instanceof List<?> || list instanceof String)) {
if (list == null) {
addError("The item with " + key + " is null.");
} else {
addError("The item with " + key + " is not a list or a string, it is a " + list.getClass().getName());
}
return Collections.emptyMap();
} else if (list instanceof String) {
newMap.put(key, new String[] { (String) list });
} else {
List<?> items = (List<?>) list;
String[] newItems = new String[items.size()];
for (int i = 0; i < items.size(); i++) {
Object listItem = items.get(i);
if (!(listItem instanceof String)) {
newItems[i] = listItem.toString();
} else {
newItems[i] = (String) listItem;
}
}
newMap.put(key, newItems);
}
}
return newMap;
}
use of org.mule.mvel2.ParserConfiguration in project jbpm by kiegroup.
the class MVELObjectModelResolver method getInstance.
@Override
public Object getInstance(ObjectModel model, ClassLoader cl, Map<String, Object> contextParams) {
Object instance = null;
InternalRuntimeManager manager = null;
if (contextParams.containsKey("runtimeManager")) {
manager = (InternalRuntimeManager) contextParams.get("runtimeManager");
instance = manager.getCacheManager().get(model.getIdentifier());
if (instance != null) {
return instance;
}
}
ParserConfiguration config = new ParserConfiguration();
config.setClassLoader(cl);
ParserContext ctx = new ParserContext(config);
if (contextParams != null) {
for (Map.Entry<String, Object> entry : contextParams.entrySet()) {
ctx.addVariable(entry.getKey(), entry.getValue().getClass());
}
}
Object compiledExpression = MVEL.compileExpression(model.getIdentifier(), ctx);
instance = MVELSafeHelper.getEvaluator().executeExpression(compiledExpression, contextParams);
if (manager != null && instance instanceof Cacheable) {
manager.getCacheManager().add(model.getIdentifier(), instance);
}
return instance;
}
use of org.mule.mvel2.ParserConfiguration in project jbpm by kiegroup.
the class MVELLifeCycleManager method eval.
public static Object eval(String str, Map<String, Object> vars) {
ParserConfiguration pconf = new ParserConfiguration();
pconf.addPackageImport("org.kie.internal.task.api.model");
pconf.addPackageImport("org.jbpm.services.task");
pconf.addPackageImport("org.jbpm.services.task.impl.model");
pconf.addPackageImport("org.jbpm.services.task.query");
pconf.addPackageImport("org.jbpm.services.task.internals.lifecycle");
pconf.addImport(Status.class);
pconf.addImport(Allowed.class);
pconf.addPackageImport("java.util");
ParserContext context = new ParserContext(pconf);
Serializable s = MVEL.compileExpression(str.trim(), context);
if (vars != null) {
return MVELSafeHelper.getEvaluator().executeExpression(s, vars);
} else {
return MVELSafeHelper.getEvaluator().executeExpression(s);
}
}
Aggregations