Package org.drools.core.rule

Examples of org.drools.core.rule.Rule


            }
        }
    }

    public void buildMetaAttributes(final RuleBuildContext context ) {
        Rule rule = context.getRule();
        for ( String metaAttr : context.getRuleDescr().getAnnotationNames() ) {
            AnnotationDescr ad = context.getRuleDescr().getAnnotation( metaAttr );
            if ( ad.hasValue() ) {
                if ( ad.getValues().size() == 1 ) {
                    rule.addMetaAttribute( metaAttr,
                                           resolveValue( ad.getSingleValue() ) );
                } else {
                    rule.addMetaAttribute( metaAttr,
                                           ad.getValueMap() );
                }
            } else {
                rule.addMetaAttribute( metaAttr,
                                       null );
            }
        }
    }
View Full Code Here


        }
        return result;
    }

    public void buildAttributes(final RuleBuildContext context) {
        final Rule rule = context.getRule();
        final RuleDescr ruleDescr = context.getRuleDescr();
        boolean enforceEager = false;

        for ( final AttributeDescr attributeDescr : ruleDescr.getAttributes().values() ) {
            final String name = attributeDescr.getName();
            if ( name.equals( "no-loop" ) ) {
                rule.setNoLoop( getBooleanValue( attributeDescr,
                                                 true ) );
                enforceEager = true;
            } else if ( name.equals( "auto-focus" ) ) {
                rule.setAutoFocus( getBooleanValue( attributeDescr,
                                                    true ) );
            } else if ( name.equals( "agenda-group" ) ) {
                if ( StringUtils.isEmpty(rule.getRuleFlowGroup())) {
                    rule.setAgendaGroup( attributeDescr.getValue() ); // don't override if RFG has already set this
                }
            } else if ( name.equals( "activation-group" ) ) {
                rule.setActivationGroup( attributeDescr.getValue() );
            } else if ( name.equals( "ruleflow-group" ) ) {
                rule.setRuleFlowGroup( attributeDescr.getValue() );
                rule.setAgendaGroup( attributeDescr.getValue() ); // assign AG to the same name as AG, as they are aliased to AGs anyway
            } else if ( name.equals( "lock-on-active" ) ) {
                boolean lockOnActive = getBooleanValue( attributeDescr, true );
                rule.setLockOnActive( lockOnActive );
                enforceEager |= lockOnActive;
            } else if ( name.equals( DroolsSoftKeywords.DURATION ) || name.equals( DroolsSoftKeywords.TIMER ) ) {
                String duration = attributeDescr.getValue();
                buildTimer( rule, duration, context);
            else if ( name.equals( "calendars" ) ) {
                buildCalendars( rule, attributeDescr.getValue(), context );
            } else if ( name.equals( "date-effective" ) ) {
                try {
                    Date date = DateUtils.parseDate( attributeDescr.getValue(),
                                                     context.getPackageBuilder().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.getPackageBuilder().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  );
                }
            }
        }

        buildSalience( context );

        buildEnabled( context );
       
        AnnotationDescr ann = ruleDescr.getAnnotation( "activationListener" );
        if ( ann != null && !StringUtils.isEmpty( ann.getSingleValue() ) ) {
            rule.setActivationListener( MVELSafeHelper.getEvaluator().evalToString( ann.getSingleValue() ) );
        }

        ann = ruleDescr.getAnnotation( "Eager" );
        if ( enforceEager || ( ann != null && trueOrDefault( ann.getSingleValue() ) ) ) {
            rule.setEager( true );
        }

        ann = ruleDescr.getAnnotation( "Direct" );
        if ( ann != null && trueOrDefault( ann.getSingleValue() ) ) {
            rule.setActivationListener( "direct" );
        }

        //        buildDuration( context );
    }
View Full Code Here

                this.rule = new Query( ruleDescr.getName() );
            } else {
                this.rule = new AbductiveQuery( ruleDescr.getName(), abductive.getValue( "mode" ) );
            }
        } else {
            this.rule = new Rule(ruleDescr.getName());
        }
        this.rule.setPackage(pkg.getName());
        this.rule.setDialect(ruleDescr.getDialect());
        this.rule.setLoadOrder( ruleDescr.getLoadOrder() );
View Full Code Here

                                        prefixPattern,
                                        (Query) context.getRule() );
            }

            if ( rce == null ) {
                Rule rule = context.getPkg().getRule( patternDescr.getObjectType() );
                if ( rule instanceof Query ) {
                    // it's a query so delegate to the QueryElementBuilder
                    QueryElementBuilder qeBuilder = QueryElementBuilder.getInstance();
                    rce = qeBuilder.build( context,
                                           descr,
View Full Code Here

        for (List<RuleDescr> rds : parents.values()) {
            for (RuleDescr ruleDescr : rds) {
                if (parents.get(ruleDescr.getParentName()) != null
                        && (sorted.containsKey(ruleDescr.getName()) || parents.containsKey(ruleDescr.getName()))) {
                    circularDep = true;
                    results.add(new RuleBuildError(new Rule(ruleDescr.getName()), ruleDescr, null,
                            "Circular dependency in rules hierarchy"));
                    break;
                }
                manageUnresolvedExtension(ruleDescr, sorted.values());
            }
View Full Code Here

        }
        String msg = "Unresolved parent name " + ruleDescr.getParentName();
        if (candidateRules.size() > 0) {
            msg += " >> did you mean any of :" + candidateRules;
        }
        results.add(new RuleBuildError(new Rule(ruleDescr.getName()), ruleDescr, msg,
                "Unable to resolve parent rule, please check that both rules are in the same package"));
    }
View Full Code Here

                        rule.getLine(),
                        rule.getColumn(),
                        packageDescr.getNamespace()));
            }
            if (pkg != null) {
                Rule duplicatedRule = pkg.getRule(name);
                if (duplicatedRule != null) {
                    Resource resource = rule.getResource();
                    Resource duplicatedResource = duplicatedRule.getResource();
                    if (resource == null || duplicatedResource == null || duplicatedResource.getSourcePath() == null ||
                            duplicatedResource.getSourcePath().equals(resource.getSourcePath())) {
                        this.results.add(new DuplicateRule(rule,
                                packageDescr,
                                this.configuration));
View Full Code Here

        for ( List<RuleDescr> rds : parents.values() ) {
            for ( RuleDescr ruleDescr : rds ) {
                if ( parents.get( ruleDescr.getParentName() ) != null
                     && (sorted.containsKey( ruleDescr.getName() ) || parents.containsKey( ruleDescr.getName() )) ) {
                    circularDep = true;
                    results.add( new RuleBuildError( new Rule( ruleDescr.getName() ), ruleDescr, null,
                                                     "Circular dependency in rules hierarchy" ) );
                    break;
                }
                manageUnresolvedExtension( ruleDescr, sorted.values() );
            }
View Full Code Here

        }
        String msg = "Unresolved parent name " + ruleDescr.getParentName();
        if ( candidateRules.size() > 0 ) {
            msg += " >> did you mean any of :" + candidateRules;
        }
        results.add( new RuleBuildError( new Rule( ruleDescr.getName() ), ruleDescr, msg,
                                         "Unable to resolve parent rule, please check that both rules are in the same package" ) );
    }
View Full Code Here

                                                   rule.getLine(),
                                                   rule.getColumn(),
                                                   packageDescr.getNamespace() ) );
            }
            if ( pkg != null ) {
                Rule duplicatedRule = pkg.getRule( name );
                if ( duplicatedRule != null ) {
                    Resource resource = rule.getResource();
                    Resource duplicatedResource = duplicatedRule.getResource();
                    if ( resource == null || duplicatedResource == null || duplicatedResource.getSourcePath() == null ||
                         duplicatedResource.getSourcePath().equals( resource.getSourcePath() ) ) {
                        this.results.add( new DuplicateRule( rule,
                                                             packageDescr,
                                                             this.configuration ) );
View Full Code Here

TOP

Related Classes of org.drools.core.rule.Rule

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.