use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class ExprConstraintHandler 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);
PatternDescr p = (PatternDescr) parser.getParent();
ExprConstraintDescr descr = new ExprConstraintDescr(expression);
p.getConstraint().addDescr(descr);
return descr;
}
use of org.drools.compiler.lang.descr.PatternDescr 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.PatternDescr 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.compiler.lang.descr.PatternDescr 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;
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleBuilderTest method testBuildBigDecimalLiteralConstraint.
@Test
public void testBuildBigDecimalLiteralConstraint() throws Exception {
final PackageDescr pkgDescr = new PackageDescr("org.drools");
final RuleDescr ruleDescr = new RuleDescr("Test Rule");
AndDescr andDescr = new AndDescr();
PatternDescr patDescr = new PatternDescr("java.math.BigDecimal", "$bd");
ExprConstraintDescr fcd = new ExprConstraintDescr("this == 10");
patDescr.addConstraint(fcd);
andDescr.addDescr(patDescr);
ruleDescr.setLhs(andDescr);
ruleDescr.setConsequence("");
pkgDescr.addRule(ruleDescr);
final KnowledgeBuilderImpl kBuilder = new KnowledgeBuilderImpl();
kBuilder.addPackage(pkgDescr);
assertTrue(kBuilder.getErrors().toString(), kBuilder.getErrors().isEmpty());
final RuleImpl rule = kBuilder.getPackages()[0].getRule("Test Rule");
final GroupElement and = rule.getLhs();
final Pattern pat = (Pattern) and.getChildren().get(0);
if (pat.getConstraints().get(0) instanceof MvelConstraint) {
final MvelConstraint fc = (MvelConstraint) pat.getConstraints().get(0);
assertTrue("Wrong class. Expected java.math.BigDecimal. Found: " + fc.getField().getValue().getClass(), fc.getField().getValue() instanceof BigDecimal);
}
}
Aggregations