/**
   * 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);
        }
      }
    }
  }
 /**
  * Checks if the variable name is suitable for the current expression context.
  *
  * @param variable the variable to validate
  */
 @Check
 public void checkVariableName(JRVariableObj variable) {
   ExpressionContext currExpContext =
       ExpressionEditorSupportUtil.safeGetCurrentExpressionContext();
   List<JRVariable> allVariables = ExpressionContextUtils.getAllDatasetsVariables(currExpContext);
   for (JRVariable v : allVariables) {
     if (("{" + v.getName() + "}").equals(variable.getBracedIdentifier()))
       return; //$NON-NLS-1$ //$NON-NLS-2$
   }
   List<JRVariable> allCrosstabsVariables =
       ExpressionContextUtils.getAllCrosstabsVariables(currExpContext);
   for (JRVariable v : allCrosstabsVariables) {
     if (("{" + v.getName() + "}").equals(variable.getBracedIdentifier()))
       return; //$NON-NLS-1$ //$NON-NLS-2$
   }
   error(
       Messages.JavaJRExpressionJavaValidator_VariableNotFoundInContextError,
       variable,
       JavaJRExpressionPackage.Literals.JR_VARIABLE_OBJ__BRACED_IDENTIFIER,
       JavaJRExpressionPackage.JR_VARIABLE_OBJ__BRACED_IDENTIFIER);
 }
예제 #3
0
  private JRVariable createHelperVariable(
      JRVariable variable, String nameSuffix, byte calculation) {
    JRDesignVariable helper = new JRDesignVariable();
    helper.setName(variable.getName() + nameSuffix);
    helper.setValueClassName(variable.getValueClassName());
    helper.setIncrementerFactoryClassName(variable.getIncrementerFactoryClassName());
    helper.setResetType(variable.getResetType());
    helper.setResetGroup(variable.getResetGroup());
    helper.setIncrementType(variable.getIncrementType());
    helper.setIncrementGroup(variable.getIncrementGroup());
    helper.setCalculation(calculation);
    helper.setSystemDefined(true);
    helper.setExpression(variable.getExpression());

    return helper;
  }
예제 #4
0
  private JRVariable createDistinctCountHelperVariable(JRVariable variable) {
    JRDesignVariable helper = new JRDesignVariable();
    helper.setName(variable.getName() + "_DISTINCT_COUNT");
    helper.setValueClassName(variable.getValueClassName());
    helper.setIncrementerFactoryClassName(JRDistinctCountIncrementerFactory.class.getName());
    helper.setResetType(JRVariable.RESET_TYPE_REPORT);

    if (variable.getIncrementType() != JRVariable.RESET_TYPE_NONE)
      helper.setResetType(variable.getIncrementType());

    helper.setResetGroup(variable.getIncrementGroup());
    helper.setCalculation(JRVariable.CALCULATION_NOTHING);
    helper.setSystemDefined(true);
    helper.setExpression(variable.getExpression());

    return helper;
  }
  private String generateExpression(JRExpression expression, byte evaluationType) {
    JRParameter jrParameter = null;
    JRField jrField = null;
    JRVariable jrVariable = null;

    StringBuffer sbuffer = new StringBuffer();

    JRExpressionChunk[] chunks = expression.getChunks();
    JRExpressionChunk chunk = null;
    String chunkText = null;
    if (chunks != null && chunks.length > 0) {
      for (int i = 0; i < chunks.length; i++) {
        chunk = chunks[i];

        chunkText = chunk.getText();
        if (chunkText == null) {
          chunkText = "";
        }

        switch (chunk.getType()) {
          case JRExpressionChunk.TYPE_TEXT:
            {
              sbuffer.append(chunkText);
              break;
            }
          case JRExpressionChunk.TYPE_PARAMETER:
            {
              jrParameter = (JRParameter) parametersMap.get(chunkText);

              sbuffer.append("((");
              sbuffer.append(jrParameter.getValueClassName());
              sbuffer.append(")super.parameter_");
              sbuffer.append(JRStringUtil.getJavaIdentifier(chunkText));
              sbuffer.append(".getValue())");

              break;
            }
          case JRExpressionChunk.TYPE_FIELD:
            {
              jrField = (JRField) fieldsMap.get(chunkText);

              sbuffer.append("((");
              sbuffer.append(jrField.getValueClassName());
              sbuffer.append(")super.field_");
              sbuffer.append(JRStringUtil.getJavaIdentifier(chunkText));
              sbuffer.append(".get");
              sbuffer.append((String) fieldPrefixMap.get(new Byte(evaluationType)));
              sbuffer.append("Value())");

              break;
            }
          case JRExpressionChunk.TYPE_VARIABLE:
            {
              jrVariable = (JRVariable) variablesMap.get(chunkText);

              sbuffer.append("((");
              sbuffer.append(jrVariable.getValueClassName());
              sbuffer.append(")super.variable_");
              sbuffer.append(JRStringUtil.getJavaIdentifier(chunkText));
              sbuffer.append(".get");
              sbuffer.append((String) variablePrefixMap.get(new Byte(evaluationType)));
              sbuffer.append("Value())");

              break;
            }
          case JRExpressionChunk.TYPE_RESOURCE:
            {
              jrParameter = (JRParameter) parametersMap.get(chunkText);

              sbuffer.append("super.evaluator.str(\"");
              sbuffer.append(chunkText);
              sbuffer.append("\")");

              break;
            }
        }
      }
    }

    if (sbuffer.length() == 0) {
      sbuffer.append("null");
    }

    return sbuffer.toString();
  }
예제 #6
0
 private boolean hasVariableCalculationReq(JRVariable var, byte calculation) {
   return variableCalculationReqs.contains(new VariableCalculationReq(var.getName(), calculation));
 }