use of org.drools.compiler.rule.builder.XpathAnalysis.XpathPart 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);
}
}
Aggregations