Search in sources :

Example 6 with FromDescr

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

the class RuleParserTest method testSimpleFunctionCallWithFrom.

@Test
public void testSimpleFunctionCallWithFrom() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "test_SimpleFunctionCallWithFrom.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final FromDescr from = (FromDescr) pattern.getSource();
    final MVELExprDescr func = (MVELExprDescr) from.getDataSource();
    assertEquals("doIt( foo,bar,42,\"hello\",[ a : \"b\", \"something\" : 42, \"a\" : foo, x : [x:y]],\"end\", [a, \"b\", 42] )", func.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) FromDescr(org.drools.drl.ast.descr.FromDescr) MVELExprDescr(org.drools.drl.ast.descr.MVELExprDescr) Test(org.junit.Test)

Example 7 with FromDescr

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

the class RuleParserTest method testSimpleAccessorAndArgWithFrom.

@Test
public void testSimpleAccessorAndArgWithFrom() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "test_SimpleAccessorArgWithFrom.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final FromDescr from = (FromDescr) pattern.getSource();
    final MVELExprDescr accessor = (MVELExprDescr) from.getDataSource();
    assertEquals("something.doIt[\"key\"]", accessor.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) FromDescr(org.drools.drl.ast.descr.FromDescr) MVELExprDescr(org.drools.drl.ast.descr.MVELExprDescr) Test(org.junit.Test)

Example 8 with FromDescr

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

the class ExpressionHandler 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);
    FromDescr parent = (FromDescr) parser.getParent();
    parent.setDataSource(new MVELExprDescr(expression.trim()));
    return null;
}
Also used : Element(org.w3c.dom.Element) FromDescr(org.drools.drl.ast.descr.FromDescr) MVELExprDescr(org.drools.drl.ast.descr.MVELExprDescr)

Example 9 with FromDescr

use of org.drools.drl.ast.descr.FromDescr 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.drl.ast.descr.PatternDescr) Element(org.w3c.dom.Element) FromDescr(org.drools.drl.ast.descr.FromDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 10 with FromDescr

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

the class FromHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final FromDescr fromDesctiptor = new FromDescr();
    return fromDesctiptor;
}
Also used : FromDescr(org.drools.drl.ast.descr.FromDescr)

Aggregations

FromDescr (org.drools.drl.ast.descr.FromDescr)20 PatternDescr (org.drools.drl.ast.descr.PatternDescr)14 RuleDescr (org.drools.drl.ast.descr.RuleDescr)11 Test (org.junit.Test)11 MVELExprDescr (org.drools.drl.ast.descr.MVELExprDescr)10 PackageDescr (org.drools.drl.ast.descr.PackageDescr)6 Declaration (org.drools.core.rule.Declaration)2 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)2 NotDescr (org.drools.drl.ast.descr.NotDescr)2 Element (org.w3c.dom.Element)2 StaticJavaParser.parseStatement (com.github.javaparser.StaticJavaParser.parseStatement)1 Node (com.github.javaparser.ast.Node)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 Statement (com.github.javaparser.ast.stmt.Statement)1 InputStreamReader (java.io.InputStreamReader)1 AnalysisResult (org.drools.compiler.compiler.AnalysisResult)1 BoundIdentifiers (org.drools.compiler.compiler.BoundIdentifiers)1 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)1 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)1 XpathAnalysis (org.drools.compiler.rule.builder.XpathAnalysis)1