if (variables != null && variables.length > 0)
{
boolean isMainDataset = dataset.isMainDataset();
for(int index = 0; index < variables.length; index++)
{
JRVariable variable = variables[index];
if (variable.getName() == null || variable.getName().trim().length() == 0)
{
addBrokenRule("Variable name missing.", variable);
}
try
{
Class valueClass = variable.getValueClass();
if (valueClass == null)
{
addBrokenRule("Class not set for variable : " + variable.getName(), variable);
}
else
{
JRExpression expression = variable.getExpression();
if (expression != null)
{
try
{
if (expression.getValueClass() == null)
{
addBrokenRule("No value class for the expression has been set in variable: " + variable.getName(), expression);
}
else
{
if (variable.getCalculationValue() != CalculationEnum.COUNT && variable.getCalculationValue() != CalculationEnum.DISTINCT_COUNT
&& variable.getCalculationValue() != CalculationEnum.SYSTEM && !valueClass.isAssignableFrom(expression.getValueClass()))
{
addBrokenRule("The variable expression class is not compatible with the variable's class : " + variable.getName(), expression);
}
}
}
catch (JRRuntimeException e)
{
addBrokenRule(e, expression);
}
}
if (variable.getInitialValueExpression() != null)
{
try
{
if (!valueClass.isAssignableFrom(variable.getInitialValueExpression().getValueClass()))
{
addBrokenRule("The initial value class is not compatible with the variable's class : " + variable.getName(), variable.getInitialValueExpression());
}
}
catch (JRRuntimeException e)
{
addBrokenRule(e, variable.getInitialValueExpression());
}
}
}
}
catch (JRRuntimeException e)
{
addBrokenRule(e, variable);
}
ResetTypeEnum resetType = variable.getResetTypeValue();
if (resetType == ResetTypeEnum.GROUP)
{
if (variable.getResetGroup() == null)
{
addBrokenRule("Reset group missing for variable : " + variable.getName(), variable);
}
else
{
Map groupsMap = dataset.getGroupsMap();
if (!groupsMap.containsKey(variable.getResetGroup().getName()))
{
addBrokenRule("Reset group \"" + variable.getResetGroup().getName() + "\" not found for variable : " + variable.getName(), variable);
}
}
}
IncrementTypeEnum incrementType = variable.getIncrementTypeValue();
if (incrementType == IncrementTypeEnum.GROUP)
{
if (variable.getIncrementGroup() == null)
{
addBrokenRule("Increment group missing for variable : " + variable.getName(), variable);
}
else
{
Map groupsMap = dataset.getGroupsMap();
if (!groupsMap.containsKey(variable.getIncrementGroup().getName()))
{
addBrokenRule("Increment group \"" + variable.getIncrementGroup().getName() + "\" not found for variable : " + variable.getName(), variable);
}
}
}
if (!isMainDataset && !variable.isSystemDefined())
{
if (resetType == ResetTypeEnum.COLUMN || resetType == ResetTypeEnum.PAGE)
{
addBrokenRule("Variable " + variable.getName() + " of dataset " + dataset.getName() + " cannot have Column or Page reset type.", variable);
}
if (incrementType == IncrementTypeEnum.COLUMN || incrementType == IncrementTypeEnum.PAGE)
{
addBrokenRule("Variable " + variable.getName() + " of dataset " + dataset.getName() + " cannot have Column or Page increment type.", variable);
}
}
}
}
}