Search in sources :

Example 1 with ConditionalElementDescr

use of org.drools.drl.ast.descr.ConditionalElementDescr in project drools by kiegroup.

the class FromHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final FromDescr fromDescr = (FromDescr) parser.getCurrent();
    Object parent = parser.getParent();
    final PatternDescr patternDescr = (PatternDescr) parent;
    final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parser.getParent(1);
    if (element.getElementsByTagName("expression").getLength() > 0) {
        patternDescr.setSource(fromDescr);
    }
    return fromDescr;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) Element(org.w3c.dom.Element) FromDescr(org.drools.drl.ast.descr.FromDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 2 with ConditionalElementDescr

use of org.drools.drl.ast.descr.ConditionalElementDescr in project drools by kiegroup.

the class CollectHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final CollectDescr collectDescr = (CollectDescr) parser.getCurrent();
    final Object parent = parser.getParent();
    if (parent.getClass().getName().equals(FromDescr.class.getName())) {
        final PatternDescr resultPattern = (PatternDescr) parser.getParent(1);
        resultPattern.setSource(collectDescr);
    } else if (parent instanceof ConditionalElementDescr) {
        final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent;
        parentDescr.addDescr(collectDescr);
    }
    return collectDescr;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) CollectDescr(org.drools.drl.ast.descr.CollectDescr) Element(org.w3c.dom.Element) FromDescr(org.drools.drl.ast.descr.FromDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 3 with ConditionalElementDescr

use of org.drools.drl.ast.descr.ConditionalElementDescr in project drools by kiegroup.

the class GroupElementBuilder method build.

public RuleConditionElement build(final RuleBuildContext context, final BaseDescr descr, final Pattern prefixPattern) {
    final ConditionalElementDescr cedescr = (ConditionalElementDescr) descr;
    final GroupElement ge = this.newGroupElementFor(descr);
    context.getDeclarationResolver().pushOnBuildStack(ge);
    if (prefixPattern != null) {
        ge.addChild(prefixPattern);
    }
    // iterate over child descriptors
    for (final BaseDescr child : cedescr.getDescrs()) {
        // gets child to build
        // child.setResource(..) does not seem to be necessary (since builderImpls have already set the resource for all children)
        // but leaving it in here to be save
        child.setResource(context.getRuleDescr().getResource());
        child.setNamespace(context.getRuleDescr().getNamespace());
        // gets corresponding builder
        final RuleConditionBuilder builder = (RuleConditionBuilder) context.getDialect().getBuilder(child.getClass());
        if (builder != null) {
            final RuleConditionElement element = builder.build(context, child);
            // builder will return null. Ex: ClassNotFound for the pattern type
            if (element != null) {
                ge.addChild(element);
            }
        } else {
            throw new RuntimeException("BUG: no builder found for descriptor class " + child.getClass());
        }
    }
    context.getDeclarationResolver().popBuildStack();
    return ge;
}
Also used : GroupElement(org.drools.core.rule.GroupElement) BaseDescr(org.drools.drl.ast.descr.BaseDescr) RuleConditionElement(org.drools.core.rule.RuleConditionElement) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 4 with ConditionalElementDescr

use of org.drools.drl.ast.descr.ConditionalElementDescr in project drools by kiegroup.

the class CEDescrBuilderImpl method and.

/**
 * {@inheritDoc}
 */
public CEDescrBuilder<CEDescrBuilder<P, T>, AndDescr> and() {
    AndDescr andDescr = new AndDescr();
    ((ConditionalElementDescr) descr).addDescr(andDescr);
    return new CEDescrBuilderImpl<CEDescrBuilder<P, T>, AndDescr>(this, andDescr);
}
Also used : AndDescr(org.drools.drl.ast.descr.AndDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 5 with ConditionalElementDescr

use of org.drools.drl.ast.descr.ConditionalElementDescr in project drools by kiegroup.

the class CEDescrBuilderImpl method not.

/**
 * {@inheritDoc}
 */
public CEDescrBuilder<CEDescrBuilder<P, T>, NotDescr> not() {
    CEDescrBuilder<CEDescrBuilder<P, T>, NotDescr> not = new CEDescrBuilderImpl<CEDescrBuilder<P, T>, NotDescr>(this, new NotDescr());
    ((ConditionalElementDescr) descr).addDescr(not.getDescr());
    return not;
}
Also used : NotDescr(org.drools.drl.ast.descr.NotDescr) CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Aggregations

ConditionalElementDescr (org.drools.drl.ast.descr.ConditionalElementDescr)30 BaseDescr (org.drools.drl.ast.descr.BaseDescr)16 AndDescr (org.drools.drl.ast.descr.AndDescr)11 Element (org.w3c.dom.Element)10 AnnotatedBaseDescr (org.drools.drl.ast.descr.AnnotatedBaseDescr)5 CEDescrBuilder (org.drools.drl.ast.dsl.CEDescrBuilder)5 OrDescr (org.drools.drl.ast.descr.OrDescr)4 FromDescr (org.drools.drl.ast.descr.FromDescr)3 PatternDescr (org.drools.drl.ast.descr.PatternDescr)3 AccumulateDescrBuilder (org.drools.drl.ast.dsl.AccumulateDescrBuilder)3 AnnotatedDescrBuilder (org.drools.drl.ast.dsl.AnnotatedDescrBuilder)3 AnnotationDescrBuilder (org.drools.drl.ast.dsl.AnnotationDescrBuilder)3 AttributeDescrBuilder (org.drools.drl.ast.dsl.AttributeDescrBuilder)3 BehaviorDescrBuilder (org.drools.drl.ast.dsl.BehaviorDescrBuilder)3 CollectDescrBuilder (org.drools.drl.ast.dsl.CollectDescrBuilder)3 ConditionalBranchDescrBuilder (org.drools.drl.ast.dsl.ConditionalBranchDescrBuilder)3 DeclareDescrBuilder (org.drools.drl.ast.dsl.DeclareDescrBuilder)3 DescrBuilder (org.drools.drl.ast.dsl.DescrBuilder)3 EntryPointDeclarationDescrBuilder (org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder)3 EnumDeclarationDescrBuilder (org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder)3