Package org.pentaho.reporting.engine.classic.core.states.datarow

Source Code of org.pentaho.reporting.engine.classic.core.states.datarow.ImportedVariablesDataRow

/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* Copyright (c) 2001 - 2009 Object Refinery Ltd, Pentaho Corporation and Contributors..  All rights reserved.
*/

package org.pentaho.reporting.engine.classic.core.states.datarow;

import java.util.HashMap;

import org.pentaho.reporting.engine.classic.core.DataRow;
import org.pentaho.reporting.engine.classic.core.ParameterMapping;
import org.pentaho.reporting.engine.classic.core.wizard.DataAttributes;
import org.pentaho.reporting.engine.classic.core.wizard.DataSchema;

/**
* Creation-Date: 06.03.2006, 18:15:06
*
* @author Thomas Morgner
*/
public class ImportedVariablesDataRow extends StaticDataRow
{
  private HashMap dataAttributes;
  private String[] outerNames;
  private String[] innerNames;

  public ImportedVariablesDataRow(final MasterDataRow innerRow)
  {
    if (innerRow == null)
    {
      throw new NullPointerException();
    }

    final DataRow globalView = innerRow.getGlobalView();
    final String[] names = globalView.getColumnNames();
    final int cols = names.length;
    this.dataAttributes = new HashMap();
    this.outerNames = new String[cols];
    this.innerNames = outerNames;
    final Object[] values = new Object[cols];
    final DataSchema dataSchema = innerRow.getDataSchema();
    for (int i = 0; i < cols; i++)
    {
      final String name = names[i];
      if (name == null)
      {
        throw new IllegalStateException("Every column must have a name.");
      }
      outerNames[i] = name;
      values[i] = globalView.get(name);

      dataAttributes.put(name, dataSchema.getAttributes(name));
    }
    setData(outerNames, values);
  }

  /**
   * Maps the inner-row into the outer data row. The parameter mapping's name represents the *outer* name and the
   * innernames.
   *
   * @param innerRow
   * @param parameterMappings
   */
  public ImportedVariablesDataRow(final MasterDataRow innerRow,
                                  final ParameterMapping[] parameterMappings)
  {
    if (innerRow == null)
    {
      throw new NullPointerException();
    }
    if (parameterMappings == null)
    {
      throw new NullPointerException();
    }

    final DataRow globalView = innerRow.getGlobalView();
    final int cols = parameterMappings.length;
    this.dataAttributes = new HashMap();
    this.outerNames = new String[cols];
    this.innerNames = outerNames;
    final Object[] values = new Object[cols];
    final DataSchema dataSchema = innerRow.getDataSchema();
    for (int i = 0; i < cols; i++)
    {
      final ParameterMapping mapping = parameterMappings[i];
      final String name = mapping.getAlias();
      if (name == null)
      {
        throw new IllegalStateException("Every column must have a name.");
      }
      outerNames[i] = name;
      values[i] = globalView.get(name);

      dataAttributes.put(mapping.getName(), dataSchema.getAttributes(name));
    }
    setData(outerNames, values);
  }


  protected ImportedVariablesDataRow(final ImportedVariablesDataRow dataRow)
  {
    super(dataRow);
    outerNames = dataRow.outerNames;
    innerNames = dataRow.innerNames;
    dataAttributes = (HashMap) dataRow.dataAttributes.clone();
  }

  public ImportedVariablesDataRow refresh(final DataRow globalView, final DataSchema dataSchema)
  {
    if (globalView == null)
    {
      throw new NullPointerException();
    }
    if (dataSchema == null)
    {
      throw new NullPointerException();
    }

    final int length = innerNames.length;
    final Object[] values = new Object[length];
    for (int i = 0; i < length; i++)
    {
      final String name = innerNames[i];
      values[i] = globalView.get(name);
      dataAttributes.put(outerNames[i], dataSchema.getAttributes(name));
    }
    final ImportedVariablesDataRow idr = new ImportedVariablesDataRow(this);
    idr.setData(outerNames, values);
    return idr;
  }


  public DataAttributes getAttributes(final String name)
  {
    if (name == null)
    {
      throw new NullPointerException();
    }
    return (DataAttributes) dataAttributes.get(name);
  }

}
TOP

Related Classes of org.pentaho.reporting.engine.classic.core.states.datarow.ImportedVariablesDataRow

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.