JRField[] fields = dataset.getFields();
if (fields != null)
{
for(int i = 0; i < fields.length; i++)
{
JRField field = fields[i];
fieldsMap.put(field.getName(), field);
fieldIndexMap.put(field.getName(), Integer.valueOf(i));
sortInfo.fieldNames.add(field.getName());
}
}
Map variablesMap = new HashMap();
JRVariable[] variables = dataset.getVariables();
if (variables != null)
{
for(int i = 0; i < variables.length; i++)
{
variablesMap.put(variables[i].getName(), variables[i]);
}
}
JRSortField[] sortFields = getAllSortFields(dataset);
if (sortFields != null)
{
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();
sortInfo.sortFieldInfo[i] = info;
}