Java Code Examples for org.mvel2.MVEL#COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION

The following examples show how to use org.mvel2.MVEL#COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION . 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: PatternBuilder.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private FieldValue getFieldValue(RuleBuildContext context,
                                 ValueType vtype,
                                 String value) {
    try {
        MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
        MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
        MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true;
        MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true;

        MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData("mvel");
        ParserConfiguration pconf = data.getParserConfiguration();
        ParserContext pctx = new ParserContext(pconf);

        Object o = MVELSafeHelper.getEvaluator().executeExpression(MVEL.compileExpression(value, pctx));
        if (o != null && vtype == null) {
            // was a compilation problem else where, so guess valuetype so we can continue
            vtype = ValueType.determineValueType(o.getClass());
        }

        return context.getCompilerFactory().getFieldFactory().getFieldValue(o, vtype);
    } catch (final Exception e) {
        // we will fallback to regular preducates, so don't raise an error
    }
    return null;
}
 
Example 2
Source File: MVELObjectClassFieldReader.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public static void doCompile(MVELClassFieldReader target, MVELDialectRuntimeData runtimeData, Object evaluationContext) {
    Class cls;
    try {            
        cls = runtimeData.getRootClassLoader().loadClass( target.getClassName() );
    } catch ( ClassNotFoundException e ) {
        throw new IllegalStateException( "Unable to compile as Class could not be found '" + target.getClassName() + "'");
    }
    ParserContext context = new ParserContext(runtimeData.getParserConfiguration(), evaluationContext);
    context.addInput( "this", cls );
    context.setStrongTyping( target.isTypeSafe() );

    MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true;
    MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true;
    ExecutableStatement mvelExpression = (ExecutableStatement)MVEL.compileExpression( target.getExpression(), context);
    
    Class returnType = mvelExpression.getKnownEgressType();
    target.setExecutableStatement( mvelExpression );
    target.setFieldType( returnType );
    target.setValueType( ValueType.determineValueType( returnType ) );
    target.setEvaluationContext(evaluationContext);
}
 
Example 3
Source File: MVELCompilationUnit.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private static Serializable compile( final String text,
                                     final ParserContext parserContext ) {
    MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true;
    MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true;   
    
    if ( MVELDebugHandler.isDebugMode() ) {
        parserContext.setDebugSymbols( true );
    }

    return MVEL.compileExpression( text.trim(),
                                   parserContext );
}
 
Example 4
Source File: PatternBuilder.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
protected void setInputs(RuleBuildContext context,
                         ExprBindings descrBranch,
                         Class<?> thisClass,
                         String expr) {
    MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData("mvel");
    ParserConfiguration conf = data.getParserConfiguration();

    conf.setClassLoader(context.getKnowledgeBuilder().getRootClassLoader());

    final ParserContext pctx = new ParserContext(conf);
    pctx.setStrictTypeEnforcement(false);
    pctx.setStrongTyping(false);
    pctx.addInput("this", thisClass);
    pctx.addInput("empty", boolean.class); // overrides the mvel empty label
    MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true;
    MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true;

    try {
        MVEL.analysisCompile(expr, pctx);
    } catch (Exception e) {
        // There is a problem in setting the inputs for this expression, but it will be
        // reported during expression analysis, so swallow it at the moment
        return;
    }

    if (!pctx.getInputs().isEmpty()) {
        for (String v : pctx.getInputs().keySet()) {
            // in the following if, we need to check that the expr actually contains a reference
            // to an "empty" property, or the if will evaluate to true even if it doesn't 
            if ("this".equals(v) || (PropertyTools.getFieldOrAccessor(thisClass,
                                                                      v) != null && expr.matches("(^|.*\\W)empty($|\\W.*)"))) {
                descrBranch.getFieldAccessors().add(v);
            } else if ("empty".equals(v)) {
                // do nothing
            } else if (!context.getPkg().getGlobals().containsKey(v)) {
                descrBranch.getRuleBindings().add(v);
            } else {
                descrBranch.getGlobalBindings().add(v);
            }
        }
    }
}