Package org.mule.mvel2.compiler

Examples of org.mule.mvel2.compiler.ExpressionCompiler


        super( -1, // index
               Object.class, // fieldType
               ValueType.determineValueType( Object.class ) ); // value type
        this.extractors = 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();
                                   
            InternalReadAccessor extr = cache.getReadAccessor( new AccessorKey( cls.getName(), basefield, AccessorKey.AccessorType.FieldAccessor), cls );
            this.extractors.put( basefield, extr );
View Full Code Here


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

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

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

        synchronized ( COMPILER_LOCK ) {
            ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader();

            Thread.currentThread().setContextClassLoader( pkgBuilder.getRootClassLoader() );

            AbstractParser.setLanguageLevel( languageLevel );
            Serializable expr = compiler.compile( parserContext );

            Thread.currentThread().setContextClassLoader( tempClassLoader );

            return expr;
        }
View Full Code Here

    @Test
    public void testDebugSymbolCount() {
        String expr = "System.out.println( \"a1\" );\n" + "System.out.println( \"a2\" );\n" + "System.out.println( \"a3\" );\n" + "System.out.println( \"a4\" );\n";

        ExpressionCompiler compiler = new ExpressionCompiler( expr );

        ParserContext context = new ParserContext();
        context.setDebugSymbols( true );
        context.addImport( "System",
                           System.class );
        context.setStrictTypeEnforcement( true );
        //context.setDebugSymbols( true );
        context.setSourceFile( "mysource" );


        Serializable compiledExpression = compiler.compile( context );

        String s = DebugTools.decompile( compiledExpression );

        System.out.println( "s " + s );
View Full Code Here

    @Test
    public void testDebugSymbolCount() {
        String expr = "System.out.println( \"a1\" );\n" + "System.out.println( \"a2\" );\n" + "System.out.println( \"a3\" );\n" + "System.out.println( \"a4\" );\n";

        ExpressionCompiler compiler = new ExpressionCompiler( expr );

        ParserContext context = new ParserContext();
        context.setDebugSymbols( true );
        context.addImport( "System",
                           System.class );
        context.setStrictTypeEnforcement( true );
        //context.setDebugSymbols( true );
        context.setSourceFile( "mysource" );


        Serializable compiledExpression = compiler.compile( context );

        String s = DebugTools.decompile( compiledExpression );

        System.out.println( "s " + s );
View Full Code Here

    public Object evaluate(String expression, Map<String, Object> evaluationContext, Object root) throws ExpressionEvaluationException {
        try {
            Serializable template = this.templateCache.get(expression);
            if (template == null) {
                LOG.debug("Compiled template not found in cache, compiling template and caching.");
                ExpressionCompiler compiler = new ExpressionCompiler(expression);
                compiler.newContext(context);
                template = compiler.compile();
                this.templateCache.put(expression, template);
            }
            return MVEL.executeExpression(template, root, evaluationContext);
        } catch (Exception e) {
            throw new ExpressionEvaluationException(expression, e);
View Full Code Here

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

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

        synchronized ( COMPILER_LOCK ) {
            ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader();

            Thread.currentThread().setContextClassLoader( pkgBuilder.getRootClassLoader() );

            AbstractParser.setLanguageLevel( languageLevel );
            Serializable expr = compiler.compile( parserContext );

            Thread.currentThread().setContextClassLoader( tempClassLoader );

            return expr;
        }
View Full Code Here

     */
    private Class getFieldReturnType(final Pattern pattern,
                                     final FieldConstraintDescr fieldConstraintDescr) {
        String dummyField = "__DUMMY__";
        String dummyExpr = dummyField + "." + fieldConstraintDescr.getFieldName();
        ExpressionCompiler compiler = new ExpressionCompiler( dummyExpr );
        ParserContext mvelcontext = new ParserContext();
        mvelcontext.addInput( dummyField,
                              ((ClassObjectType) pattern.getObjectType()).getClassType() );
        compiler.compile( mvelcontext );
        Class resultType = compiler.getReturnType();
        return resultType;
    }
View Full Code Here

    @Test
    public void testDebugSymbolCount() {
        String expr = "System.out.println( \"a1\" );\n" + "System.out.println( \"a2\" );\n" + "System.out.println( \"a3\" );\n" + "System.out.println( \"a4\" );\n";

        ExpressionCompiler compiler = new ExpressionCompiler( expr );

        ParserContext context = new ParserContext();
        context.setDebugSymbols( true );
        context.addImport( "System",
                           System.class );
        context.setStrictTypeEnforcement( true );
        //context.setDebugSymbols( true );
        context.setSourceFile( "mysource" );


        Serializable compiledExpression = compiler.compile( context );

        String s = DebugTools.decompile( compiledExpression );

        System.out.println( "s " + s );
View Full Code Here

                        if (actionString == null) {
                            errors.add(new ProcessValidationErrorImpl(process,
                                "Action node '" + node.getName() + "' [" + node.getId() + "] has empty action."));
                        } else if( "mvel".equals( droolsAction.getDialect() ) ) {
                            try {
                                ExpressionCompiler compiler = new ExpressionCompiler(actionString);
                                compiler.setVerifying(true);
                                ParserContext parserContext = new ParserContext();
                                //parserContext.setStrictTypeEnforcement(true);
                                compiler.compile(parserContext);
                                List<ErrorDetail> mvelErrors = parserContext.getErrorList();
                                if (mvelErrors != null) {
                                    for (Iterator<ErrorDetail> iterator = mvelErrors.iterator(); iterator.hasNext(); ) {
                                        ErrorDetail error = iterator.next();
                                        errors.add(new ProcessValidationErrorImpl(process,
View Full Code Here

                                final ClassLoader classLoader,
                                final ParserContext parserContext,
                                final int languageLevel) {
      MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
     
        ExpressionCompiler compiler = new ExpressionCompiler( text.trim() );

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

        synchronized ( COMPILER_LOCK ) {
            ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader();

            Thread.currentThread().setContextClassLoader( classLoader );

            AbstractParser.setLanguageLevel( languageLevel );
            Serializable expr = null;
            try {
                expr = compiler.compile( parserContext );
            } finally {
                // make sure that in case of exceptions the context classloader is properly restored
                Thread.currentThread().setContextClassLoader( tempClassLoader );
            }
View Full Code Here

TOP

Related Classes of org.mule.mvel2.compiler.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.