Package org.mvel

Examples of org.mvel.ParserContext


                      errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.ACTION_NODE_WITHOUT_ACTION, "name = " + actionNode.getName() ) );
                    } else {
                        try {
                          ExpressionCompiler compiler = new ExpressionCompiler(actionString);
                          compiler.setVerifying(true);
                        ParserContext parserContext = new ParserContext();
                        //parserContext.setStrictTypeEnforcement(true);
                        compiler.compile(parserContext);
                        List mvelErrors = parserContext.getErrorList();
                        if (mvelErrors != null) {
                          for (Iterator iterator = mvelErrors.iterator(); iterator.hasNext(); ) {
                            Object error = iterator.next();
                            errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.ACTION_NODE_WITH_INVALID_ACTION, "name = " + actionNode.getName() + " " + error ) );
                          }
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();
        // imports
        List imports = getProcessInstance().getRuleFlowProcess().getImports();
        Set importSet = new HashSet();
        if (imports != null) {
            importSet.addAll(imports);
          for (Iterator iterator = imports.iterator(); iterator.hasNext(); ) {
            String importClassName = (String) iterator.next();
            if ( importClassName.endsWith( ".*" ) ) {
              importClassName = importClassName.substring(0, importClassName.indexOf(".*"));
                    parserContext.addPackageImport(importClassName);
                } else {
              try {
                parserContext.addImport(Class.forName(importClassName));
              } catch (ClassNotFoundException e) {
                // class not found, do nothing
              }
                }
          }
View Full Code Here

    public Serializable compile(final String text,
                                final Dialect.AnalysisResult analysis,
                                final Map interceptors,
                                final Map outerDeclarations,
                                final RuleBuildContext context) {
        final ParserContext parserContext = getParserContext(analysis, outerDeclarations, context );

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

        if (MVELDebugHandler.isDebugMode()) {
          System.out.println("Source before MVEL Compilation:\n"+text.trim());
View Full Code Here

        Serializable expr = compiler.compile( parserContext );
        return expr;
    }

    public ParserContext getParserContext(final Dialect.AnalysisResult analysis, final Map outerDeclarations, 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 ) );
        }

        Map mvelVars = ((MVELAnalysisResult) analysis).getMvelVariables();
        if ( mvelVars != null ) {
            for ( Iterator it = mvelVars.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() );

            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

    public Serializable compile(final String text,
                                final Dialect.AnalysisResult analysis,
                                final Map interceptors,
                                final Map outerDeclarations,
                                final RuleBuildContext context) {
        final ParserContext parserContext = getParserContext(analysis, outerDeclarations, context );

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

        if (MVELDebugHandler.isDebugMode()) {
            compiler.setDebugSymbols( true );
View Full Code Here

        Serializable expr = compiler.compile( parserContext );
        return expr;
    }
   
    public ParserContext getParserContext(final Dialect.AnalysisResult analysis, final Map outerDeclarations, final RuleBuildContext context) {
        final ParserContext parserContext = new ParserContext( 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 );
        }

        //this.configuration.get

        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 ) );
        }

        Map mvelVars = ((MVELAnalysisResult) analysis).getMvelVariables();
        if ( mvelVars != null ) {
            for ( Iterator it = mvelVars.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

    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

                      "System.out.println( \"a3\" );\n" +
                      "System.out.println( \"a4\" );\n";
  
        ExpressionCompiler compiler = new ExpressionCompiler(expr);
  
        ParserContext context = new ParserContext();
        context.addImport("System", System.class);
        context.setStrictTypeEnforcement(true);
        //context.setDebugSymbols( true );
        context.setSourceFile( "mysource" );
  
        compiler.setDebugSymbols( true );
       
        Serializable compiledExpression = compiler.compile(context);          
  
View Full Code Here

                      "System.out.println( \"a3\" );\n" +
                      "System.out.println( \"a4\" );\n";
  
        ExpressionCompiler compiler = new ExpressionCompiler(expr);
  
        ParserContext context = new ParserContext();
        context.addImport("System", System.class);
        context.setStrictTypeEnforcement(true);
        //context.setDebugSymbols( true );
        context.setSourceFile( "mysource" );
  
        compiler.setDebugSymbols( true );
       
        Serializable compiledExpression = compiler.compile(context);          
  
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.