use of org.drools.compiler.lang.descr.MVELExprDescr 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;
}
use of org.drools.compiler.lang.descr.MVELExprDescr in project drools by kiegroup.
the class RuleParserTest method testSimpleMethodCallWithFrom.
@Test
public void testSimpleMethodCallWithFrom() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "test_SimpleMethodCallWithFrom.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final FromDescr from = (FromDescr) pattern.getSource();
final MVELExprDescr method = (MVELExprDescr) from.getDataSource();
assertEquals("something.doIt( foo,bar,42,\"hello\",[ a : \"b\", \"something\" : 42, \"a\" : foo, x : [x:y]],\"end\", [a, \"b\", 42] )", method.getExpression());
}
use of org.drools.compiler.lang.descr.MVELExprDescr in project drools by kiegroup.
the class PatternBuilder method lookupObjectType.
private void lookupObjectType(RuleBuildContext context, PatternDescr patternDescr) {
List<? extends BaseDescr> descrs = patternDescr.getConstraint().getDescrs();
if (descrs.size() != 1 || !(descrs.get(0) instanceof ExprConstraintDescr)) {
return;
}
ExprConstraintDescr descr = (ExprConstraintDescr) descrs.get(0);
String expr = descr.getExpression();
if (expr.charAt(0) != '/') {
return;
}
XpathAnalysis xpathAnalysis = XpathAnalysis.analyze(expr);
if (xpathAnalysis.hasError()) {
registerDescrBuildError(context, patternDescr, "Invalid xpath expression '" + expr + "': " + xpathAnalysis.getError());
return;
}
XpathPart firstXpathChunk = xpathAnalysis.getPart(0);
String identifier = firstXpathChunk.getField();
DeclarationScopeResolver resolver = context.getDeclarationResolver();
if (resolver.hasDataSource(identifier)) {
patternDescr.setObjectType(findObjectType(context, firstXpathChunk, identifier));
FromDescr fromDescr = new FromDescr();
fromDescr.setDataSource(new MVELExprDescr(identifier));
patternDescr.setSource(fromDescr);
patternDescr.removeAllConstraint();
firstXpathChunk.getConstraints().forEach(s -> patternDescr.addConstraint(new ExprConstraintDescr(s)));
if (!xpathAnalysis.isSinglePart()) {
patternDescr.addConstraint(new ExprConstraintDescr(patternDescr.getIdentifier() + " : " + expr.substring(xpathAnalysis.getPart(1).getStart())));
patternDescr.setIdentifier("$void$");
}
} else {
Declaration declr = resolver.getDeclaration(identifier);
patternDescr.setXpathStartDeclaration(declr);
patternDescr.setObjectType(declr.getExtractor().getExtractToClassName());
expr = patternDescr.getIdentifier() + (patternDescr.isUnification() ? " := " : " : ") + expr.substring(identifier.length() + 1);
descr.setExpression(expr);
}
}
use of org.drools.compiler.lang.descr.MVELExprDescr in project drools by kiegroup.
the class XmlPackageReaderTest method testParseFrom.
@Test
public void testParseFrom() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseFrom.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
assertNotNull(packageDescr);
RuleDescr obj = (RuleDescr) packageDescr.getRules().get(0);
PatternDescr patterndescr = (PatternDescr) obj.getLhs().getDescrs().get(0);
FromDescr from = (FromDescr) patterndescr.getSource();
MVELExprDescr accessordescriptor = (MVELExprDescr) from.getDataSource();
assertEquals("cheesery.getCheeses(i+4)", accessordescriptor.getExpression());
assertEquals(patterndescr.getObjectType(), "Cheese");
assertEquals(patterndescr.getIdentifier(), "cheese");
}
use of org.drools.compiler.lang.descr.MVELExprDescr in project drools by kiegroup.
the class SourceDescrBuilderImpl method expression.
public P expression(String expression) {
FromDescr from = new FromDescr();
from.setDataSource(new MVELExprDescr(expression));
from.setResource(descr.getResource());
descr.setSource(from);
return parent;
}
Aggregations