Java Code Examples for org.mvel2.MVEL#analyze()

The following examples show how to use org.mvel2.MVEL#analyze() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MVELExprAnalyzer.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public static Class<?> getExpressionType(PackageBuildContext context,
                                         Map<String, Class< ? >> declCls,
                                         RuleConditionElement source,
                                         String expression) {
    MVELDialectRuntimeData data = ( MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" );
    ParserConfiguration conf = data.getParserConfiguration();
    conf.setClassLoader( context.getKnowledgeBuilder().getRootClassLoader() );
    ParserContext pctx = new ParserContext( conf );
    pctx.setStrongTyping(true);
    pctx.setStrictTypeEnforcement(true);
    for (Map.Entry<String, Class< ? >> entry : declCls.entrySet()) {
        pctx.addInput(entry.getKey(), entry.getValue());
    }
    for (Declaration decl : source.getOuterDeclarations().values()) {
        pctx.addInput(decl.getBindingName(), decl.getDeclarationClass());
    }
    try {
        return MVEL.analyze( expression, pctx );
    } catch (Exception e) {
        log.warn( "Unable to parse expression: " + expression, e );
    }
    return null;
}
 
Example 2
Source File: QueryArgument.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private void init() {
    Map<String, Class> inputs = new HashMap<String, Class>();
    for (Declaration d : declarations) {
        inputs.put(d.getBindingName(), d.getDeclarationClass());
    }
    parserContext.setInputs(inputs);

    this.argumentClass = MVEL.analyze( expression, parserContext );
    this.mvelExpr = MVEL.compileExpression( expression, parserContext );
}