001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * ImportedVariablesDataRow.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.states.datarow;
030:
031: import org.jfree.report.DataRow;
032: import org.jfree.report.ParameterMapping;
033:
034: /**
035: * Creation-Date: 06.03.2006, 18:15:06
036: *
037: * @author Thomas Morgner
038: */
039: public class ImportedVariablesDataRow extends StaticDataRow {
040: private String[] outerNames;
041: private String[] innerNames;
042:
043: public ImportedVariablesDataRow(final GlobalMasterRow innerRow) {
044: final DataRow globalView = innerRow.getGlobalView();
045: final int cols = globalView.getColumnCount();
046: this .outerNames = new String[cols];
047: this .innerNames = outerNames;
048: final Object[] values = new Object[outerNames.length];
049: for (int i = 0; i < outerNames.length; i++) {
050: outerNames[i] = globalView.getColumnName(i);
051: if (outerNames[i] == null) {
052: throw new IllegalStateException(
053: "Every column must have a name.");
054: }
055: values[i] = globalView.get(i);
056: }
057: setData(outerNames, values);
058: }
059:
060: /**
061: * Maps the inner-row into the outer data row. The parameter mapping's name
062: * represents the *outer* name and the innernames.
063: *
064: * @param innerRow
065: * @param parameterMappings
066: */
067: public ImportedVariablesDataRow(final GlobalMasterRow innerRow,
068: final ParameterMapping[] parameterMappings) {
069: this (innerRow.getGlobalView(), parameterMappings);
070: }
071:
072: public ImportedVariablesDataRow(final DataRow globalView,
073: final ParameterMapping[] parameterMappings) {
074: this .outerNames = new String[parameterMappings.length];
075: this .innerNames = new String[parameterMappings.length];
076: final Object[] values = new Object[parameterMappings.length];
077: for (int i = 0; i < parameterMappings.length; i++) {
078: final ParameterMapping mapping = parameterMappings[i];
079: final String name = mapping.getAlias();
080: values[i] = globalView.get(name);
081: innerNames[i] = name;
082: outerNames[i] = mapping.getName();
083: }
084: setData(outerNames, values);
085: }
086:
087: protected ImportedVariablesDataRow(
088: final ImportedVariablesDataRow dataRow) {
089: super (dataRow);
090: outerNames = dataRow.outerNames;
091: innerNames = dataRow.innerNames;
092: }
093:
094: public ImportedVariablesDataRow refresh(
095: final GlobalMasterRow innerRow) {
096: final DataRow globalView = innerRow.getGlobalView();
097: final int length = innerNames.length;
098: final Object[] values = new Object[length];
099: for (int i = 0; i < length; i++) {
100: final String name = innerNames[i];
101: values[i] = globalView.get(name);
102: }
103: final ImportedVariablesDataRow idr = new ImportedVariablesDataRow(
104: this);
105: idr.setData(outerNames, values);
106: return idr;
107: }
108: }
|