AvailableShards availableShards)
throws DissectionException {
// Create a SelectedShards object to hold the shards that have been
// selected for each dissectable area.
SelectedShards selectedShards = document.createSelectedShards();
// Get the shard that has been selected for each dissectable area. This
// is done by iterating over the dissectable areas looking to see if a
// shard has been specified for them in the fragmentation state. If no
// shard has been explicitly set then the first shard is used.
int count = selectedShards.getCount();
for (int i = 0; i < count; i += 1) {
DissectableArea area = document.getDissectableArea(i);
int shardIndex = requestedShards.getShard(area.getIndex());
// Retrieve the appropriate shard from the area. If the shard index
// is invalid for some reason then we may not get back exactly the
// one that we asked for but we will get one back.
Shard shard
= area.retrieveShard(dissectionContext, shardIndex,
(AvailableShardsImpl) availableShards);
if (shard == null) {
throw new DissectionException(
exceptionLocalizer.format("shard-not-found"));
}
// todo: We need to check to see whether there are any discrepancies
// todo: between the requested shards and the selected ones as if
// todo: there are it means that there is a problem with the
// todo: source of the information such as fragmentation state.
// Set the shard on the specified area.
selectedShards.setShard(area, shard);
}
return selectedShards;
}