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());
}
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());
}
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;
}
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;
}
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;
}
Aggregations