Search in sources :

Example 6 with PatternDescr

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;
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) Element(org.w3c.dom.Element) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr)

Example 7 with PatternDescr

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;
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) CollectDescr(org.drools.compiler.lang.descr.CollectDescr) Element(org.w3c.dom.Element) FromDescr(org.drools.compiler.lang.descr.FromDescr) ConditionalElementDescr(org.drools.compiler.lang.descr.ConditionalElementDescr)

Example 8 with PatternDescr

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;
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) Element(org.w3c.dom.Element) ConnectiveDescr(org.drools.compiler.lang.descr.ConnectiveDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr)

Example 9 with PatternDescr

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;
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) Element(org.w3c.dom.Element) FromDescr(org.drools.compiler.lang.descr.FromDescr) ConditionalElementDescr(org.drools.compiler.lang.descr.ConditionalElementDescr)

Example 10 with PatternDescr

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);
    }
}
Also used : Pattern(org.drools.core.rule.Pattern) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) GroupElement(org.drools.core.rule.GroupElement) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) MvelConstraint(org.drools.core.rule.constraint.MvelConstraint) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

PatternDescr (org.drools.compiler.lang.descr.PatternDescr)150 Test (org.junit.Test)122 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)103 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)84 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)56 AndDescr (org.drools.compiler.lang.descr.AndDescr)52 AccumulateDescr (org.drools.compiler.lang.descr.AccumulateDescr)19 Cheese (org.drools.compiler.Cheese)14 FromDescr (org.drools.compiler.lang.descr.FromDescr)14 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)11 NotDescr (org.drools.compiler.lang.descr.NotDescr)11 OrDescr (org.drools.compiler.lang.descr.OrDescr)11 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)11 Element (org.w3c.dom.Element)9 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)8 InputStreamReader (java.io.InputStreamReader)7 List (java.util.List)7 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)7 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)7