⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 levelledexpressionlist.java

📁 Java的Web报表库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        else
        {
          try
          {
            if (e.isActive())
            {
              e.getValue();
            }
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
      }
    }
  }

  /**
   * Receives notification that a group of item bands has been completed.
   * <P>
   * The itemBand is finished, the report starts to close open groups.
   *
   * @param event  the event.
   */
  public void itemsFinished(final ReportEvent event)
  {
    // clearError(); done in the prepare event ...

    for (int i = 0; i < levels.length; i++)
    {
      final int level = levels[i];
      if (level < getLevel())
      {
        break;
      }
      final Iterator itLevel = expressionList.getElementsForLevel(level);
      while (itLevel.hasNext())
      {
        final Expression e = (Expression) itLevel.next();
        if (e instanceof Function)
        {
          final Function f = (Function) e;
          try
          {
            f.itemsFinished(event);
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
        else
        {
          try
          {
            if (e.isActive())
            {
              e.getValue();
            }
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
      }
    }
  }

  /**
   * Receives notification that a new row has been read.
   * <P>
   * This event is raised before an ItemBand is printed.
   *
   * @param event  the event.
   */
  public void itemsAdvanced(final ReportEvent event)
  {
    // clearError(); done in the prepare event ...

    for (int i = 0; i < levels.length; i++)
    {
      final int level = levels[i];
      if (level < getLevel())
      {
        break;
      }
      final Iterator itLevel = expressionList.getElementsForLevel(level);
      while (itLevel.hasNext())
      {
        final Expression e = (Expression) itLevel.next();
        if (e instanceof Function)
        {
          final Function f = (Function) e;
          try
          {
            f.itemsAdvanced(event);
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
        else
        {
          try
          {
            if (e.isActive())
            {
              e.getValue();
            }
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
      }
    }
  }

  /**
   * Receives notification that the band layouting has completed.
   * <P>
   * The event carries the current report state.
   *
   * @param event The event.
   */
  public void layoutComplete(final LayoutEvent event)
  {
    // this is an internal event, no need to handle prepare outside ..
    // clearError();
    firePrepareEventLayoutListener(event);

    for (int i = 0; i < levels.length; i++)
    {
      final int level = levels[i];
      if (level < getLevel())
      {
        break;
      }
      final Iterator itLevel = expressionList.getElementsForLevel(level);
      while (itLevel.hasNext())
      {
        final Expression e = (Expression) itLevel.next();
        if (e instanceof LayoutListener && e instanceof Function)
        {
          final LayoutListener f = (LayoutListener) e;
          try
          {
            f.layoutComplete(event);
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
      }
    }
  }

  /**
   * Receives notification that report generation has completed, the report footer was printed,
   * no more output is done. This is a helper event to shut down the output service.
   *
   * @param event The event.
   */
  public void reportDone(final ReportEvent event)
  {
    // clearError(); done in the prepare event ...

    for (int i = 0; i < levels.length; i++)
    {
      final int level = levels[i];
      if (level < getLevel())
      {
        break;
      }
      final Iterator itLevel = expressionList.getElementsForLevel(level);
      while (itLevel.hasNext())
      {
        final Expression e = (Expression) itLevel.next();
        if (e instanceof Function)
        {
          final Function f = (Function) e;
          try
          {
            f.reportDone(event);
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
        else
        {
          try
          {
            if (e.isActive())
            {
              e.getValue();
            }
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
      }
    }
  }

  /**
   * Connects the given datarow to the expression collection and all expressions contained in
   * this collection.
   *
   * @param dr  the datarow to be connected (null not permitted).
   *
   * @throws IllegalStateException if there is a datarow already connected.
   * @throws NullPointerException if the given datarow is null.
   */
  public void setDataRow(final DataRow dr)
  {
    if (dr != null && dataRow != null)
    {
      // be paranoid and make sure that we dont replace the datarow
      // by accident
      throw new IllegalStateException
          ("Paranoia: Update calls must be done using the updateDataRow method.");
    }
    updateDataRow(dr);
  }

  /**
   * Updates the datarow for all expressions. Does not perform validity
   * checks, so use this function with care.
   *
   * @param dr  the datarow to be connected.
   *
   * @throws NullPointerException if the given datarow is null.
   * @throws IllegalStateException if there is no datarow connected.
   */
  public void updateDataRow(final DataRow dr)
  {
    dataRow = dr;
    for (int i = 0; i < expressionList.size(); i++)
    {
      final Expression f = (Expression) expressionList.get(i);
      f.setDataRow(dr);
    }
  }

  /**
   * Returns the currently connected dataRow.
   *
   * @return the dataRow.
   */
  public DataRow getDataRow()
  {
    return dataRow;
  }

  /**
   * Initialises the expressions.
   *
   * @param expressionCollection  the expression collection.
   */
  private void initializeExpressions(final ExpressionCollection expressionCollection)
  {
    final int size = expressionCollection.size();
    for (int i = 0; i < size; i++)
    {
      Expression f = expressionCollection.getExpression(i);
      if (f != null)
      {
        f = f.getInstance();
        expressionList.add(f);
        expressionList.setLevel(f, f.getDependencyLevel());
      }
    }
  }

  /**
   * Initialises the functions.
   *
   * @param functionCollection  the function collection.
   */
  private void initializeFunctions(final ExpressionCollection functionCollection)
  {
    final int size = functionCollection.size();
    for (int i = 0; i < size; i++)
    {
      // Explicit cast to Function to test all contained elements to be Functions!
      Function f = (Function) functionCollection.getExpression(i);
      if (f != null)
      {
        f = (Function) f.getInstance();
        expressionList.add(f);
        expressionList.setLevel(f, f.getDependencyLevel());
      }
    }
  }

  /**
   * Size does not change, so it is cached.
   *
   * @return the size.
   */
  public int size()
  {
    return expressionList.size();
  }

  /**
   * Creates and returns a copy of this object.  The precise meaning
   * of "copy" may depend on the class of the object.
   * <p>
   * The cloned LevelledExpression list will no longer be connected to
   * a datarow.
   *
   * @return     a clone of this instance.
   * @exception  CloneNotSupportedException  if the object's class does not
   *               support the <code>Cloneable</code> interface.
   * @exception  OutOfMemoryError            if there is not enough memory.
   * @see        java.lang.Cloneable
   */
  public Object clone() throws CloneNotSupportedException
  {
    final LevelledExpressionList ft = (LevelledExpressionList) super.clone();
    ft.expressionList = new LevelList(); // dont clone, too expensive ...
    ft.levels = levels;
    ft.dataRow = null;
    ft.errorList = (ArrayList) errorList.clone();

    final int size = expressionList.size();
    for (int i = 0; i < size; i++)
    {
      final Expression ex = (Expression) expressionList.get(i);
      if (ex instanceof Function)
      {
        final Expression exClone = (Expression) ex.clone();
        exClone.setDataRow(null);
        ft.expressionList.add(exClone, expressionList.getLevel(i));
      }
      else
      {
        final Expression exClone = ex.getInstance();
        exClone.setDataRow(null);
        ft.expressionList.add(exClone, expressionList.getLevel(i));
      }
    }
    return ft;
  }

  public LevelledExpressionList getPreviewInstance ()
  {
    final LevelledExpressionList ft = new LevelledExpressionList();
    ft.expressionList = new LevelList(); // dont clone, too expensive ...
    ft.errorList = new ArrayList();

    final int size = expressionList.size();
    for (int i = 0; i < size; i++)
    {
      final Expression ex = (Expression) expressionList.get(i);
      if (ex instanceof Function)
      {
        // ignore it, functions are state dependent and cannot be used
        // to compute group changes ...
      }
      else
      {
        ft.expressionList.add(ex.getInstance(), expressionList.getLevel(i));
      }
    }
    ft.levels = ft.buildLevels();
    return ft;
  }

  /**
   * Sets the level.
   *
   * @param level  the level.
   */
  public void setLevel(final int level)
  {
    this.level = level;
  }

  /**
   * Gets the current level.
   *
   * @return the current level.
   */
  public int getLevel()
  {
    return level;
  }

  /**
   * Returns an iterator that provides access to the levels in descending order.
   *
   * @return the iterator.
   */
  public Iterator getLevelsDescending()
  {
    return expressionList.getLevelsDescending();
  }

  /**
   * Returns an iterator that provides access to the levels in ascending order.
   *
   * @return the iterator.
   */
  public Iterator getLevelsAscending()
  {
    return expressionList.getLevelsAscending();
  }

  /**
   * Returns the values of an expression.
   *
   * @param index  the function/expression index.
   *
   * @return the value.
   */
  public Object getValue(final int index)
  {
    return ((Expression) expressionList.get(index)).getValue();
  }

  /**
   * Returns an expression.
   *
   * @param index  the function/expression index.
   *
   * @return the function/expression.
   */
  public Expression getExpression(final int index)
  {
    return ((Expression) expressionList.get(index));
  }

  /**
   * Returns the list of errors, that occured during the last event handling.
   *
   * @return the list of errors.
   */
  public List getErrors()
  {
    return Collections.unmodifiableList(errorList);
  }

  /**
   * Returns true, if this list has detected at least one error in the last operation.
   *
   * @return true, if there were errors, false otherwise.
   */
  public boolean hasErrors()
  {
    return errorList.size() != 0;
  }

  /**
   * Adds the error to the current list of errors.
   *
   * @param e the new exception that occured during the event dispatching.
   */
  protected void addError(final Exception e)
  {
    Log.debug ("Error added: " + e);
    errorList.add(e);
  }

  /**
   * Clears the error list.
   */
  protected void clearError()
  {
    errorList.clear();
  }

  /**
   * Fires a prepare event.
   *
   * @param event  the event.
   */
  public void firePrepareEvent(final ReportEvent event)
  {
    clearError();

    for (int i = 0; i < levels.length; i++)
    {
      final int level = levels[i];
      if (level < getLevel())
      {
        break;
      }
      final Iterator itLevel = expressionList.getElementsForLevel(level);
      while (itLevel.hasNext())
      {
        final Expression e = (Expression) itLevel.next();
        if (e instanceof Function && e instanceof PrepareEventListener)
        {
          final PrepareEventListener f = (PrepareEventListener) e;
          try
          {
            f.prepareEvent(event);
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
      }
    }
  }

  /**
   * Fires a prepare event layout listeners.
   *
   * @param event  the event.
   */
  protected void firePrepareEventLayoutListener(final ReportEvent event)
  {
    // no clear error here ...
    for (int i = 0; i < levels.length; i++)
    {
      final int level = levels[i];
      if (level < getLevel())
      {
        break;
      }
      final Iterator itLevel = expressionList.getElementsForLevel(level);
      while (itLevel.hasNext())
      {
        final Expression e = (Expression) itLevel.next();
        if (e instanceof Function && e instanceof PrepareEventListener
            && e instanceof LayoutListener)
        {
          final PrepareEventListener f = (PrepareEventListener) e;
          try
          {
            f.prepareEvent(event);
          }
          catch (Exception ex)
          {
            addError(ex);
          }
        }
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -