Search in sources :

Example 6 with ParserConfiguration

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

Example 7 with ParserConfiguration

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

Example 8 with ParserConfiguration

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));
}
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 9 with ParserConfiguration

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

Example 10 with 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);
}
Also used : MVELExpressionExecutor(org.mule.runtime.core.internal.el.mvel.MVELExpressionExecutor) MVELExpressionLanguageContext(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext) ParserConfiguration(org.mule.mvel2.ParserConfiguration) Before(org.junit.Before)

Aggregations

ParserConfiguration (org.mvel2.ParserConfiguration)95 ParserContext (org.mvel2.ParserContext)88 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)48 HashMap (java.util.HashMap)43 LinkedHashMap (java.util.LinkedHashMap)30 Map (java.util.Map)27 Serializable (java.io.Serializable)12 CompileException (org.mvel2.CompileException)9 MVEL.evalToBoolean (org.mvel2.MVEL.evalToBoolean)9 IOException (java.io.IOException)7 MapObject (org.mvel2.tests.core.res.MapObject)7 ParserConfiguration (org.mule.mvel2.ParserConfiguration)6 Method (java.lang.reflect.Method)5 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)5 MVELExpressionLanguageContext (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext)5 RecognitionException (org.antlr.runtime.RecognitionException)4 PropertyAccessException (org.mvel2.PropertyAccessException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3