use of org.apache.nifi.record.path.paths.RootPath in project nifi by apache.
the class RecordPath method compile.
/**
* Compiles a RecordPath from the given text
*
* @param path the textual representation of the RecordPath
* @return the compiled RecordPath
* @throws RecordPathException if the given text is not a valid RecordPath
*/
public static RecordPath compile(final String path) throws RecordPathException {
try {
final CharStream input = new ANTLRStringStream(path);
final RecordPathLexer lexer = new RecordPathLexer(input);
final CommonTokenStream lexerTokenStream = new CommonTokenStream(lexer);
final RecordPathParser parser = new RecordPathParser(lexerTokenStream);
final Tree tree = (Tree) parser.pathExpression().getTree();
// We look at the first child, because 'tree' is a PATH_EXPRESSION and we really
// want the underlying PATH token.
final Tree firstChild = tree.getChild(0);
final int childType = firstChild.getType();
final boolean absolute;
final RecordPathSegment rootPath;
if (childType == PATH || childType == CHILD_REFERENCE) {
rootPath = new RootPath();
absolute = true;
} else {
rootPath = null;
absolute = false;
}
return RecordPathCompiler.compile(firstChild, rootPath, absolute);
} catch (final RecordPathException e) {
throw e;
} catch (final Exception e) {
throw new RecordPathException(e);
}
}
Aggregations