use of org.mule.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.mule.mvel2.ParserConfiguration in project mule by mulesoft.
the class AbstractVarAssignmentDataTypePropagatorTestCase method createMvelExpressionLanguageContext.
protected MVELExpressionLanguageContext createMvelExpressionLanguageContext(PrivilegedEvent testEvent, PrivilegedEvent.Builder builder, ParserConfiguration parserConfiguration) {
final MVELExpressionLanguageContext context = new MVELExpressionLanguageContext(parserConfiguration, muleContext);
final StaticVariableResolverFactory staticContext = new StaticVariableResolverFactory(parserConfiguration, muleContext);
final GlobalVariableResolverFactory globalContext = new GlobalVariableResolverFactory(emptyMap(), emptyMap(), parserConfiguration, muleContext);
final DelegateVariableResolverFactory innerDelegate = new DelegateVariableResolverFactory(globalContext, new VariableVariableResolverFactory(parserConfiguration, muleContext, testEvent, builder));
final DelegateVariableResolverFactory delegate = new DelegateVariableResolverFactory(staticContext, new MessageVariableResolverFactory(parserConfiguration, muleContext, testEvent, builder, innerDelegate));
context.setNextFactory(new CachedMapVariableResolverFactory(emptyMap(), delegate));
return context;
}
use of org.mule.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.mule.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.mule.mvel2.ParserConfiguration in project mule by mulesoft.
the class MVELExpressionLanguage method evaluateUntyped.
public <T> T evaluateUntyped(String expression, PrivilegedEvent event, PrivilegedEvent.Builder eventBuilder, ComponentLocation componentLocation, Map<String, Object> vars) {
if (event == null) {
return evaluateUntyped(expression, vars);
}
MVELExpressionLanguageContext context = createExpressionLanguageContext();
final DelegateVariableResolverFactory innerDelegate = new DelegateVariableResolverFactory(globalContext, createVariableVariableResolverFactory(event, eventBuilder));
final DelegateVariableResolverFactory delegate = new DelegateVariableResolverFactory(staticContext, new EventVariableResolverFactory(parserConfiguration, muleContext, event, eventBuilder, componentLocation, innerDelegate));
if (vars != null) {
context.setNextFactory(new CachedMapVariableResolverFactory(vars, delegate));
} else {
context.setNextFactory(delegate);
}
return evaluateInternal(expression, context);
}
Aggregations