Search in sources :

Example 1 with ConditionalBranchDescr

use of org.drools.compiler.lang.descr.ConditionalBranchDescr in project drools by kiegroup.

the class ConditionalBranchBuilder method build.

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;
    }
    RuleConditionBuilder evalBuilder = (RuleConditionBuilder) context.getDialect().getBuilder(EvalDescr.class);
    EvalCondition condition = (EvalCondition) evalBuilder.build(context, conditionalBranch.getCondition(), getLastPattern(context));
    NamedConsequenceBuilder namedConsequenceBuilder = (NamedConsequenceBuilder) context.getDialect().getBuilder(NamedConsequenceDescr.class);
    NamedConsequence consequence = namedConsequenceBuilder.build(context, conditionalBranch.getConsequence());
    ConditionalBranchDescr elseBranchDescr = conditionalBranch.getElseBranch();
    return new ConditionalBranch(condition, consequence, elseBranchDescr != null ? build(context, elseBranchDescr, prefixPattern) : null);
}
Also used : DroolsError(org.drools.compiler.compiler.DroolsError) NamedConsequenceDescr(org.drools.compiler.lang.descr.NamedConsequenceDescr) ConditionalBranchDescr(org.drools.compiler.lang.descr.ConditionalBranchDescr) RuleBuildError(org.drools.compiler.compiler.RuleBuildError) EvalDescr(org.drools.compiler.lang.descr.EvalDescr) ConditionalBranch(org.drools.core.rule.ConditionalBranch) EvalCondition(org.drools.core.rule.EvalCondition) NamedConsequence(org.drools.core.rule.NamedConsequence)

Example 2 with ConditionalBranchDescr

use of org.drools.compiler.lang.descr.ConditionalBranchDescr in project kie-wb-common by kiegroup.

the class PackageDescrIndexVisitor method visit.

protected void visit(final ConditionalBranchDescr descr) {
    visit(descr.getCondition());
    visit(descr.getConsequence());
    ConditionalBranchDescr elseBranch = descr.getElseBranch();
    if (elseBranch != null) {
        visit(elseBranch);
    }
}
Also used : ConditionalBranchDescr(org.drools.compiler.lang.descr.ConditionalBranchDescr)

Aggregations

ConditionalBranchDescr (org.drools.compiler.lang.descr.ConditionalBranchDescr)2 DroolsError (org.drools.compiler.compiler.DroolsError)1 RuleBuildError (org.drools.compiler.compiler.RuleBuildError)1 EvalDescr (org.drools.compiler.lang.descr.EvalDescr)1 NamedConsequenceDescr (org.drools.compiler.lang.descr.NamedConsequenceDescr)1 ConditionalBranch (org.drools.core.rule.ConditionalBranch)1 EvalCondition (org.drools.core.rule.EvalCondition)1 NamedConsequence (org.drools.core.rule.NamedConsequence)1