int indexType = Type.ITEM;
for (final Iterator<Collection> i = contextSequence.getCollectionIterator(); i.hasNext(); ) {
final Collection collection = i.next();
if (collection.getURI().startsWith(XmldbURI.SYSTEM_COLLECTION_URI))
{continue;}
final QNameRangeIndexSpec config = collection.getIndexByQNameConfiguration(context.getBroker(), qname);
if (config == null) {
// no index found for this collection
if (LOG.isTraceEnabled())
{LOG.trace("Cannot optimize: collection " + collection.getURI() + " does not define an index " +
"on " + qname);}
// if enfoceIndexUse == "always", continue to check other collections
// for indexes. It is sufficient if one collection defines an index
if (enforceIndexUse == null || !"always".equals(enforceIndexUse))
{return Type.ITEM;} // found a collection without index
} else {
int type = config.getType();
if (indexType == Type.ITEM) {
indexType = type;
// if enforceIndexUse == "always", it is sufficient if one collection
// defines an index. Just return it.
if (enforceIndexUse != null && "always".equals(enforceIndexUse))