Search in sources :

Example 1 with CollectDescr

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

the class CollectBuilder method build.

public RuleConditionElement build(final RuleBuildContext context, final BaseDescr descr, final Pattern prefixPattern) {
    final CollectDescr collectDescr = (CollectDescr) descr;
    final PatternBuilder patternBuilder = (PatternBuilder) context.getDialect().getBuilder(PatternDescr.class);
    final Pattern sourcePattern = (Pattern) patternBuilder.build(context, collectDescr.getInputPattern());
    if (sourcePattern == null) {
        return null;
    }
    final String className = "collect" + context.getNextId();
    collectDescr.setClassMethodName(className);
    Pattern resultPattern = (Pattern) context.getDeclarationResolver().peekBuildStack();
    return new Collect(sourcePattern, resultPattern);
}
Also used : Pattern(org.drools.core.rule.Pattern) PatternDescr(org.drools.drl.ast.descr.PatternDescr) CollectDescr(org.drools.drl.ast.descr.CollectDescr) Collect(org.drools.core.rule.Collect)

Example 2 with CollectDescr

use of org.drools.drl.ast.descr.CollectDescr 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 CollectDescr

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

the class CollectHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final CollectDescr collectDescr = new CollectDescr();
    return collectDescr;
}
Also used : CollectDescr(org.drools.drl.ast.descr.CollectDescr)

Example 4 with CollectDescr

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

the class RuleParserTest method testAccumulateWithNestedFrom.

@Test
public void testAccumulateWithNestedFrom() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulate_with_nested_from.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final AccumulateDescr accumulate = (AccumulateDescr) out.getSource();
    PatternDescr person = (PatternDescr) accumulate.getInputPattern();
    assertEquals("Person", person.getObjectType());
    final CollectDescr collect2 = (CollectDescr) person.getSource();
    final PatternDescr people = collect2.getInputPattern();
    assertEquals("People", people.getObjectType());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) CollectDescr(org.drools.drl.ast.descr.CollectDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) Test(org.junit.Test)

Example 5 with CollectDescr

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

the class RuleParserTest method testCollectWithNestedFrom.

@Test
public void testCollectWithNestedFrom() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "collect_with_nested_from.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final CollectDescr collect = (CollectDescr) out.getSource();
    PatternDescr person = (PatternDescr) collect.getInputPattern();
    assertEquals("Person", person.getObjectType());
    final CollectDescr collect2 = (CollectDescr) person.getSource();
    final PatternDescr people = collect2.getInputPattern();
    assertEquals("People", people.getObjectType());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) CollectDescr(org.drools.drl.ast.descr.CollectDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Aggregations

CollectDescr (org.drools.drl.ast.descr.CollectDescr)6 PatternDescr (org.drools.drl.ast.descr.PatternDescr)5 PackageDescr (org.drools.drl.ast.descr.PackageDescr)3 RuleDescr (org.drools.drl.ast.descr.RuleDescr)3 Test (org.junit.Test)3 Collect (org.drools.core.rule.Collect)1 Pattern (org.drools.core.rule.Pattern)1 AccumulateDescr (org.drools.drl.ast.descr.AccumulateDescr)1 ConditionalElementDescr (org.drools.drl.ast.descr.ConditionalElementDescr)1 FromDescr (org.drools.drl.ast.descr.FromDescr)1 Element (org.w3c.dom.Element)1