Search in sources :

Example 6 with ExistsDescr

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

the class ExistsHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final ExistsDescr existsDescr = new ExistsDescr();
    return existsDescr;
}
Also used : ExistsDescr(org.drools.compiler.lang.descr.ExistsDescr)

Example 7 with ExistsDescr

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

the class ExistsHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final ExistsDescr existsDescr = (ExistsDescr) parser.getCurrent();
    if ((existsDescr.getDescrs().size() != 1) && (existsDescr.getDescrs().get(0).getClass() != PatternDescr.class)) {
        throw new SAXParseException("<exists> can only have a single <pattern...> as a child element", parser.getLocator());
    }
    final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parser.getParent();
    parentDescr.addDescr(existsDescr);
    return existsDescr;
}
Also used : ExistsDescr(org.drools.compiler.lang.descr.ExistsDescr) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) ConditionalElementDescr(org.drools.compiler.lang.descr.ConditionalElementDescr)

Example 8 with ExistsDescr

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

the class RuleParserTest method testPluggableOperators2.

@Test
public void testPluggableOperators2() throws Exception {
    final String text = "rule \"tt\"\n" + "    dialect \"mvel\"\n" + "when\n" + "    exists (TelephoneCall( this finishes [1m] \"25-May-2011\" ))\n" + "then\n" + "end";
    PatternDescr pattern = (PatternDescr) ((ExistsDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0)).getDescrs().get(0);
    assertEquals("TelephoneCall", pattern.getObjectType());
    ExprConstraintDescr constr = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
    assertEquals("this finishes [1m] \"25-May-2011\"", constr.getText());
}
Also used : ExistsDescr(org.drools.compiler.lang.descr.ExistsDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Aggregations

ExistsDescr (org.drools.compiler.lang.descr.ExistsDescr)8 Test (org.junit.Test)4 NotDescr (org.drools.compiler.lang.descr.NotDescr)3 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)3 ConditionalElementDescr (org.drools.compiler.lang.descr.ConditionalElementDescr)2 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)2 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)2 InputStreamReader (java.io.InputStreamReader)1 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)1 CEDescrBuilder (org.drools.compiler.lang.api.CEDescrBuilder)1 AndDescr (org.drools.compiler.lang.descr.AndDescr)1 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)1 OrDescr (org.drools.compiler.lang.descr.OrDescr)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)1 GroupElement (org.drools.core.rule.GroupElement)1 Pattern (org.drools.core.rule.Pattern)1 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)1 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)1 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)1