Package net.sf.jasperreports.engine

Examples of net.sf.jasperreports.engine.JRVariable


    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())");
View Full Code Here


    {
      // add the variable before the first non-system variable
      ListIterator it = variablesList.listIterator();
      while (it.hasNext())
      {
        JRVariable var = (JRVariable) it.next();
        if (!var.isSystemDefined())
        {
          it.previous();
          break;
        }
      }
View Full Code Here

    {
      clone.variablesList = new ArrayList(variablesList.size());
      clone.variablesMap = new HashMap(variablesList.size());
      for(int i = 0; i < variablesList.size(); i++)
      {
        JRVariable variable =
          (JRVariable)((JRVariable)variablesList.get(i)).clone();
        clone.variablesList.add(variable);
        clone.variablesMap.put(variable.getName(), variable);
      }
    }
   
    if (groupsList != null)
    {
View Full Code Here

    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);
          }
        }
      }
    }
  }
View Full Code Here

      String incrementerFactoryClassName = getIncrementerFactoryClassName();
     
      JRIncrementerFactory incrementerFactory;
      if (incrementerFactoryClassName == null)
      {
        JRVariable toVariable = filler.getVariable(getToVariable());
        incrementerFactory = JRDefaultIncrementerFactory.getFactory(toVariable.getValueClass());
      }
      else
      {
        try
        {
View Full Code Here

    byte evaluationType
    )
  {
    JRParameter jrParameter = null;
    JRField jrField = null;
    JRVariable jrVariable = null;

    StringBuffer sb = 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 :
          {
            appendExpressionText(expression, sb, chunkText);
            break;
          }
          case JRExpressionChunk.TYPE_PARAMETER :
          {
            jrParameter = (JRParameter)parametersMap.get(chunkText);
 
            sb.append("((");
            sb.append(jrParameter.getValueClassName());
            sb.append(")parameter_");
            sb.append(JRStringUtil.getJavaIdentifier(chunkText));
            sb.append(".getValue())");
 
            break;
          }
          case JRExpressionChunk.TYPE_FIELD :
          {
            jrField = (JRField)fieldsMap.get(chunkText);
 
            sb.append("((");
            sb.append(jrField.getValueClassName());
            sb.append(")field_");
            sb.append(JRStringUtil.getJavaIdentifier(chunkText));
            sb.append(".get");
            sb.append((String)fieldPrefixMap.get(new Byte(evaluationType)));
            sb.append("Value())");
 
            break;
          }
          case JRExpressionChunk.TYPE_VARIABLE :
          {
            jrVariable = (JRVariable)variablesMap.get(chunkText);
 
            sb.append("((");
            sb.append(jrVariable.getValueClassName());
            sb.append(")variable_");
            sb.append(JRStringUtil.getJavaIdentifier(chunkText));
            sb.append(".get");
            sb.append((String)variablePrefixMap.get(new Byte(evaluationType)));
            sb.append("Value())");
View Full Code Here

    if (variablesList != null)
    {
      clone.variablesList = new SequencedHashMap(variablesList.size());
      for(Iterator it = variablesList.values().iterator(); it.hasNext();)
      {
        JRVariable variable = (JRVariable) it.next();
        // check whether the variable was already cloned as part of a group or measure
        JRVariable variableClone = (JRVariable) clonedVariables.get(variable);
        if (variableClone == null)
        {
          variableClone = (JRVariable) variable.clone();
        }
        clone.variablesList.put(variableClone.getName(), variableClone);
      }
    }
   
    if (cellsList != null)
    {
View Full Code Here

        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)
View Full Code Here

    switch (calculation)
    {
      case AVERAGE:
      case VARIANCE:
      {
        JRVariable countVar = createHelperVariable(parentVariable, "_COUNT", CalculationEnum.COUNT);
        JRFillVariable fillCountVar = addVariable(countVar, variableList, factory);
        variable.setHelperVariable(fillCountVar, JRCalculable.HELPER_COUNT);

        JRVariable sumVar = createHelperVariable(parentVariable, "_SUM", CalculationEnum.SUM);
        JRFillVariable fillSumVar = addVariable(sumVar, variableList, factory);
        variable.setHelperVariable(fillSumVar, JRCalculable.HELPER_SUM);

        break;
      }
      case STANDARD_DEVIATION:
      {
        JRVariable varianceVar = createHelperVariable(parentVariable, "_VARIANCE", CalculationEnum.VARIANCE);
        JRFillVariable fillVarianceVar = addVariable(varianceVar, variableList, factory);
        variable.setHelperVariable(fillVarianceVar, JRCalculable.HELPER_VARIANCE);

        break;
      }
      case DISTINCT_COUNT:
      {
        JRVariable countVar = createDistinctCountHelperVariable(parentVariable);
        JRFillVariable fillCountVar = addVariable(countVar, variableList, factory);
        variable.setHelperVariable(fillCountVar, JRCalculable.HELPER_COUNT);

        break;
      }
View Full Code Here

  {
    if (hasVariableCalculationReq(variable, CalculationEnum.AVERAGE) || hasVariableCalculationReq(variable, CalculationEnum.VARIANCE))
    {
      if (variable.getHelperVariable(JRCalculable.HELPER_COUNT) == null)
      {
        JRVariable countVar = createHelperVariable(variable, "_COUNT", CalculationEnum.COUNT);
        JRFillVariable fillCountVar = factory.getVariable(countVar);
        checkVariableCalculationReq(fillCountVar, variableList, factory);
        variable.setHelperVariable(fillCountVar, JRCalculable.HELPER_COUNT);
      }

      if (variable.getHelperVariable(JRCalculable.HELPER_SUM) == null)
      {
        JRVariable sumVar = createHelperVariable(variable, "_SUM", CalculationEnum.SUM);
        JRFillVariable fillSumVar = factory.getVariable(sumVar);
        checkVariableCalculationReq(fillSumVar, variableList, factory);
        variable.setHelperVariable(fillSumVar, JRCalculable.HELPER_SUM);
      }
    }

    if (hasVariableCalculationReq(variable, CalculationEnum.STANDARD_DEVIATION))
    {
      if (variable.getHelperVariable(JRCalculable.HELPER_VARIANCE) == null)
      {
        JRVariable varianceVar = createHelperVariable(variable, "_VARIANCE", CalculationEnum.VARIANCE);
        JRFillVariable fillVarianceVar = factory.getVariable(varianceVar);
        checkVariableCalculationReq(fillVarianceVar, variableList, factory);
        variable.setHelperVariable(fillVarianceVar, JRCalculable.HELPER_VARIANCE);
      }
    }

    if (hasVariableCalculationReq(variable, CalculationEnum.DISTINCT_COUNT))
    {
      if (variable.getHelperVariable(JRCalculable.HELPER_COUNT) == null)
      {
        JRVariable countVar = createDistinctCountHelperVariable(variable);
        JRFillVariable fillCountVar = factory.getVariable(countVar);
        checkVariableCalculationReq(fillCountVar, variableList, factory);
        variable.setHelperVariable(fillCountVar, JRCalculable.HELPER_COUNT);
      }
    }
View Full Code Here

TOP

Related Classes of net.sf.jasperreports.engine.JRVariable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.