public static FsIndexCollection mergeFsIndexes(List aFsIndexCollections,
ResourceManager aResourceManager) throws ResourceInitializationException {
Map aggIndexes = new HashMap();
Iterator it = aFsIndexCollections.iterator();
while (it.hasNext()) {
FsIndexCollection indexColl = (FsIndexCollection) it.next();
if (indexColl != null) {
try {
indexColl.resolveImports(aResourceManager);
} catch (InvalidXMLException e) {
throw new ResourceInitializationException(e);
}
FsIndexDescription[] indexes = indexColl.getFsIndexes();
for (int i = 0; i < indexes.length; i++) {
// does an index with this label already exist?
FsIndexDescription duplicateIndex = (FsIndexDescription) aggIndexes.get(indexes[i]
.getLabel());
if (duplicateIndex == null) {
// no, so add it
aggIndexes.put(indexes[i].getLabel(), indexes[i]);
} else if (!duplicateIndex.equals(indexes[i])) {
// index with same label exists, they better be equal!
throw new ResourceInitializationException(
ResourceInitializationException.DUPLICATE_INDEX_NAME, new Object[] {
duplicateIndex.getLabel(), duplicateIndex.getSourceUrlString(),
indexes[i].getSourceUrlString() });
}
}
}
}
// convert index map to FsIndexCollection
FsIndexCollection aggIndexColl = UIMAFramework.getResourceSpecifierFactory()
.createFsIndexCollection();
Collection indexes = aggIndexes.values();
FsIndexDescription[] indexArray = new FsIndexDescription[indexes.size()];
indexes.toArray(indexArray);
aggIndexColl.setFsIndexes(indexArray);
return aggIndexColl;
}