Package org.mvel

Examples of org.mvel.ExpressionCompiler


        final ParserContext parserContext = getParserContext( analysis,
                                                              outerDeclarations,
                                                              otherInputVariables,
                                                              context );

        ExpressionCompiler compiler = new ExpressionCompiler( text.trim() );

        if ( MVELDebugHandler.isDebugMode() ) {
            System.out.println( "Source before MVEL Compilation:\n" + text.trim() );
            compiler.setDebugSymbols( true );
        }

        Serializable expr = compiler.compile( parserContext );
        return expr;
    }
View Full Code Here


                                                final String expr,
                                                final Set[] availableIdentifiers,
                                                final Map localTypes) throws RecognitionException {
        MVELAnalysisResult result = null;
        if ( expr.trim().length() > 0 ) {
            ExpressionCompiler compiler = new ExpressionCompiler( expr );

            MVELDialect dialect = (MVELDialect) context.getDialect( "mvel" );

            final ParserContext parserContext = new ParserContext( dialect.getImports(),
                                                                   null,
                                                                   context.getPkg().getName() + "." + context.getRuleDescr().getClassName() );

            if ( dialect.getPackgeImports() != null && !dialect.getPackgeImports().isEmpty() ) {
              for ( Iterator it = dialect.getPackgeImports().values().iterator(); it.hasNext(); ) {
                  String packageImport = (String) it.next();
                  parserContext.addPackageImport( packageImport );
              }
            }
           
            parserContext.setStrictTypeEnforcement( false );

            parserContext.setInterceptors( dialect.getInterceptors() );

            compiler.compile( parserContext );

            result = analyze( compiler.getParserContextState().getInputs().keySet(),
                              availableIdentifiers );

            result.setMvelVariables( compiler.getParserContextState().getVariables() );
        } else {
            result = analyze( Collections.EMPTY_SET,
                              availableIdentifiers );
            result.setMvelVariables( new HashMap() );
View Full Code Here

                                                final String expr,
                                                final Set[] availableIdentifiers,
                                                final Map localTypes) throws RecognitionException {
        MVELAnalysisResult result = null;
        if ( expr.trim().length() > 0 ) {
            ExpressionCompiler compiler = new ExpressionCompiler( expr );

            MVELDialect dialect = (MVELDialect) context.getDialect( "mvel" );

            final ParserContext parserContext = new ParserContext( dialect.getImports(),
                                                                   null,
                                                                   context.getPkg().getName() + "." + context.getRuleDescr().getClassName() );

            if ( dialect.getPackgeImports() != null && !dialect.getPackgeImports().isEmpty() ) {
              for ( Iterator it = dialect.getPackgeImports().values().iterator(); it.hasNext(); ) {
                  String packageImport = (String) it.next();
                  parserContext.addPackageImport( packageImport );
              }
            }
           
            parserContext.setStrictTypeEnforcement( false );

            parserContext.setInterceptors( dialect.getInterceptors() );

            compiler.compile( parserContext );

            result = analyze( compiler.getParserContextState().getInputs().keySet(),
                              availableIdentifiers );

            result.setMvelVariables( compiler.getParserContextState().getVariables() );
        } else {
            result = analyze( Collections.EMPTY_SET,
                              availableIdentifiers );
            result.setMvelVariables( new HashMap() );
View Full Code Here

        final ParserContext parserContext = getParserContext( analysis,
                                                              outerDeclarations,
                                                              otherInputVariables,
                                                              context );

        ExpressionCompiler compiler = new ExpressionCompiler( text.trim() );

        if ( MVELDebugHandler.isDebugMode() ) {
            compiler.setDebugSymbols( true );
        }

        Serializable expr = compiler.compile( parserContext );
        return expr;
    }
View Full Code Here

    public void trigger(final RuleFlowNodeInstance from) {
    Object action = getActionNode().getAction();
    if (action instanceof DroolsConsequenceAction) {
      String actionString = ((DroolsConsequenceAction) action).getConsequence();
        ExpressionCompiler compiler = new ExpressionCompiler(actionString);
        ParserContext parserContext = new ParserContext();
        Serializable expression = compiler.compile(parserContext);
        DroolsMVELFactory factory = new DroolsMVELFactory(Collections.EMPTY_MAP, null, Collections.EMPTY_MAP);
        MVEL.executeExpression(expression, null, factory);
    } else {
      throw new RuntimeException("Unknown action: " + action);
    }
View Full Code Here

               Object.class, // fieldType
               ValueType.determineValueType( Object.class ) ); // value type
        this.extractors = new HashMap();
        this.variables = new HashMap();

        ExpressionCompiler compiler = new ExpressionCompiler( fieldName );
        this.mvelExpression = compiler.compile();
       
        Set inputs = compiler.getParserContextState().getInputs().keySet();
        for( Iterator it = inputs.iterator(); it.hasNext(); ) {
            String basefield = (String) it.next();
                       
            Extractor extr = ClassFieldExtractorCache.getExtractorclazz, basefield, classLoader );
            this.extractors.put( basefield, extr );
View Full Code Here

    }

    public void testMVELSerialization() {
        String expression = "x";
       
        ExpressionCompiler compiler = new ExpressionCompiler( expression );
        ParserContext ctx = new ParserContext();
        ctx.addImport( "x", int.class );
       
        Serializable result = compiler.compile( ctx );
       
        try {
            byte[] out = serializeOut( result );
            Serializable in = (Serializable) serializeIn( out );
            assertNotNull( in );
View Full Code Here

TOP

Related Classes of org.mvel.ExpressionCompiler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.