{
sortInfo.sortFieldInfo = new SortFieldInfo[sortFields.length];
for(int i = 0; i < sortFields.length; i++)
{
JRSortField sortField = sortFields[i];
String sortFieldName = sortField.getName();
SortFieldInfo info = new SortFieldInfo();
info.name = sortFieldName;
info.isVariable = sortField.getType() == SortFieldTypeEnum.VARIABLE;
info.order = (SortOrderEnum.ASCENDING == sortField.getOrderValue() ? 1 : -1);
Integer index;
if (info.isVariable)
{
JRVariable variable = (JRVariable)variablesMap.get(sortFieldName);
if (variable == null)
{
throw new JRRuntimeException("Sort variable \"" + sortFieldName + "\" not found in dataset.");
}
index = new Integer(sortInfo.fieldNames.size());
info.collatorFlag = String.class.getName().equals(variable.getValueClassName());
sortInfo.fieldNames.add(variable.getName());
}
else
{
JRField field = (JRField)fieldsMap.get(sortFieldName);
if (field == null)
{
throw new JRRuntimeException("Sort field \"" + sortFieldName + "\" not found in dataset.");
}
index = (Integer)fieldIndexMap.get(sortField.getName());
info.collatorFlag = String.class.getName().equals(field.getValueClassName());
}
info.index = index.intValue();