Examples of DroolsError


Examples of org.drools.compiler.compiler.DroolsError

                                                     context.getKnowledgeBuilder().getDateFormats()  );
                    final Calendar cal = Calendar.getInstance();
                    cal.setTime( date );
                    rule.setDateEffective( cal );
                } catch (Exception e) {
                    DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                          "Wrong date-effective value: " + e.getMessage() );
                    context.addError( err  );
                }
            } else if ( name.equals( "date-expires" ) ) {
                try {
                    Date date = DateUtils.parseDate( attributeDescr.getValue(),
                                                     context.getKnowledgeBuilder().getDateFormats()  );
                    final Calendar cal = Calendar.getInstance();
                    cal.setTime( date );
                    rule.setDateExpires( cal );
                } catch (Exception e) {
                    DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                          "Wrong date-expires value: " + e.getMessage() );
                    context.addError( err  );
                }
            }
        }
View Full Code Here

Examples of org.drools.compiler.compiler.DroolsError

            }

            rule.setDataDriven(ruleDescr.hasAnnotation(DataDriven.class));
            rule.setAllMatches(ruleDescr.hasAnnotation(All.class));
        } catch (Exception e) {
            DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                  e.getMessage() );
            context.addError( err  );
        }
    }
View Full Code Here

Examples of org.drools.compiler.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

Examples of org.drools.compiler.compiler.DroolsError

        int colonPos = timerString.indexOf( ":" );
        int semicolonPos = timerString.indexOf( ";" );
        String protocol = "int"; // default protocol
        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;
            }
        } else {
            protocol = timerString.substring( 0, colonPos );
        }
       
        String startDate = extractParam(timerString, "start");
        String endDate = extractParam(timerString, "end");
        String repeatLimitString = extractParam(timerString, "repeat-limit");
        int repeatLimit = repeatLimitString != null ? Integer.parseInt( repeatLimitString ) : -1;
       
        String body = timerString.substring( colonPos + 1, semicolonPos > 0 ? semicolonPos : timerString.length() ).trim();
       
        Timer timer;
        if ( "cron".equals( protocol ) ) {
            try {
                timer = new CronTimer( createMVELExpr(startDate, context), createMVELExpr(endDate, context), 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( createMVELExpr(startDate, context), createMVELExpr(endDate, context), 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 = tok.hasMoreTokens() ?
                                          MVELObjectExpressionBuilder.build( tok.nextToken().trim(), context ) :
                                          MVELObjectExpressionBuilder.build( "0", context );

            timer = new ExpressionIntervalTimer( createMVELExpr(startDate, context), createMVELExpr(endDate, context), 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

Examples of org.drools.compiler.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

Examples of org.drools.compiler.compiler.DroolsError

       
        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

Examples of org.drools.compiler.compiler.DroolsError

        if (!errors.isEmpty()) {
            System.err.println("------->ERROR(s) DURING THREAD TEST : <-------------------");
            for (Iterator<PackageBuilderErrors> iterator = errors.iterator(); iterator.hasNext();) {
                PackageBuilderErrors e = iterator.next();
                for (int i = 0; i < e.getErrors().length; i++) {
                    DroolsError de = e.getErrors()[i];
                    errorBuf.append(de.getMessage() + "\n");
                }

            }
        }
View Full Code Here

Examples of org.drools.compiler.compiler.DroolsError

            // KnowledgeBuilder API
            KnowledgePackageImpl kpkg = (KnowledgePackageImpl) object;
            overrideReSource(kpkg, resource);
            addPackage(kpkg);
        } else {
            results.add(new DroolsError(resource) {

                @Override
                public String getMessage() {
                    return "Unknown binary format trying to load resource " + resource.toString();
                }
View Full Code Here

Examples of org.drools.compiler.compiler.DroolsError

                for (Resource removedRes : changeSet.getResourcesRemoved()) {
                    resources.add(removedRes);
                }
                buildResources.push(resources);
            } catch (Exception e) {
                results.add(new DroolsError() {

                    public String getMessage() {
                        return "Unable to register changeset resource " + resource;
                    }
View Full Code Here

Examples of org.drools.compiler.compiler.DroolsError

    public ConditionalBranch build(RuleBuildContext context, BaseDescr descr, Pattern prefixPattern) {
        ConditionalBranchDescr conditionalBranch = (ConditionalBranchDescr) descr;

        String consequenceName = conditionalBranch.getConsequence().getName();
        if ( !context.getRuleDescr().getNamedConsequences().keySet().contains( consequenceName ) ) {
            DroolsError err = new RuleBuildError( context.getRule(), context.getParentDescr(), null,
                                                  "Unknown consequence name: " + consequenceName );
            context.addError( err  );
            return null;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.