protected JRBaseSubreportReturnValue(
      JRSubreportReturnValue returnValue, JRBaseObjectFactory factory) {
    factory.put(returnValue, this);

    subreportVariable = returnValue.getSubreportVariable();
    toVariable = returnValue.getToVariable();
    calculation = returnValue.getCalculation();
    incrementerFactoryClassName = returnValue.getIncrementerFactoryClassName();
  }
  protected JRSubreportReturnValue createHelperReturnValue(
      JRSubreportReturnValue returnValue, String nameSuffix, CalculationEnum calculation) {
    JRDesignSubreportReturnValue helper = new JRDesignSubreportReturnValue();
    helper.setToVariable(returnValue.getToVariable() + nameSuffix);
    helper.setSubreportVariable(returnValue.getSubreportVariable());
    helper.setCalculation(calculation);
    helper.setIncrementerFactoryClassName(
        helper.getIncrementerFactoryClassName()); // FIXME shouldn't it be returnValue?

    return helper;
  }
  protected JRSubreportReturnValue createDistinctCountHelperReturnValue(
      JRSubreportReturnValue returnValue) {
    JRDesignSubreportReturnValue helper = new JRDesignSubreportReturnValue();
    helper.setToVariable(returnValue.getToVariable() + "_DISTINCT_COUNT");
    helper.setSubreportVariable(returnValue.getSubreportVariable());
    helper.setCalculation(CalculationEnum.NOTHING);
    helper.setIncrementerFactoryClassName(
        helper
            .getIncrementerFactoryClassName()); // FIXME shouldn't it be returnValue? tests required

    return helper;
  }
 public boolean usesForReturnValue(String variableName) {
   boolean used = false;
   if (returnValues != null) {
     for (int j = 0; j < returnValues.length; j++) {
       JRSubreportReturnValue returnValue = returnValues[j];
       if (returnValue.getToVariable().equals(variableName)) {
         used = true;
         break;
       }
     }
   }
   return used;
 }
  /**
   * Verifies the list of copied values against the subreport.
   *
   * @throws JRException
   */
  private void checkReturnValues() throws JRException {
    if (returnValues != null && returnValues.length > 0) {
      for (int i = 0; i < returnValues.length; i++) {
        JRSubreportReturnValue returnValue = returnValues[i];
        String subreportVariableName = returnValue.getSubreportVariable();
        JRVariable subrepVariable = subreportFiller.getVariable(subreportVariableName);
        if (subrepVariable == null) {
          throw new JRException("Subreport variable " + subreportVariableName + " not found.");
        }

        JRVariable variable = filler.getVariable(returnValue.getToVariable());
        if (returnValue.getCalculationValue() == CalculationEnum.COUNT
            || returnValue.getCalculationValue() == CalculationEnum.DISTINCT_COUNT) {
          if (!Number.class.isAssignableFrom(variable.getValueClass())) {
            throw new JRException(
                "Variable " + returnValue.getToVariable() + " must have a numeric type.");
          }
        } else if (!variable.getValueClass().isAssignableFrom(subrepVariable.getValueClass())
            && !(Number.class.isAssignableFrom(variable.getValueClass())
                && Number.class.isAssignableFrom(subrepVariable.getValueClass()))) {
          throw new JRException(
              "Variable "
                  + returnValue.getToVariable()
                  + " is not assignable from subreport variable "
                  + subreportVariableName);
        }
      }
    }
  }