private Object createCollection(JXPathContext context, int index) {
createPath(context);
Object collection = getBaseValue();
if (collection == null) {
throw new JXPathException(
"Factory did not assign a collection to variable '"
+ name
+ "' for path: "
+ asPath());
}
if (index == WHOLE_COLLECTION) {
index = 0;
}
else if (index < 0) {
throw new JXPathException("Index is less than 1: " + asPath());
}
if (index >= getLength()) {
collection = ValueUtils.expandCollection(collection, index + 1);
variables.declareVariable(name.toString(), collection);