String entityName = token.children().firstElement().value();
if (!rootEntity.label().equals(entityName)) {
throw new WikiQueryException(WikiQueryException.InvalidQueryStatement, "Unknown entity " + entityName + " as root of the database");
}
XPathComponent pathElement = null;
if (token.children().size() == 2) {
XAQLToken conditionToken = token.children().get(1);
if (conditionToken.type() == XAQLToken.INDEX_CONDITION) {
int index = -1;
try {
index = Integer.parseInt(conditionToken.children().firstElement().value());
} catch (java.lang.NumberFormatException nfe) {
throw new WikiQueryException(WikiQueryException.InvalidQueryStatement, "Invalid number format " + conditionToken.children().firstElement().value());
}
pathElement = new XPathComponent(rootEntity, new IndexCondition(index));
} else {
Condition condition = null;
if (conditionToken.children().size() > 1) {
Conjunction conjunction = new Conjunction();
for (int iCondition = 0; iCondition < conditionToken.children().size(); iCondition++) {
conjunction.add(new ConditionGenerator().getCondition(rootEntity, versionIndex, conditionToken.children().get(iCondition).children(), new RelativeTargetPathGenerator()));
}
condition = conjunction;
} else {
condition = new ConditionGenerator().getCondition(rootEntity, versionIndex, conditionToken.children().get(0).children(), new RelativeTargetPathGenerator());
}
pathElement = new XPathComponent(rootEntity, new SubPathCondition(condition));
}
} else {
pathElement = new XPathComponent(rootEntity);
}
if (pathTokens.hasNext()) {
return new XPath(pathElement, new RelativeTargetPathGenerator().getTargetPath(rootEntity, versionIndex, pathTokens));
} else {