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

📄 tableprocessor.java

📁 Java的Web报表库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        level = ((Integer) it.next()).intValue();
        if (state instanceof FinishState)
        {
          state = new StartState((FinishState) state, level);
        }
        else
        {
          throw new IllegalStateException("Repaginate did not produce an finish state");
        }
      }
    } while (hasNext == true);

    // root of evilness here ... pagecount should not be handled specially ...
    // The pagecount should not be added as report property, there are functions to
    // do this.
    /*
    state.setProperty(JFreeReportConstants.REPORT_PAGECOUNT_PROPERTY,
                      new Integer(state.getCurrentPage() - 1));
    */
    state.setProperty(JFreeReportConstants.REPORT_PREPARERUN_PROPERTY, Boolean.FALSE);

    // finally prepeare the returned start state.
    final StartState sretval = (StartState) retval;
    if (sretval == null)
    {
      throw new IllegalStateException("There was no valid pagination done.");
    }
    // reset the state, so that the datarow points to the first row of the tablemodel.
    sretval.resetState();
    return sretval;
  }

  /**
   * Processes the report. The generated output is written using the defined
   * writer, the report is repaginated before the final writing.
   *
   * @throws ReportProcessingException if the report processing failed.
   */
  public void processReport() throws ReportProcessingException
  {
    try
    {
      ReportState state = repaginate();

      final TableWriter w = (TableWriter) state.getDataRow().get(TABLE_WRITER);
      w.setProducer(createProducer(false));
      w.getProducer().configure(getProperties());

      w.setMaxWidth((float) getReport().getDefaultPageFormat().getImageableWidth());

      int maxRows = state.getNumberOfRows();
      int lastRow = -1;
      int eventCount = 0;
      int eventTrigger = maxRows / MAX_EVENTS_PER_RUN;
      RepaginationState stateEvent = new RepaginationState(this, 0, 0, 0, 0, false);

      final boolean failOnError =
          getReport().getReportConfiguration().isStrictErrorHandling();
      ReportStateProgress progress = null;
      while (!state.isFinish())
      {

        if (lastRow != state.getCurrentDisplayItem())
        {
          lastRow = state.getCurrentDisplayItem();
          if (eventCount == 0)
          {
            stateEvent.reuse(TableWriter.OUTPUT_LEVEL, state.getCurrentPage(),
                state.getCurrentDataItem(), state.getNumberOfRows(), true);
            fireStateUpdate(stateEvent);
            eventCount += 1;
          }
          else
          {
            if (eventCount == eventTrigger)
            {
              eventCount = 0;
            }
            else
            {
              eventCount += 1;
            }
          }
        }

        progress = state.createStateProgress(progress);
        state = state.advance();
        if (failOnError && state.isErrorOccured() == true)
        {
          throw new ReportEventException("Failed to dispatch an event.", state.getErrors());
        }
        if (!state.isFinish())
        {
          if (!state.isProceeding(progress))
          {
            throw new ReportProcessingException("State did not proceed, bailing out!");
          }
        }
      }
    }
    catch (CloneNotSupportedException cne)
    {
      throw new ReportProcessingException("StateCopy was not supported");
    }
  }

  /**
   * Creates a TableProducer. The TableProducer is responsible to create the table.
   *
   * @param dummy true, if dummy mode is enabled, and no writing should be done, false otherwise.
   * @return the created table producer, never null.
   */
  protected abstract TableProducer createProducer(boolean dummy);

  /**
   * Defines a property for this output target. Properties are the standard way of configuring
   * an output target.
   *
   * @param property  the name of the property to set (<code>null</code> not permitted).
   * @param value  the value of the property.  If the value is <code>null</code>, the property is
   * removed from the output target.
   */
  public void setProperty(final String property, final Object value)
  {
    if (property == null)
    {
      throw new NullPointerException();
    }

    if (value == null)
    {
      properties.remove(property);
    }
    else
    {
      properties.put(property, value);
    }
  }

  /**
   * Queries the property named with <code>property</code>. If the property is not found, <code>
   * null</code> is returned.
   *
   * @param property the name of the property to be queried
   *
   * @return the value stored under the given property name
   *
   * @throws java.lang.NullPointerException if <code>property</code> is null
   */
  public Object getProperty(final String property)
  {
    return getProperty(property, null);
  }

  /**
   * Queries the property named with <code>property</code>. If the property is not found, the
   * default value is returned.
   *
   * @param property the name of the property to be queried
   * @param defaultValue the defaultvalue returned if there is no such property
   *
   * @return the value stored under the given property name
   *
   * @throws NullPointerException if <code>property</code> is null
   */
  public Object getProperty(final String property, final Object defaultValue)
  {
    if (property == null)
    {
      throw new NullPointerException();
    }

    final Object retval = properties.get(property);
    if (retval == null)
    {
      return defaultValue;
    }
    return retval;
  }

  /**
   * Returns an enumeration of the property names.
   *
   * @return the enumeration.
   */
  protected Iterator getPropertyNames()
  {
    return properties.keySet().iterator();
  }

  /**
   * Gets the internal properties storage.
   *
   * @return the internal properties storage.
   */
  protected Properties getProperties()
  {
    return properties;
  }

  /**
   * Gets the report configuration prefix for that processor. This prefix defines
   * how to map the property names into the global report configuration.
   *
   * @return the report configuration prefix.
   */
  protected abstract String getReportConfigurationPrefix();

  /**
   * Copies all report configuration properties which match the configuration
   * prefix of this table processor into the property set of this processor.
   */
  protected void configure()
  {
    final ReportConfiguration rc = getReport().getReportConfiguration();
    final Enumeration enum = rc.getConfigProperties();
    final String prefix = getReportConfigurationPrefix();

    while (enum.hasMoreElements())
    {
      final String key = (String) enum.nextElement();
      if (key.startsWith(prefix) == false)
      {
        continue;
      }
      final String propKey = key.substring(prefix.length());
      if (getProperties().containsKey(propKey))
      {
        continue;
      }
      final Object value = rc.getConfigProperty(key);
      setProperty(propKey, value);
    }

    getTableWriter().setMaxWidth((float) getReport().getDefaultPageFormat().getImageableWidth());
  }

  /**
   * Adds a repagination listener. This listener will be informed of
   * pagination events.
   *
   * @param l  the listener.
   */
  public void addRepaginationListener(final RepaginationListener l)
  {
    if (l == null)
    {
      throw new NullPointerException("Listener == null");
    }
    if (listeners == null)
    {
      listeners = new ArrayList(5);
    }
    listenersCache = null;
    listeners.add(l);
  }

  /**
   * Removes a repagination listener.
   *
   * @param l  the listener.
   */
  public void removeRepaginationListener(final RepaginationListener l)
  {
    if (l == null)
    {
      throw new NullPointerException("Listener == null");
    }
    if (listeners == null)
    {
      return;
    }
    listenersCache = null;
    listeners.remove(l);
  }

  /**
   * Sends a repagination update to all registered listeners.
   *
   * @param state  the state.
   */
  protected void fireStateUpdate(final RepaginationState state)
  {
    if (listeners == null)
    {
      return;
    }
    if (listenersCache == null)
    {
      listenersCache = listeners.toArray();
    }
    for (int i = 0; i < listenersCache.length; i++)
    {
      final RepaginationListener l = (RepaginationListener) listenersCache[i];
      l.repaginationUpdate(state);
    }
  }

}

⌨️ 快捷键说明

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