*/
public static void setupIndexes(CASMgr aCASMgr, FsIndexDescription[] aIndexes)
throws ResourceInitializationException {
if (aIndexes != null) {
TypeSystemMgr tsm = aCASMgr.getTypeSystemMgr();
FSIndexRepositoryMgr irm = aCASMgr.getIndexRepositoryMgr();
for (int i = 0; i < aIndexes.length; i++) {
int kind = FSIndex.SORTED_INDEX;
String kindStr = aIndexes[i].getKind();
if (kindStr != null) {
if (kindStr.equals(FsIndexDescription.KIND_BAG))
kind = FSIndex.BAG_INDEX;
else if (kindStr.equals(FsIndexDescription.KIND_SET))
kind = FSIndex.SET_INDEX;
else if (kindStr.equals(FsIndexDescription.KIND_SORTED))
kind = FSIndex.SORTED_INDEX;
}
Type type = tsm.getType(aIndexes[i].getTypeName());
if (type == null) {
throw new ResourceInitializationException(
ResourceInitializationException.UNDEFINED_TYPE_FOR_INDEX, new Object[] {
aIndexes[i].getTypeName(), aIndexes[i].getLabel(),
aIndexes[i].getSourceUrlString() });
}
FSIndexComparator comparator = irm.createComparator();
comparator.setType(type);
FsIndexKeyDescription[] keys = aIndexes[i].getKeys();
if (keys != null) {
for (int j = 0; j < keys.length; j++) {
if (keys[j].isTypePriority()) {
comparator.addKey(irm.getDefaultTypeOrder(), FSIndexComparator.STANDARD_COMPARE);
} else {
Feature feature = type.getFeatureByBaseName(keys[j].getFeatureName());
if (feature == null) {
throw new ResourceInitializationException(
ResourceInitializationException.INDEX_KEY_FEATURE_NOT_FOUND, new Object[] {
keys[j].getFeatureName(), aIndexes[i].getLabel(),
aIndexes[i].getSourceUrlString() });
}
comparator.addKey(feature, keys[j].getComparator());
}
}
}
irm.createIndex(comparator, aIndexes[i].getLabel(), kind);
}
}
}