use of org.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);
}
}
use of org.mvel2.ParserConfiguration in project jbpm by kiegroup.
the class MVELDataTransformer method compile.
@Override
public Object compile(String expression, Map<String, Object> parameters) {
logger.debug("About to compile mvel expression {}", expression);
ClassLoader classLoader = (ClassLoader) parameters.get("classloader");
if (classLoader == null) {
classLoader = this.getClass().getClassLoader();
}
ParserConfiguration config = new ParserConfiguration();
config.setClassLoader(classLoader);
ParserContext context = new ParserContext(config);
if (parameters != null) {
@SuppressWarnings("unchecked") Set<String> imports = (Set<String>) parameters.get("imports");
if (imports != null) {
for (String clazz : imports) {
try {
Class<?> cl = Class.forName(clazz, true, classLoader);
context.addImport(cl.getSimpleName(), cl);
} catch (ClassNotFoundException e) {
logger.warn("Unable to load class {} due to {}", clazz, e.getException());
}
;
}
}
}
return MVEL.compileExpression(expression, context);
}
use of org.mvel2.ParserConfiguration in project mule by mulesoft.
the class AbstractVarExpressionDataTypeResolverTestCase method doVarDataTypeTest.
protected void doVarDataTypeTest(String expression) throws Exception {
DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
PrivilegedEvent event = setVariable((PrivilegedEvent) testEvent(), EXPRESSION_VALUE, expectedDataType);
final ParserConfiguration parserConfiguration = MVELExpressionLanguage.createParserConfiguration(Collections.EMPTY_MAP);
final MVELExpressionLanguageContext context = createMvelExpressionLanguageContext(event, parserConfiguration);
CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(parserConfiguration));
// Expression must be executed, otherwise the variable accessor is not properly configured
MVEL.executeExpression(compiledExpression, context);
assertThat(expressionDataTypeResolver.resolve(event, compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mvel2.ParserConfiguration in project mule by mulesoft.
the class MVELExpressionLanguage method createParserConfiguration.
public static ParserConfiguration createParserConfiguration(Map<String, Class<?>> imports) {
ParserConfiguration ParserConfiguration = new ParserConfiguration();
configureParserConfiguration(ParserConfiguration, imports);
return ParserConfiguration;
}
use of org.mvel2.ParserConfiguration in project mule by mulesoft.
the class DateTimeExpressionLanguageFunctionTestCase method setup.
@Before
public void setup() throws InitialisationException {
ParserConfiguration parserConfiguration = new ParserConfiguration();
expressionExecutor = new MVELExpressionExecutor(parserConfiguration);
context = new MVELExpressionLanguageContext(parserConfiguration, Mockito.mock(MuleContext.class));
dateTimeFunction = new DateTimeExpressionLanguageFuntion();
context.declareFunction("dateTime", dateTimeFunction);
}
Aggregations