Package org.mvel

Examples of org.mvel.ParserContext


                                final Dialect.AnalysisResult analysis,
                                final Map interceptors,
                                final Map outerDeclarations,
                                final Map otherInputVariables,
                                final RuleBuildContext context) {
        final ParserContext parserContext = getParserContext( analysis,
                                                              outerDeclarations,
                                                              otherInputVariables,
                                                              context );

        ExpressionCompiler compiler = new ExpressionCompiler( text.trim() );
View Full Code Here


    public ParserContext getParserContext(final Dialect.AnalysisResult analysis,
                                          final Map outerDeclarations,
                                          final Map otherInputDeclarations,
                                          final RuleBuildContext context) {
        final ParserContext parserContext = new ParserContext( this.imports,
                                                               null,
                                                               context.getPkg().getName() + "." + context.getRuleDescr().getClassName() );

        for ( Iterator it = this.packageImports.values().iterator(); it.hasNext(); ) {
            String packageImport = (String) it.next();
            parserContext.addPackageImport( packageImport );
        }

        parserContext.setStrictTypeEnforcement( strictMode );

        if ( interceptors != null ) {
            parserContext.setInterceptors( interceptors );
        }
        //FIXME: analysis can be null, throws an NPE
        List list[] = analysis.getBoundIdentifiers();
        DeclarationScopeResolver resolver = context.getDeclarationResolver();
        for ( Iterator it = list[0].iterator(); it.hasNext(); ) {
            String identifier = (String) it.next();
            Class cls = resolver.getDeclaration( identifier ).getExtractor().getExtractToClass();
            parserContext.addInput( identifier,
                                    cls );
        }

        Map globalTypes = context.getPkg().getGlobals();
        for ( Iterator it = list[1].iterator(); it.hasNext(); ) {
            String identifier = (String) it.next();
            parserContext.addInput( identifier,
                                    (Class) globalTypes.get( identifier ) );
        }

        if ( otherInputDeclarations != null ) {
            for ( Iterator it = otherInputDeclarations.entrySet().iterator(); it.hasNext(); ) {
                Entry entry = (Entry) it.next();
                parserContext.addInput( (String) entry.getKey(),
                                        (Class) entry.getValue() );
            }
        }
       
        if ( outerDeclarations != null ) {
            for ( Iterator it = outerDeclarations.entrySet().iterator(); it.hasNext(); ) {
                Entry entry = (Entry) it.next();
                parserContext.addInput( (String) entry.getKey(),
                                        ((Declaration) entry.getValue()).getExtractor().getExtractToClass() );
            }
        }

        parserContext.addInput( "drools",
                                KnowledgeHelper.class );

        return parserContext;
    }
View Full Code Here

        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 );
View Full Code Here

        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 );
View Full Code Here

                                final Dialect.AnalysisResult analysis,
                                final Map interceptors,
                                final Map outerDeclarations,
                                final Map otherInputVariables,
                                final RuleBuildContext context) {
        final ParserContext parserContext = getParserContext( analysis,
                                                              outerDeclarations,
                                                              otherInputVariables,
                                                              context );

        ExpressionCompiler compiler = new ExpressionCompiler( text.trim() );
View Full Code Here

    public ParserContext getParserContext(final Dialect.AnalysisResult analysis,
                                          final Map outerDeclarations,
                                          final Map otherInputDeclarations,
                                          final RuleBuildContext context) {
        final ParserContext parserContext = new ParserContext( this.imports,
                                                               null,
                                                               context.getPkg().getName() + "." + context.getRuleDescr().getClassName() );

        for ( Iterator it = this.packageImports.values().iterator(); it.hasNext(); ) {
            String packageImport = (String) it.next();
            parserContext.addPackageImport( packageImport );
        }

        parserContext.setStrictTypeEnforcement( strictMode );

        if ( interceptors != null ) {
            parserContext.setInterceptors( interceptors );
        }
        //FIXME: analysis can be null, throws an NPE
        List list[] = analysis.getBoundIdentifiers();
        DeclarationScopeResolver resolver = context.getDeclarationResolver();
        for ( Iterator it = list[0].iterator(); it.hasNext(); ) {
            String identifier = (String) it.next();
            Class cls = resolver.getDeclaration( identifier ).getExtractor().getExtractToClass();
            parserContext.addInput( identifier,
                                    cls );
        }

        Map globalTypes = context.getPkg().getGlobals();
        for ( Iterator it = list[1].iterator(); it.hasNext(); ) {
            String identifier = (String) it.next();
            parserContext.addInput( identifier,
                                    (Class) globalTypes.get( identifier ) );
        }

        if ( otherInputDeclarations != null ) {
            for ( Iterator it = otherInputDeclarations.entrySet().iterator(); it.hasNext(); ) {
                Entry entry = (Entry) it.next();
                parserContext.addInput( (String) entry.getKey(),
                                        (Class) entry.getValue() );
            }
        }
       
        if ( outerDeclarations != null ) {
            for ( Iterator it = outerDeclarations.entrySet().iterator(); it.hasNext(); ) {
                Entry entry = (Entry) it.next();
                parserContext.addInput( (String) entry.getKey(),
                                        ((Declaration) entry.getValue()).getExtractor().getExtractToClass() );
            }
        }

        parserContext.addInput( "drools",
                                KnowledgeHelper.class );

        return parserContext;
    }
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

    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 );
View Full Code Here

TOP

Related Classes of org.mvel.ParserContext

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.