Search in sources :

Example 36 with ParserConfiguration

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);
}
Also used : Set(java.util.Set) ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 37 with ParserConfiguration

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;
}
Also used : DelegateVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.DelegateVariableResolverFactory) MVELExpressionLanguageContext(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext) GlobalVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.GlobalVariableResolverFactory) MessageVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.MessageVariableResolverFactory) CachedMapVariableResolverFactory(org.mule.mvel2.integration.impl.CachedMapVariableResolverFactory) StaticVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.StaticVariableResolverFactory) VariableVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.VariableVariableResolverFactory)

Example 38 with ParserConfiguration

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) MVELExpressionLanguageContext(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext) DataType(org.mule.runtime.api.metadata.DataType) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression) ParserConfiguration(org.mule.mvel2.ParserConfiguration)

Example 39 with ParserConfiguration

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;
}
Also used : ParserConfiguration(org.mule.mvel2.ParserConfiguration)

Example 40 with 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);
}
Also used : CachedMapVariableResolverFactory(org.mule.mvel2.integration.impl.CachedMapVariableResolverFactory)

Aggregations

ParserConfiguration (org.mvel2.ParserConfiguration)74 ParserContext (org.mvel2.ParserContext)70 HashMap (java.util.HashMap)39 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)32 LinkedHashMap (java.util.LinkedHashMap)29 Map (java.util.Map)23 Serializable (java.io.Serializable)10 MVELExpressionLanguageContext (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext)7 CompileException (org.mvel2.CompileException)7 ParserConfiguration (org.mule.mvel2.ParserConfiguration)6 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)5 MapObject (org.mvel2.tests.core.res.MapObject)5 Method (java.lang.reflect.Method)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Before (org.junit.Before)3 CachedMapVariableResolverFactory (org.mule.mvel2.integration.impl.CachedMapVariableResolverFactory)3 MVELExpressionExecutor (org.mule.runtime.core.internal.el.mvel.MVELExpressionExecutor)3 Bar (org.mvel2.tests.core.res.Bar)3