Package org.pentaho.reporting.engine.classic.core.parameters

Source Code of org.pentaho.reporting.engine.classic.core.parameters.CompoundDataRow

package org.pentaho.reporting.engine.classic.core.parameters;

import org.pentaho.reporting.engine.classic.core.DataRow;
import org.pentaho.reporting.libraries.base.util.LinkedMap;

/**
* Todo: Document me!
* <p/>
* Date: 17.12.2009
* Time: 17:30:41
*
* @author Thomas Morgner.
*/
public class CompoundDataRow implements DataRow
{
  private LinkedMap columnSources;
  private DataRow envDataRow;
  private DataRow dataRow;

  public CompoundDataRow(final DataRow envDataRow, final DataRow dataRow)
  {
    this.envDataRow = envDataRow;
    this.dataRow = dataRow;

    columnSources = new LinkedMap();
    final String[] dataRowNames = dataRow.getColumnNames();
    for (int i = 0; i < dataRowNames.length; i++)
    {
      final String dataRowName = dataRowNames[i];
      columnSources.put(dataRowName, Boolean.TRUE);
    }

    final String[] envRowNames = envDataRow.getColumnNames();
    for (int i = 0; i < envRowNames.length; i++)
    {
      final String dataRowName = envRowNames[i];
      columnSources.put(dataRowName, Boolean.FALSE);
    }
  }

  public DataRow getEnvDataRow()
  {
    return envDataRow;
  }

  public DataRow getDataRow()
  {
    return dataRow;
  }

  /**
   * Returns the value of the function, expression or column using its specific name. The given name is translated into
   * a valid column number and the the column is queried. For functions and expressions, the <code>getValue()</code>
   * method is called and for columns from the tablemodel the tablemodel method <code>getValueAt(row, column)</code>
   * gets called.
   *
   * @param col the item index.
   * @return the value.
   */
  public Object get(final String col)
  {
    final Boolean b = (Boolean) columnSources.get(col);
    if (Boolean.FALSE.equals(b))
    {
      return envDataRow.get(col);
    }
    return dataRow.get(col);
  }

  /**
   * Returns the known column names, this data-row understands. The column names may change over time but do not
   * change while a event is processed by a function. The array returned is a copy of the internal data-storage
   * and can be safely modified.
   *
   * @return the column names as array.
   */
  public String[] getColumnNames()
  {
    final LinkedMap columnSources = new LinkedMap();
    final String[] dataRowNames = dataRow.getColumnNames();
    for (int i = 0; i < dataRowNames.length; i++)
    {
      final String dataRowName = dataRowNames[i];
      columnSources.put(dataRowName, Boolean.TRUE);
    }

    final String[] envRowNames = envDataRow.getColumnNames();
    for (int i = 0; i < envRowNames.length; i++)
    {
      final String dataRowName = envRowNames[i];
      columnSources.put(dataRowName, Boolean.FALSE);
    }
    return (String[]) columnSources.keys(new String[columnSources.size()]);
  }

  /**
   * Checks whether the value contained in the column has changed since the last advance-operation.
   *
   * @param name the name of the column.
   * @return true, if the value has changed, false otherwise.
   */
  public boolean isChanged(final String name)
  {
    return false;
  }
}
TOP

Related Classes of org.pentaho.reporting.engine.classic.core.parameters.CompoundDataRow

TOP
Copyright © 2018 www.massapi.com. 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.