Search in sources :

Example 96 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class FieldBindingHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final BindingDescr fieldBindingDescr = (BindingDescr) parser.getCurrent();
    final PatternDescr patternDescr = (PatternDescr) parser.getParent();
    patternDescr.addConstraint(fieldBindingDescr);
    return fieldBindingDescr;
}
Also used : BindingDescr(org.drools.drl.ast.descr.BindingDescr) PatternDescr(org.drools.drl.ast.descr.PatternDescr) Element(org.w3c.dom.Element)

Example 97 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class RestrictionConnectiveHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Object op = parser.getParent();
    ConnectiveDescr c = (ConnectiveDescr) parser.getCurrent();
    if (op instanceof PatternDescr) {
        StringBuilder sb = new StringBuilder();
        c.buildExpression(sb);
        ExprConstraintDescr expr = new ExprConstraintDescr();
        expr.setExpression(sb.toString());
        final PatternDescr patternDescr = (PatternDescr) op;
        patternDescr.addConstraint(expr);
    } else {
        ConnectiveDescr p = (ConnectiveDescr) op;
        p.add(c);
    }
    return c;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) Element(org.w3c.dom.Element) ConnectiveDescr(org.drools.drl.ast.descr.ConnectiveDescr) RestrictionConnectiveDescr(org.drools.drl.ast.descr.RestrictionConnectiveDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr)

Example 98 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class PredicateHandler 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();
    if (expression == null || expression.trim().equals("")) {
        throw new SAXParseException("<predicate> must have some content", parser.getLocator());
    }
    final PatternDescr patternDescr = (PatternDescr) parser.getParent();
    ExprConstraintDescr expr = new ExprConstraintDescr("eval(" + expression + ")");
    patternDescr.addConstraint(expr);
    return expr;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr)

Example 99 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class AccumulateHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final AccumulateDescr accumulateDescr = (AccumulateDescr) parser.getCurrent();
    final Object parent = parser.getParent();
    if (parent.getClass().getName().equals(FromDescr.class.getName())) {
        final PatternDescr result = (PatternDescr) parser.getParent(1);
        result.setSource(accumulateDescr);
    } else if (parent instanceof ConditionalElementDescr) {
        final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent;
        parentDescr.addDescr(accumulateDescr);
    }
    return accumulateDescr;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) Element(org.w3c.dom.Element) FromDescr(org.drools.drl.ast.descr.FromDescr) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 100 with PatternDescr

use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.

the class NamedConsequenceVisitor method visit.

public void visit(ConditionalBranchDescr desc) {
    PatternDescr patternRelated = desc.getReferringPatternDescr(context.getParentDescr());
    if (patternRelated == null) {
        context.addCompilationError(new InvalidExpressionErrorResult("Related pattern cannot be found for " + desc));
        return;
    }
    Class<?> patternRelatedClass = getClassFromContext(context.getTypeResolver(), patternRelated.getObjectType());
    MethodCallExpr whenBlock = whenThenDSL(desc, patternRelated, patternRelatedClass, WHEN_CALL, null);
    recurseAmongElseBranch(patternRelatedClass, patternRelated, whenBlock, desc.getElseBranch());
}
Also used : InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) PatternDescr(org.drools.drl.ast.descr.PatternDescr) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

PatternDescr (org.drools.drl.ast.descr.PatternDescr)162 Test (org.junit.Test)131 RuleDescr (org.drools.drl.ast.descr.RuleDescr)103 PackageDescr (org.drools.drl.ast.descr.PackageDescr)84 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)65 AndDescr (org.drools.drl.ast.descr.AndDescr)61 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)18 AccumulateDescr (org.drools.drl.ast.descr.AccumulateDescr)18 FromDescr (org.drools.drl.ast.descr.FromDescr)16 BaseDescr (org.drools.drl.ast.descr.BaseDescr)15 NotDescr (org.drools.drl.ast.descr.NotDescr)14 Cheese (org.drools.mvel.compiler.Cheese)14 OrDescr (org.drools.drl.ast.descr.OrDescr)13 BindingDescr (org.drools.drl.ast.descr.BindingDescr)11 Element (org.w3c.dom.Element)9 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)8 InputStreamReader (java.io.InputStreamReader)7 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)7 GlobalDescr (org.drools.drl.ast.descr.GlobalDescr)7 MVELExprDescr (org.drools.drl.ast.descr.MVELExprDescr)7