Package org.mvel

Examples of org.mvel.ExpressionCompiler


               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.getInstance().getExtractorclazz, basefield, classLoader );
            this.extractors.put( basefield, extr );
View Full Code Here


                    String actionString = droolsAction.getConsequence();
                    if (actionString == null) {
                      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
              }
                }
          }
        }
        TypeResolver typeResolver = new ClassTypeResolver(importSet, Thread.currentThread().getContextClassLoader());
        // compile expression
        Serializable expression = compiler.compile(parserContext);
        // globals
        Map globalDefs = getProcessInstance().getRuleFlowProcess().getGlobals();
        Map globals = new HashMap();
        if (globalDefs != null) {
          for (Iterator iterator = globalDefs.entrySet().iterator(); iterator.hasNext(); ) {
View Full Code Here

        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();
                       
            Extractor extr = ClassFieldExtractorCache.getInstance().getExtractorclazz, basefield, classLoader );
            this.extractors.put( basefield, extr );
View Full Code Here

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

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

        Serializable expr = compiler.compile( parserContext );
        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

        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.addImport("System", System.class);
        context.setStrictTypeEnforcement(true);
        //context.setDebugSymbols( true );
        context.setSourceFile( "mysource" );
  
        compiler.setDebugSymbols( true );
       
        Serializable compiledExpression = compiler.compile(context);          
  
        String s = org.mvel.debug.DebugTools.decompile( compiledExpression );
  
        System.out.println("s "+s);
       
View Full Code Here

        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.addImport("System", System.class);
        context.setStrictTypeEnforcement(true);
        //context.setDebugSymbols( true );
        context.setSourceFile( "mysource" );
  
        compiler.setDebugSymbols( true );
       
        Serializable compiledExpression = compiler.compile(context);          
  
        String s = org.mvel.debug.DebugTools.decompile( compiledExpression );
  
        System.out.println("s "+s);
       
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.