use of org.drools.drl.ast.descr.ConnectiveDescr in project drools by kiegroup.
the class FieldConstraintHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final ConnectiveDescr c = (ConnectiveDescr) parser.getCurrent();
Object p = parser.getParent();
if (p instanceof PatternDescr) {
StringBuilder sb = new StringBuilder();
c.buildExpression(sb);
ExprConstraintDescr expr = new ExprConstraintDescr();
expr.setExpression(sb.toString());
final PatternDescr patternDescr = (PatternDescr) parser.getParent();
patternDescr.addConstraint(expr);
} else if (p instanceof ConnectiveDescr) {
((ConnectiveDescr) p).add(c);
}
return c;
}
use of org.drools.drl.ast.descr.ConnectiveDescr in project drools by kiegroup.
the class ReturnValueRestrictionHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final String expression = ((org.w3c.dom.Text) element.getChildNodes().item(0)).getWholeText();
emptyContentCheck(localName, expression, parser);
ConnectiveDescr c = (ConnectiveDescr) parser.getParent();
String s = ((String) parser.getCurrent()) + "(" + expression + ")";
c.add(s);
return null;
}
use of org.drools.drl.ast.descr.ConnectiveDescr in project drools by kiegroup.
the class LiteralRestrictionHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
ConnectiveDescr c = (ConnectiveDescr) parser.getParent();
String s = (String) parser.getCurrent();
c.add(s);
return null;
}
use of org.drools.drl.ast.descr.ConnectiveDescr in project drools by kiegroup.
the class QualifiedIdentifierRestrictionHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final String expression = ((org.w3c.dom.Text) element.getChildNodes().item(0)).getWholeText();
emptyContentCheck(localName, expression, parser);
ConnectiveDescr c = (ConnectiveDescr) parser.getParent();
String s = ((String) parser.getCurrent()) + expression;
c.add(s);
return null;
}
use of org.drools.drl.ast.descr.ConnectiveDescr in project drools by kiegroup.
the class ConnectiveDescrTest method testBuildExpression.
@Test
public void testBuildExpression() {
ConnectiveDescr descr1 = new ConnectiveDescr(RestrictionConnectiveType.OR);
descr1.setPrefix("name");
descr1.add("== 'darth'");
descr1.add("== 'bobba'");
StringBuilder sb = new StringBuilder();
descr1.buildExpression(sb);
Assertions.assertThat("name == 'darth' || == 'bobba'").isEqualToIgnoringWhitespace(sb.toString());
ConnectiveDescr descr2 = new ConnectiveDescr(RestrictionConnectiveType.AND);
descr2.setPrefix("name");
descr2.add("!= 'luke'");
sb = new StringBuilder();
descr2.buildExpression(sb);
Assertions.assertThat("name != 'luke'").isEqualToIgnoringWhitespace(sb.toString());
descr2.add("!= 'yoda'");
ConnectiveDescr descr3 = new ConnectiveDescr(RestrictionConnectiveType.AND);
descr3.add(descr1);
descr3.add(descr2);
sb = new StringBuilder();
descr3.buildExpression(sb);
Assertions.assertThat("(name == 'darth' || == 'bobba') && (name != 'luke' && != 'yoda')").isEqualToIgnoringWhitespace(sb.toString());
ConnectiveDescr descr4 = new ConnectiveDescr(RestrictionConnectiveType.AND);
descr4.setPrefix("age");
descr4.add("!= 33");
descr4.add("!= 34");
ConnectiveDescr descr5 = new ConnectiveDescr(RestrictionConnectiveType.OR);
descr5.add(descr3);
descr5.add(descr4);
sb = new StringBuilder();
descr5.buildExpression(sb);
Assertions.assertThat("((name == 'darth' || == 'bobba') && (name != 'luke' && != 'yoda')) || (age != 33 && != 34)").isEqualToIgnoringWhitespace(sb.toString());
}
Aggregations