Search in sources :

Example 36 with BindingDescr

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

the class DRLExprParserTest method testBindingConstraint.

@Test
public void testBindingConstraint() throws Exception {
    String source = "$x : property > value";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(1, result.getDescrs().size());
    RelationalExprDescr rel = (RelationalExprDescr) result.getDescrs().get(0);
    assertEquals(">", rel.getOperator());
    BindingDescr bind = (BindingDescr) rel.getLeft();
    assertEquals("$x", bind.getVariable());
    assertEquals("property", bind.getExpression());
    AtomicExprDescr right = (AtomicExprDescr) rel.getRight();
    assertEquals("value", right.getExpression());
}
Also used : BindingDescr(org.drools.drl.ast.descr.BindingDescr) AtomicExprDescr(org.drools.drl.ast.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.drl.ast.descr.RelationalExprDescr) Test(org.junit.Test)

Example 37 with BindingDescr

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

the class DRLExprParserTest method testBinding.

@Test
public void testBinding() throws Exception {
    String source = "$x : property";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(1, result.getDescrs().size());
    BindingDescr bind = (BindingDescr) result.getDescrs().get(0);
    assertEquals("$x", bind.getVariable());
    assertEquals("property", bind.getExpression());
}
Also used : BindingDescr(org.drools.drl.ast.descr.BindingDescr) ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 38 with BindingDescr

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

the class FieldBindingHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final String identifier = attrs.getValue("identifier");
    final String fieldName = attrs.getValue("field-name");
    emptyAttributeCheck(localName, "identifier", identifier, parser);
    emptyAttributeCheck(localName, "fieldName", fieldName, parser);
    final BindingDescr fieldBindingDescr = new BindingDescr(identifier, fieldName);
    return fieldBindingDescr;
}
Also used : BindingDescr(org.drools.drl.ast.descr.BindingDescr)

Example 39 with BindingDescr

use of org.drools.drl.ast.descr.BindingDescr 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 40 with BindingDescr

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

the class PatternBuilder method createDeclarationObject.

protected static Declaration createDeclarationObject(final RuleBuildContext context, final String identifier, final String expr, final Pattern pattern) {
    final BindingDescr implicitBinding = new BindingDescr(identifier, expr);
    final Declaration declaration = new Declaration(identifier, null, pattern, true);
    InternalReadAccessor extractor = getFieldReadAccessor(context, implicitBinding, pattern, implicitBinding.getExpression(), declaration, false);
    if (extractor == null) {
        return null;
    }
    declaration.setReadAccessor(extractor);
    return declaration;
}
Also used : BindingDescr(org.drools.drl.ast.descr.BindingDescr) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) TypeDeclaration(org.drools.core.rule.TypeDeclaration) Declaration(org.drools.core.rule.Declaration)

Aggregations

BindingDescr (org.drools.drl.ast.descr.BindingDescr)42 ConstraintConnectiveDescr (org.drools.drl.ast.descr.ConstraintConnectiveDescr)17 Test (org.junit.Test)17 BaseDescr (org.drools.drl.ast.descr.BaseDescr)13 PatternDescr (org.drools.drl.ast.descr.PatternDescr)11 RuleDescr (org.drools.drl.ast.descr.RuleDescr)11 AtomicExprDescr (org.drools.drl.ast.descr.AtomicExprDescr)10 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)10 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)9 AndDescr (org.drools.drl.ast.descr.AndDescr)8 Cheese (org.drools.mvel.compiler.Cheese)8 PackageDescr (org.drools.drl.ast.descr.PackageDescr)7 RelationalExprDescr (org.drools.drl.ast.descr.RelationalExprDescr)7 DumperContext (org.drools.compiler.lang.DumperContext)6 GlobalDescr (org.drools.drl.ast.descr.GlobalDescr)6 ClassObjectType (org.drools.core.base.ClassObjectType)5 Declaration (org.drools.core.rule.Declaration)5 TypeDeclaration (org.drools.core.rule.TypeDeclaration)5 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 PredicateConstraint (org.drools.core.rule.PredicateConstraint)4