* @throws InvalidRequestException if more than one "where" parameter is
* specified.
*/
private DocumentHitIterator getDocumentHitIterator(OperationRequest operation, ApiView view)
throws InvalidRequestException {
Range range = OperationUtil.getOptionalParameter(operation, ParamsProperty.RANGE);
Integer index = OperationUtil.getOptionalParameter(operation, ParamsProperty.INDEX);
DocumentModifyQuery query =
OperationUtil.getOptionalParameter(operation, ParamsProperty.MODIFY_QUERY);
DocumentHitIterator hitIterator;
if (range != null) {
if (index != null || query != null) {
throw new InvalidRequestException(
"At most one parameter out of RANGE, INDEX and MODIFY_QUERY must be specified",
operation);
}
// Use the specified range
hitIterator = new DocumentHitIterator.Singleshot(range);
} else if (index != null) {
if (query != null) { // range is null.
throw new InvalidRequestException(
"At most one parameter out of RANGE, INDEX and MODIFY_QUERY must be specified",
operation);
}
// Use exactly the location of the index
hitIterator = new DocumentHitIterator.Singleshot(new Range(index, index + 1));
} else if (query != null) { // range and index are both null.
// Use the query
hitIterator = new DocumentHitIterator.ElementMatcher(
view, query.getElementMatch(), query.getRestrictions(), query.getMaxRes());
} else {
// Take entire document since nothing appropriate was specified
hitIterator = new DocumentHitIterator.Singleshot(new Range(0, view.apiContents().length()));
}
return hitIterator;
}