return data;
}
public Object visit(ASTQuery node, Object data) {
root = new QueryRootNode();
root.setLocationNode(new PathQueryNode(root));
// pass to select, from, where, ...
node.childrenAccept(this, root);
// use //* if no path has been set
PathQueryNode pathNode = root.getLocationNode();
pathNode.setAbsolute(true);
if (pathConstraints.size() == 0) {
pathNode.addPathStep(new LocationStepQueryNode(pathNode, null, true));
} else {
try {
while (pathConstraints.size() > 1) {
// merge path nodes
MergingPathQueryNode path = null;
for (Iterator it = pathConstraints.iterator(); it.hasNext();) {
path = (MergingPathQueryNode) it.next();
if (path.needsMerge()) {
break;
} else {
path = null;
}
}
if (path == null) {
throw new IllegalArgumentException("Invalid combination of jcr:path clauses");
} else {
pathConstraints.remove(path);
MergingPathQueryNode[] paths = (MergingPathQueryNode[]) pathConstraints.toArray(new MergingPathQueryNode[pathConstraints.size()]);
paths = path.doMerge(paths);
pathConstraints.clear();
pathConstraints.addAll(Arrays.asList(paths));
}
}
} catch (NoSuchElementException e) {
throw new IllegalArgumentException("Invalid combination of jcr:path clauses");
}
MergingPathQueryNode path = (MergingPathQueryNode) pathConstraints.get(0);
LocationStepQueryNode[] steps = path.getPathSteps();
for (int i = 0; i < steps.length; i++) {
LocationStepQueryNode step = new LocationStepQueryNode(pathNode, steps[i].getNameTest(), steps[i].getIncludeDescendants());
step.setIndex(steps[i].getIndex());
pathNode.addPathStep(step);
}
}
if (constraintNode.getNumOperands() > 0) {
// attach constraint to last path step
LocationStepQueryNode[] steps = pathNode.getPathSteps();
steps[steps.length - 1].addPredicate(constraintNode);
}
return root;
}