use of org.drools.compiler.lang.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;
}
use of org.drools.compiler.lang.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;
}
use of org.drools.compiler.lang.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());
}
use of org.drools.compiler.lang.descr.CollectDescr in project drools by kiegroup.
the class RuleParserTest method testCollect.
@Test
public void testCollect() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "collect.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final CollectDescr collect = (CollectDescr) outPattern.getSource();
final PatternDescr pattern = (PatternDescr) collect.getInputPattern();
assertEquals("Person", pattern.getObjectType());
}
use of org.drools.compiler.lang.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);
}
Aggregations