Package org.drools.compiler

Examples of org.drools.compiler.DroolsError


            if ( val instanceof List ) {
                calNames = ( String[] ) ((List)val).toArray( new String[ ((List)val).size() ] );
            } else if ( val instanceof String ) {
                calNames = new String[] { (String) val };
            } else {
                DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                      "Calendars attribute did not return a String or String[] '" + val + "'" );
                context.addError( err  );
            }
            if ( calNames != null ) {
                rule.setCalendars( calNames );
            }
        } catch ( Exception e ) {
            DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                  "Unable to build Calendars attribute '" + val + "'"  + e.getMessage() );
            context.addError( err );
        }
    }
View Full Code Here


       
        int colonPos = timerString.indexOf( ":" );
        String protocol = null;
        if ( colonPos == -1 ) {
            if ( timerString.startsWith( "int" ) || timerString.startsWith( "cron" ) || timerString.startsWith( "expr" ) ) {
                DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                      "Incorrect timer definition '" + timerString + "' - missing colon?" );
                context.addError( err );
                return;
            }
            // no protocol so assume interval semantics
            protocol = "int";
        } else {
            protocol = timerString.substring( 0, colonPos );
        }
       
        int startPos = timerString.indexOf( "start" );
        int endPos = timerString.indexOf( "end" );
        int repeatPos = timerString.indexOf( "repeat-limit" );
       
        Date startDate = null;
        Date endDate = null;
        int repeatLimit = -1;
       
        int  optionsPos = timerString.length();
       
        if ( startPos != -1 ) {
            optionsPos = startPos;
            int p = ( endPos != -1 && endPos < repeatPos ) ? endPos : repeatPos;
           
            if ( p == -1 ) {
                p = timerString.length();
            }
           
            int equalsPos = timerString.indexOf( '=', startPos );
            startDate = DateUtils.parseDate( timerString.substring( equalsPos + 1, p ).trim(),
                                             context.getPackageBuilder().getDateFormats()  );
        }
       
        if ( endPos != -1 ) {
            if ( optionsPos > endPos ) {
                optionsPos = endPos;
            }
            int p = ( startPos != -1 && startPos < repeatPos ) ? startPos : repeatPos;
           
            if ( p == -1 ) {
                p = timerString.length();
            }
           
            int equalsPos = timerString.indexOf( '=', endPos );
            endDate = DateUtils.parseDate( timerString.substring( equalsPos + 1, p ).trim(),
                                           context.getPackageBuilder().getDateFormats()  );
        }
       
        if ( repeatPos != -1 ) {
            if ( optionsPos > repeatPos ) {
                optionsPos = repeatPos;
            }
            int p = ( startPos != -1 && startPos < endPos ) ? startPos : endPos;
           
            if ( p == -1 ) {
                p = timerString.length();
            }
           
            int equalsPos = timerString.indexOf( '=', repeatPos );
            repeatLimit = Integer.parseInt( timerString.substring( equalsPos + 1, p ).trim() );
        }
                    
        String body = timerString.substring( colonPos + 1, optionsPos ).trim();
       
        Timer timer = null;
        if ( "cron".equals( protocol ) ) {
            try {
                timer = new CronTimer( startDate, endDate, repeatLimit, new CronExpression( body ) );
            } catch ( ParseException e ) {
                DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                      "Unable to build set timer '" + timerString + "'" );               
                context.addError( err );
                return;
            }
        } else if ( "int".equals( protocol ) ) {
            String[] times = body.trim().split( "\\s" );
            long delay = 0;
            long period = 0;

            if ( times.length > 2 ) {
                DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                      "Incorrect number of arguments for interval timer '" + timerString + "'" );
                context.addError( err );
                return;
            }

            try {
                if ( times.length == 1 ) {
                    // only defines a delay
                    delay = TimeUtils.parseTimeString( times[0] );
                } else {
                    // defines a delay and a period for intervals
                    delay = TimeUtils.parseTimeString( times[0] );
                    period = TimeUtils.parseTimeString( times[1] );
                }
            } catch (RuntimeException e) {
                DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                      "Incorrect timer definition '" + timerString + "' " + e.getMessage() );
                context.addError( err );
                return;
            }

            timer = new IntervalTimer(startDate, endDate, repeatLimit, delay, period);
        } else if ( "expr".equals( protocol ) ) {
            body = body.trim();
            StringTokenizer tok = new StringTokenizer( body, ",;" );

            if ( tok.countTokens() > 2 ) {
                DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                        "Incorrect number of arguments for expression timer '" + timerString + "'" );
                context.addError( err );
                return;
            }

            MVELObjectExpression times = MVELObjectExpressionBuilder.build( tok.nextToken().trim(), context );
            MVELObjectExpression period = null;
            if ( tok.hasMoreTokens() ) {
                period = MVELObjectExpressionBuilder.build( tok.nextToken().trim(), context );
            } else {
                period = MVELObjectExpressionBuilder.build( "0", context );
            }

            timer = new ExpressionIntervalTimer( startDate, endDate, repeatLimit, times, period );
        } else {
            DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                  "Protocol for timer does not exist '" + timerString +"'" );
            context.addError( err );
            return;
        }
        rule.setTimer( timer );
View Full Code Here

        // parser errors are another test case
        final PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "errors_in_rule.drl" ) ) );
        final Package pkg = builder.getPackage();

        final DroolsError err = builder.getErrors().getErrors()[0];
        final RuleError ruleErr = (RuleError) err;
        assertNotNull( ruleErr.getDescr() );
        assertTrue( ruleErr.getLine() != -1 );

        final DroolsError errs[] = builder.getErrors().getErrors();

        assertEquals( 3,
                      builder.getErrors().getErrors().length );

        // check that its getting it from the ruleDescr
View Full Code Here

        // parser errors are another test case
        final PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "errors_in_rule.drl" ) ) );
        final Package pkg = builder.getPackage();

        final DroolsError err = builder.getErrors().getErrors()[0];
        final DescrBuildError ruleErr = (DescrBuildError) err;
        assertNotNull( ruleErr.getDescr() );
        assertTrue( ruleErr.getLine() != -1 );

        final DroolsError errs[] = builder.getErrors().getErrors();

        assertEquals( 3,
                      builder.getErrors().getErrors().length );

        // check that its getting it from the ruleDescr
View Full Code Here

        // parser errors are another test case
        final PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "errors_in_rule.drl" ) ) );
        final Package pkg = builder.getPackage();

        final DroolsError err = builder.getErrors().getErrors()[0];
        final DescrBuildError ruleErr = (DescrBuildError) err;
        assertNotNull( ruleErr.getDescr() );
        assertTrue( ruleErr.getLine() != -1 );

        final DroolsError errs[] = builder.getErrors().getErrors();

        assertEquals( 3,
                      builder.getErrors().getErrors().length );

        // check that its getting it from the ruleDescr
View Full Code Here

     */
    private void markOtherErrors(List markers,
                                        DroolsError[] buildErrors) {
        // TODO are there warnings too?
        for (int i = 0; i < buildErrors.length; i++ ) {
            DroolsError error = buildErrors[i];
            if (error instanceof GlobalError) {
                GlobalError globalError = (GlobalError) error;
                markers.add(new DroolsBuildMarker("Global error: " + globalError.getGlobal(), -1));
            } else if (error instanceof RuleBuildError) {
                RuleBuildError ruleError = (RuleBuildError) error;
                // TODO try to retrieve line number (or even character start-end)
                // disabled for now because line number are those of the rule class,
                // not the rule file itself
                if (ruleError.getObject() instanceof CompilationProblem[]) {
                    CompilationProblem[] problems = (CompilationProblem[]) ruleError.getObject();
                    for (int j = 0; j < problems.length; j++) {
                        markers.add(new DroolsBuildMarker(problems[j].getMessage(), ruleError.getLine()));
                    }
                } else {
                    markers.add(new DroolsBuildMarker(ruleError.getRule().getName() + ":" + ruleError.getMessage(), ruleError.getLine()));
                }
            } else if (error instanceof ParserError) {
                ParserError parserError = (ParserError) error;
                // TODO try to retrieve character start-end
                markers.add(new DroolsBuildMarker(parserError.getMessage(), parserError.getRow()));
            } else if (error instanceof FunctionError) {
                FunctionError functionError = (FunctionError) error;
                // TODO add line to function error
                // TODO try to retrieve character start-end
                if (functionError.getObject() instanceof CompilationProblem[]) {
                    CompilationProblem[] problems = (CompilationProblem[]) functionError.getObject();
                    for (int j = 0; j < problems.length; j++) {
                        markers.add(new DroolsBuildMarker(problems[j].getMessage(), functionError.getErrorLines()[j]));
                    }
                } else {
                    markers.add(new DroolsBuildMarker(functionError.getFunctionDescr().getName() + ":" + functionError.getMessage(), -1));
                }
            } else if (error instanceof FieldTemplateError) {
                markers.add(new DroolsBuildMarker(error.getMessage(), ((FieldTemplateError) error).getLine()));
            } else if (error instanceof FactTemplateError) {
                markers.add(new DroolsBuildMarker(error.getMessage(), ((FactTemplateError) error).getLine()));
            } else if (error instanceof ImportError) {
                markers.add(new DroolsBuildMarker("ImportError: " + error.getMessage()));
            } else if (error instanceof DescrBuildError) {
                markers.add(new DroolsBuildMarker("BuildError: " + error.getMessage(), ((DescrBuildError) error).getLine()));
            } else {
                markers.add(new DroolsBuildMarker("Unknown DroolsError " + error.getClass() + ": " + error));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.drools.compiler.DroolsError

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.